rebus-org / Rebus.ServiceProvider

:bus: Microsoft Extensions Dependency Injection container adapter for Rebus
https://mookid.dk/category/rebus
Other
67 stars 32 forks source link

Working with non existing queue #52

Closed kostazol closed 3 years ago

kostazol commented 3 years ago

Hello. I have a problem. When I configure Rebus with existing queue it work great, but if I configure Rebus with non existing queue I got error. I checked code of Rebus.AmazonSQS, and it might create a queue if it isn't exists when Initialized method is called. And If I understand right, ServiceProvider will not call Initialized or Start method of RebusConfigurer. It call only Start method of IBusStarter. Please check working with non existing queue. image

mookid8000 commented 3 years ago

Hi @kostazol , Rebus intentionally doesn't create destination queues if they do not exist – instead, it throws an exception.

This way, the behavior aligns across transports like MSMQ, Azure Service Bus, Amazon SQS, etc., since they all throw an exception if you accidentally send to a non-existent queue.

The reasoning behind this behavior, is that it's almost always an error, if you send to a queue that doesn't exist – because, when you send a message to a queue, it's a sign that you care about the message, and you care that a special someone is going to have it, but if that special someone doesn't exist, you most likely want to know it as fast as possible. 🙂

In the code you posted, you have configured the bus instance to be a "one-way client", meaning that it can only be used to send/publish messages - maybe you meant to configure it to have an input queue, i.e. be able to receive messages as well? In that case, configure it to have an "input queue" (i.e. a queue it consumes messages from) like this:

services.AddRebus(configure => configure
    .Transport(t => t.UseAmazonSQS(credentials, _sqsConfig, "testQueue"))
    .Routing(r => r.TypeBased().Map<string>("testQueue"))
    .Options(o => o.SimpleRetryStrategy(errorQueueAddress: "ErrorQueue")));
kostazol commented 3 years ago

Why is there void CreateQueue in AmazonSQS transport and it called in void Initialize? https://github.com/rebus-org/Rebus.AmazonSQS/blob/master/Rebus.AmazonSQS/AmazonSQS/AmazonSqsTransport.cs

mookid8000 commented 3 years ago

It's there so the Rebus instance can create its own input queue.