rebus-org / Rebus

:bus: Simple and lean service bus implementation for .NET
https://mookid.dk/category/rebus
Other
2.32k stars 363 forks source link

How to publish one message but subscribe to another #903

Closed stefandevo closed 4 years ago

stefandevo commented 4 years ago

I have this setup:

When I use the UseAzureServiceBusAsOneWayClient I can send message1. But I cannot handle message2. (or don't know how).

When I use the UseAzureServiceBus I cannot send message1 because I don't have an handler. I can receive message2.

Is this setup possible?

mookid8000 commented 4 years ago

A "one-way client" is a Rebus instance that does not have an input queue and therefore isn't capable of receiving anything. This is why you can't make your bus instance configured with UseAzureServiceBusAsOneWayClient handle anything.

A normal bus instance (i.e. one that has an input queue) will try to consume anything you put into its input queue. You just need to get some messages into its queue, either by having someone await bus.Send(...) a message directly to it, or by having it await bus.Subscribe<TEvent>() to one or more events.

Both can send and publish messages just the same.

Does this make sense? 🙂

stefandevo commented 4 years ago

Ok thanks; clear. That makes clear that what I want cannot be handled by Rebus. I thought I could mix the two; having certain messages published and other handled.

mookid8000 commented 4 years ago

(...) I thought I could mix the two; having certain messages published and other handled.

I don't understand this sentence... could you maybe rephrase it somehow?

stefandevo commented 4 years ago

I have the following situation: my microservices acts upon receiving SMS messages. When the service is called I put this on a queue; another service will handle the message (type: 'IncomingSMS') . Here I can use UseAzureServiceBusAsOneWayClient. But that same microservice is responsible for replying (type: 'OutgoingSMS'). However, this is a result from a service that is picking up the 'IncomingSMS', processing it, and then sending a 'OutgoingSMS' on the bus. So that same microservice then needs to handle the 'OutgoingSMS'. For that I need the regular UseAzureBus but then it will fail for the 'IncomingSMS' because it doesn't have a handler.

mookid8000 commented 4 years ago

If I understand your setup correctly, then yes – you'd need two ordinary bus instances: one that acts as an SMS gateway, and one that handles incoming SMS messages.

It could be sketched like this (numbers hint at the sequence): image

Does that make sense?