Publish/Subscribe samples with RabbitMQ in .NET [closed]

眉间皱痕 提交于 2020-01-22 18:42:50

问题


I've built this sample: Getting Started With RabbitMQ in .net, but made 2 programs:

  • one-publisher
  • one-subscriber

I'm using BasicPublish to publish and BasicAck to listen as in example. If I run one publisher and several subscribers-on every "send message" from publisher- only one subscriber gets it. So that there is some order (as subscribers were started) in which publisher sends message to subscribers, and I want to send one message to all subscribers. What is wrong with that sample? May be you can provide working sample of publisher/subscribers message exchange via RabbitMq?


回答1:


The example you link to uses simple queueing without an exchange, which ensures that only a single consumer will handle the message. To support pub/sub in RabbitMQ, you need to first create an Exchange, and then have each subscriber bind a Queue on that Exchange. The producer then sends messages to the Exchange, which will publish the message to each Queue that has been bound to it (at least with the simple Fanout exchange type. Routing can be achieved with Direct and Topic exchanges.)

For a Java sample (which could be converted to C# pretty easily) please see here.

Edit: Updated .Net version can be found here




回答2:


I've added a new tutorial about this Getting Started With RabbitMQ in .net




回答3:


There are also some official sources now.



来源:https://stackoverflow.com/questions/5951477/publish-subscribe-samples-with-rabbitmq-in-net

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