arcus.messaging icon indicating copy to clipboard operation
arcus.messaging copied to clipboard

Possibility to explicitly start the MessagePump

Open fgheysels opened this issue 10 months ago • 1 comments

When using Arcus.Messaging, we typically add a MessagePump to our DI container by calling one of the extension methods that adds a message-pump. This method adds a BackGroundService to our Dependency Container.

As far as I know or can see, the BackGroundJob immediately starts, but it would be good if an application programmer could have a possibility to decide when the MessagePump should in fact start reading from ServiceBus.

I have a scenario where I want to make sure that certain dependencies are available before I want the MessagePump to start receiving messages. AFAIK, I can't use the service-breaker functionality for this, because the service-breaker can only be activated once we've already received a message.

I don't know if it would be possible to register / inject a class that implements a certain interface that an application programmer could use to implement some logic. Only when that logic is executed, the MessagePump starts reading from the broker. That class could then maybe be called by the StartProcessingMessagesAsync method of the MessagePump class

Image

fgheysels avatar Mar 03 '25 14:03 fgheysels

There already exists a 'lifetime' interface/default implementation. Couldn't that be used?

stijnmoreels avatar Mar 04 '25 06:03 stijnmoreels

Playing with the idea to maybe have a options.UseTrigger(Func<IServiceProvider, Task> waitForStartAsync); way of registering a delegate that can be used for application developers to retrieve injected services and run the necessary 'pre-start' requirements before we actually go through the message pump initialization.

stijnmoreels avatar Sep 05 '25 07:09 stijnmoreels

I think this might indeed be a good idea. Sounds like some kind of interceptor mechanism that we can maybe extend later to inject services that need to be executed after start, before shutdown ..... Not needed for now, but just thinking out loud.

fgheysels avatar Sep 08 '25 08:09 fgheysels