rebusrebus-rabbitmq

Accepting command and raising events from a service


Using Rebus as message bus over RabbitMq message broker for enabling event driven communication between micro services. Using bus.Send(command) service A sends command over a specific queue, to which service B has subscribed. we are using type based routing.

Service B during the workflow of command needs to emit events for change in status (performingA, performedA etc..). One of the handler for an event will be in service B only ( per say it will listen to a specific event and call another api).

To achieve this do I need to have 3 instances of rebus in service B? One for subscribing to command from service A and another for raising events and 3rd to handle the event?


Solution

  • do I need to have 3 instances of rebus in service B? One for subscribing to command from service A and another for raising events and 3rd to handle the event?

    No 😃 you only need one Rebus instance in service B.

    One Rebus endpoint (with one input queue) is enough to:

    ...receive the command (you already know that 😊)

    ...subscribe to an event (e.g. await bus.Subscribe<YourEvent>();)

    ...publish the event (e.g. await bus.Publish(new YourEvent(...);)

    ...receive the event (because you subscribed to it, creating a binding from a topic named after your YourEvent type to service B's input queue.