mateodelnorte / servicebus

Simple service bus for sending events between processes using amqp.
MIT License
420 stars 66 forks source link

How to combine fanout with worker queues #97

Closed balmasi closed 7 years ago

balmasi commented 7 years ago

I've been struggling to implement this using servicebus.

Example Scenario:

User service: 1 process Order Service: 3 processes Analytics Service: 5 processes

user updates firstname.

I want to publish 'event.user.updated', { user } to both order service and analytics service.

However, only one processes should pick it up and process it PER SERVICE. e.g. 1 process from the 5 analytics processes picks the message up and does something. 1 process from the 3 order processes picks the message up and does something.

Everything I've tried with servicebus leads to roundrobin between the processes of all the services. How can I achieve this?

AnsonT commented 7 years ago

You can specify a specific queue for each of the services, and the processes of that service will round robin off the same queue. e.g.

bus.subscribe({ routingKey: "event.user.updated", queueName: "event.user.updated.orderService"}, handleUserUpdated) bus.subscribe({ routingKey: "event.user.updated", queueName: "event.user.updated.analyticService"}, handleUserUpdated)

mateodelnorte commented 7 years ago

Yup. That's the way to do it.

mateodelnorte commented 7 years ago

Would love help documenting some of this stuff, if anybody wants to help become a maintainer.