minghuaw / fe2o3-amqp

A rust implementation of the AMQP1.0 protocol based on serde and tokio.
MIT License
58 stars 7 forks source link

How to publish Message to Exchange with routing key without creating new Sender #246

Closed Guneet-commits closed 2 months ago

Guneet-commits commented 2 months ago

Hi @minghuaw, let exchange_address = "/exchange/Exchange1/RoutingKey"; let mut sender = Sender::builder() .name("rust-sender-link-1") .target(exchange_address) .attach(&mut session) .await .unwrap(); If I implement this, it works fine, but the issue is I have to publish to multiple routing keys say 30, so I'd have to create 30 senders which is not feasible, so is there a way through which i can just specify the exchange_name in exchange_address and then specify the routing key using some property of Sender::builder or Suppose i have 10 if else cases I could change the value of sender.target for each if else case without creating a new Sender.

minghuaw commented 2 months ago

@Guneet-commits Can you provide more details on what broker/exchange you are working with?

minghuaw commented 2 months ago

@Guneet-commits If you are working with rabbitmq, their documentation (https://github.com/rabbitmq/rabbitmq-amqp1.0) could be more useful.

Looking at the "Routing and Addressing" section, I think if you want to publish to the "X" exchange, then what you need to do is to create a sender to the target address "/exchange/", and then set the subject field (https://docs.rs/fe2o3-amqp/latest/fe2o3_amqp/types/messaging/properties/struct.Builder.html#method.subject) of the message property (https://docs.rs/fe2o3-amqp/latest/fe2o3_amqp/types/messaging/properties/struct.Properties.html) to the name of the exchange "X".

Guneet-commits commented 2 months ago

Thanks alot @minghuaw , it worked by the following way : Setting my exchange_address = "/exchange/Relay1_HashMapData/"; Here /exchange is mandatory. I was trying the same thing but I was passing the values to application_properties. Is there some where I can the detailed documentation?

minghuaw commented 2 months ago

Is there some where I can the detailed documentation?

This really depends on the broker you are working with. There are some intricate differences in the way they use the protocol. If you are dealing with rabbitmq, then the official documentation mentioned above is probably your best chance. Other sources of documentation would be:

  1. The AMQP 1.0 protocol itself: http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-overview-v1.0.html
  2. docs for the crate: https://docs.rs/fe2o3-amqp/latest/fe2o3_amqp/
  3. There's a curated list of resources for AMQP 1.0: https://github.com/xinchen10/awesome-amqp

If you are ONLY dealing with rabbitmq, I'd recommend you opt in a dedicated AMQP 0.9.1 crate instead (like lapin https://crates.io/crates/lapin).

Guneet-commits commented 2 months ago

It was compulsory for me to use AMQP 1.0 but the issue is resolved now.... Thanks alot @minghuaw for the quick replies really appreciate it.

minghuaw commented 2 months ago

Would you mind closing this issue if you consider it resolved?