1

I´m new with RabbitMQ. I would like to have "integration events" for other services. So a kind of routing for a message for all microservices.

However, if I have replicated services for scaling, I do not want all the replicated services to receive the message.

Example:
                             >>> Service B (gets message)
Service A > Push Message >>> Service B (Should NOT receive a message, is replicated)
                             >>> Service C (gets message)

I think it is a combination of "routing" and "work queues" what I need?
But how can I do that correctly? I use Node.js or C#, if you have examples.

Gregor Biswanger
  • 529
  • 3
  • 16

2 Answers2

1

Scaling up your services (your consumers) is not a problem in this case. Rather it's a feature of how queues work.

In short, it doesn't matter if you have one service-instance consuming from a queue or if you have ten instances consuming from the same queue. Only one consumer will receive the same message from that queue. Think of this as messages being distributed in a round-robin fashion.

If you want to send the same message to multiple consumers, you must (in the end) publish it on separate queues. That is, each consumer should listen on a specific queue and your exchange publishes the message on all queues. Fanout exchange might work here.

Martin Wickman
  • 19,662
  • 12
  • 82
  • 106
  • I want all the services to get the message at the same time ("routing"). However, if a microservice was scalled, this should only be able to get one ("work queues" ala round-robin). So I need a combination of "routing" and "work queues". I just have no idea how to implement this in Node.js. For C # NServiceBus sounds good, only it is a commercial product. – Gregor Biswanger Nov 01 '19 at 12:05
  • 1
    Read up on [exchange types](https://lostechies.com/derekgreer/2012/03/28/rabbitmq-for-windows-exchange-types/) and routing keys as I am pretty sure most of your problems can be solved without going down the service bus rabbit hole, so to speak. Consider update your question with more specifc examples so we can better help you. – Martin Wickman Nov 01 '19 at 13:05
0

I have my microservices and DDD information in here . Take a look

If you want to publish an event to a special Service, then you should use a service bus. I use NServiceBus. It is the best tool in .net. RabbitMQ is just a queue. Inside NServiceBus you can use many different queues such as RabbitMQ , SqlServer , etc

So now for your example, Service A publishes an event, let's say UserCreated. Service B has an EventHandler as UserCreatedEventHandler. Sine then service B can get any published event of UserCreated. NServiceBus has Automatic subscriptions and Message routing to know what Service is subscribed on what events. their documents perfectly is complete. Take a look at them

unos baghaii
  • 2,539
  • 4
  • 25
  • 42