Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 269
0x49D1 Avatar asked May 10 '11 14:05

0x49D1


People also ask

Does RabbitMQ publish subscription?

Conceptually, RabbitMQ is both: point-to-point as well as pub-sub. You can register your listener application to the topic of an RabbitMQ exchange and receive all messages published to that Topic. So that is clearly 'pub-sub'.

How does RabbitMQ work in C#?

A RabbitMQ connection is based on protocols, is the base for having channels running and, as its names say, connects the server to the client. RabbitMQ client, which is connected to a channel listening to its queues in order to read the messages published on it.

How do I close consumer RabbitMQ?

You can kill connections to the RabbitMQ broker using the rabbitmqctl tool (see the man page) or by using the Web UI. You could also purge and delete the queue which belonged to the rogue consumer. However, you can't kill the consumer process itself using those tools.


2 Answers

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

like image 121
dlev Avatar answered Sep 21 '22 18:09

dlev


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

like image 38
longhairedsi Avatar answered Sep 20 '22 18:09

longhairedsi