Waiting for all rabbitmq responses on a fanout exchange?

白昼怎懂夜的黑 提交于 2019-12-01 06:23:12

What you are looking for is something like a Scatter-Gather (http://www.eaipatterns.com/BroadcastAggregate.html) pattern, isn’t it?

You don’t know the consumers bound to the fan-out, so you can:

  1. implement an keep-alive from the consumer(s) using for example an queue where the producer is bound. Each consumer sends a keep-alive each one second, if you don’t receive a message you can considerer the consumer off-line.
  2. Use an in-memory database where the consumer are registered (always with a keep-alive).
  3. Use the HTTP API to know the consumers list bound to the fan-out, in this way:

http://rabbitmqip/vhost/yourfanout/bindings/source and the result is like this:

 [{"source":"yourfanout","vhost":"/","destination":"amq.gen-xOpYc8m10Qy1s4KCNFCgFw","destination_type":"queue","routing_key":"","arguments":{},"properties_key":"~"},{"source":" yourfanout","vhost":"/","destination":"myqueue","destination_type":"queue","routing_key":"","arguments":{},"properties_key":"~"}]

Once count the consumers you know the replies count.

Call the API before send a request.

NOTE the last-one can works only if you use a temporary queue bound to the consumers.

I found this resource that could help you (http://geekswithblogs.net/michaelstephenson/archive/2012/08/06/150373.aspx)

I don't know exactly your final scope, but with a keep-alive you can wait max one second before decide if the consumer is alive.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!