zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
466 stars 77 forks source link

[Host.Outbox] Fails to retrieve bus when no child buses are in use #294

Closed EtherZa closed 4 days ago

EtherZa commented 1 month ago

When SlimMessageBus is configured to use a primary (Main) bus only, the OutboxSendingTask fails to locate the bus.

I have narrowed the issue down to the OutboxSendingTask.GetBus method but unfortunately don't have the time to dig/resolve the issue for the time being.

    private static IMasterMessageBus GetBus(ICompositeMessageBus compositeMessageBus, IMessageBusTarget messageBusTarget, string name)
    {
        if (name != null && compositeMessageBus != null)
        {
            return compositeMessageBus.GetChildBus(name);
        }
        if (messageBusTarget != null)
        {
            return messageBusTarget.Target as IMasterMessageBus;
        }
        return null;
    }

Steps to reproduce:

  1. Configure a bus (not a child bus) to use the Outbox plugin.
  2. Publish a message so that it is spooled to sql
  3. When OutboxSendingTask attempts to find the 'Main' bus, it will satisfy the condition first condition of the GetBus method and attempt to resolve a ChildBus instead of falling through to messageBusTarget.Target.
  4. GetBus returns null, which aborts the message delivery

Workaround:

Configure SlimMessageBus to add the bus as a child.


builder.Services.AddSlimMessageBus(builder =>
{
    builder.AddChildBus("SVB", bus =>
    {
        ...
    });

    ...
});
zarusz commented 1 month ago

Thanks for reporting. I can have a look.