dashbitco / broadway_rabbitmq

A Broadway producer for RabbitMQ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should producers automatically create exchanges?

wanderanimrod opened this issue · comments

Thanks for the great work on this producer. Quick question:

The AMQP library on which this producer is based provides the AMQP.Exchange.declare/4 function to declare exchanges. Calling this function creates an exchange if it doesn't exist or does nothing if the exchange exists.

I am trying to follow the docs to create a producer that binds an auto-generated queue to an exchange, and I want the exchange to be auto created when the producer starts if the exchange doesn't exist. I also want to create the exchange as type :topic.

Is there a way to do this? If not, is there a reason why the broadway_rabbitmq producer shouldn't declare exchanges?

Thanks.

@wanderanimrod the :declare and :bindings options that were added don't take care of creating the exchange as well. However, this is by design: a BroadwayRabbitMQ.Producer is a RabbitMQ consumer, so the API it needs is queues to consume from and bindings so that messages get routed to those queues. The exchange is usually a concern of the publisher. However, nothing stops you from declaring the necessary exchange before starting the Broadway pipeline. We added queue and binding declaration because there are some things (like auto_delete queues) that would have been a bit of a pain without these options.

Thank you @josevalim and @whatyouhide . I'll take care of the exchange declaration outside the broadway pipeline.