Skip to content

Commit

Permalink
a durable and auto delete exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
wildonion committed May 31, 2024
1 parent 4c8281a commit c8f2005
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/workers/producers/notif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,20 @@ impl NotifProducerActor{
match pool.create_channel().await{
Ok(chan) => {

let mut ex_options = ExchangeDeclareOptions::default();
ex_options.auto_delete = true; // the exchange can only be deleted if all bindings are deleted
ex_options.durable = true; // durability is the ability to restore data on node shutdown

// -ˋˏ✄┈┈┈┈ creating exchange
/*
you should set the auto_delete flag to True when declaring the exchange. This will
automatically delete the exchange when all channels are done with it.
Keep in mind that this means that it will stay as long as there is an active binding
to the exchange. If you delete the binding, or queue, the exchange will be deleted.
if you need to keep the queue, but not the exchange you can remove the binding once
you are done publishing. This should automatically remove the exchange.
so when all bindings (queues and exchanges) get deleted the exchange will be deleted.
*/
match chan
.exchange_declare(&exchange, {
match exchange_type.as_str(){
Expand All @@ -106,12 +119,12 @@ impl NotifProducerActor{
"headers" => deadpool_lapin::lapin::ExchangeKind::Headers,
_ => deadpool_lapin::lapin::ExchangeKind::Topic,
}
},
ExchangeDeclareOptions::default(), FieldTable::default()
},
ex_options, FieldTable::default()
)
.await
{
Ok(ex) => ex,
Ok(ok) => {ok},
Err(e) => {
use crate::error::{ErrorKind, HoopoeErrorResponse};
let e_string = &e.to_string();
Expand Down Expand Up @@ -144,7 +157,7 @@ impl NotifProducerActor{
&routing_key, // the way that message gets routed to the queue based on a unique routing key
BasicPublishOptions::default(),
payload, // this is the ProduceNotif data,
BasicProperties::default(),
BasicProperties::default().with_content_type("application/json".into()),
)
.await
{
Expand Down

0 comments on commit c8f2005

Please sign in to comment.