rebus-org / Rebus.SqlServer

:bus: Microsoft SQL Server transport and persistence for Rebus
https://mookid.dk/category/rebus
Other
43 stars 42 forks source link

Questions about queues existence #102

Closed ghost closed 9 months ago

ghost commented 9 months ago

I am using SqlServer as implementation for Rebus and I have some doubts about its functioning:

  1. I noticed messages being lost when the subcriber of the messages did not registered itself. I referer to the situation when the queue and the corresponding subcription do not exist. The problem here is I expected receiving an error when publishing to a non-existent queue. I debug the code at this repo and it simply does not send the message if there is not any subscription for it. Is it a desired behaviour? Can it be configured?

  2. Has RabbitMq implementation the same behaviour?

Thanks in advance for your time.

mookid8000 commented 9 months ago

The problem here is I expected receiving an error when publishing to a non-existent queue.

That's how "publishing" works. When you PUBLISH a message, as a publisher you do not care whether there's 0..n subscribers that get a copy of the message.

Has RabbitMq implementation the same behaviour?

Yes. This is how Rebus behaves when publishing across all transports: Rebus will distribute 0..n copies of the event to those that have subscribed at that point in time.

If you want to send a message, and you (as the sender) care that someone receives the message, I don't think it sounds like an event, it sounds more like it could be some kind of COMMAND. In that case you should use Rebus' support for commands, which you can send like this:

await bus.Send(yourCommand);

When you await bus.Send(..), exactly one copy of the message will be sent, and it will be sent directly to the input queue mapped in Rebus' endpoint mappings:

services.AddRebus(
    configure => configure
        .(...)
        .Routing(r => r.TypeBased().Map<YourCommand>("your-command-processor"))
);

which is the queue "your-command-processor" in this case.

I hope that clarifies it 🙂