From 3223f32f5c808dacce20319cc8174820d15ebf19 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Thu, 30 Apr 2020 19:50:34 +0200 Subject: [PATCH] make messages persistent Should ensure we don't loose pending builds or evaluations when rabbitmq restarts. --- ofborg/src/easylapin.rs | 8 +++++++- ofborg/src/notifyworker.rs | 1 + ofborg/src/worker.rs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ofborg/src/easylapin.rs b/ofborg/src/easylapin.rs index 3868335..20178eb 100644 --- a/ofborg/src/easylapin.rs +++ b/ofborg/src/easylapin.rs @@ -190,13 +190,19 @@ async fn action_deliver( let key = msg.routing_key.take().unwrap_or_else(|| "".to_owned()); log::debug!("action publish {}", exch); + let mut props = BasicProperties::default().with_delivery_mode(2); // persistent. + + if let Some(s) = msg.content_type { + props = props.with_content_type(s.into()); + } + let _confirmaton = chan .basic_publish( &exch, &key, BasicPublishOptions::default(), msg.content, - BasicProperties::default(), + props, ) .await? .await?; diff --git a/ofborg/src/notifyworker.rs b/ofborg/src/notifyworker.rs index aeb8842..9be12d4 100644 --- a/ofborg/src/notifyworker.rs +++ b/ofborg/src/notifyworker.rs @@ -82,6 +82,7 @@ impl<'a> NotificationReceiver for ChannelNotificationReceiver<'a> { let props = BasicProperties { content_type: msg.content_type, + delivery_mode: Some(2), // persistent ..Default::default() }; self.channel diff --git a/ofborg/src/worker.rs b/ofborg/src/worker.rs index 7aae8fa..51a72ba 100644 --- a/ofborg/src/worker.rs +++ b/ofborg/src/worker.rs @@ -104,6 +104,7 @@ impl amqp::Consumer for Worker { let props = BasicProperties { content_type: msg.content_type, + delivery_mode: Some(2), // persistent ..Default::default() }; channel