Pub/Sub endpoint with MSMQ transport and Outbox enabled POC

Hi,

I am trying to create a small POC in order to see how I can have a hybrid solution with
two MSMQ endpoints and two AzureServicebus endpoints. Here are the issues I’m currently facing:

  1. When I enable Outbox on my MSMQ endpoint, nservicebus control message (from event subscription) fails
*info: NServiceBus.SubscriptionReceiverBehavior[0]*
*      Subscribe from NServiceBusOutboxPOC.ASB.PubSubEndpointA@MCC23-MIDEBLOIS on message type NServiceBusOutboxPOC.Shared.ProductInserted,Version=1.0.0*
*info: NServiceBus.ImmediateRetry[0]*
*      Immediate Retry is going to retry message '14223e81-196b-4ee5-852c-5c5a3626462b\32009' because of an exception:*
*      System.NullReferenceException: Object reference not set to an instance of an object.*
*         at NServiceBus.Persistence.AzureTable.OutboxPersister.SetAsDispatched(String messageId, ContextBag context, CancellationToken cancellationToken) in /_/src/NServiceBus.Persistence.AzureTable/Outbox/OutboxPersister.cs:line 77*
*         at NServiceBus.TransportReceiveToPhysicalMessageConnector.<Invoke>d__1.MoveNext() in /_/src/NServiceBus.Core/Pipeline/Incoming/TransportReceiveToPhysicalMessageConnector.cs:line 67*
  1. If I remove the event subscription inside my bridge configuration, my event handler is still triggered (event published from MSMQ, handler inside AzureServiceBus endpoint)

Regards,
Michel

Hi Michal!

Just to clarify, are you using our Bridge or are you building your own?

Cheers,

Andreas

Hi,

I am using NServiceBus Bridge. Here is the bridge configuration:

        await Host.CreateDefaultBuilder()
            .UseNServiceBusBridge((ctx, bridgeConfiguration) =>
            {
                bridgeConfiguration.RunInReceiveOnlyTransactionMode();

                //MSMQ - ReceiveOnlyEndpoint
                var msmqReceiveOnlyBridgeEndpoint = new BridgeEndpoint("NServiceBusOutboxPOC.MSMQ.ReceiveOnlyEndpoint");

                //MSMQ - PubSubEndpoint
                var msmqPubSubBridgeEndpoint = new BridgeEndpoint("NServiceBusOutboxPOC.MSMQ.PubSubEndpoint");

                //MSMQ - bridge configuration
                var msmqBridgeTransport = new BridgeTransport(new MsmqTransport());
                msmqBridgeTransport.AutoCreateQueues = true;
                msmqBridgeTransport.HasEndpoint(msmqReceiveOnlyBridgeEndpoint);
                msmqBridgeTransport.HasEndpoint(msmqPubSubBridgeEndpoint);
                bridgeConfiguration.AddTransport(msmqBridgeTransport);

                //ASB - ReceiveOnlyEndpoint
                var asbReceiveOnlyBridgeEndpoint = new BridgeEndpoint("NServiceBusOutboxPOC.ASB.ReceiveOnlyEndpoint");

                //ASB - PubSubEndpointA
                var asbPubSubBridgeEndpointA = new BridgeEndpoint("NServiceBusOutboxPOC.ASB.PubSubEndpointA");
                asbPubSubBridgeEndpointA.RegisterPublisher<ProductInserted>("NServiceBusOutboxPOC.MSMQ.PubSubEndpoint");

                //ASB - PubSubEndpointB
                var asbPubSubBridgeEndpointB = new BridgeEndpoint("NServiceBusOutboxPOC.ASB.PubSubEndpointB");

                //ASB - bridge configuration
                var asbBridgeTransport = new BridgeTransport(new AzureServiceBusTransport(connectionString));
                asbBridgeTransport.AutoCreateQueues = true;
                asbBridgeTransport.HasEndpoint(asbReceiveOnlyBridgeEndpoint);
                asbBridgeTransport.HasEndpoint(asbPubSubBridgeEndpointA);
                asbBridgeTransport.HasEndpoint(asbPubSubBridgeEndpointB);
                bridgeConfiguration.AddTransport(asbBridgeTransport);

                var learningBridgeTransport = new BridgeTransport(new LearningTransport());
                var mainEndpoint = new BridgeEndpoint("NServiceBusOutboxPOC.Main");
                learningBridgeTransport.HasEndpoint(mainEndpoint);
                bridgeConfiguration.AddTransport(learningBridgeTransport);

            })
            .Build()
            .RunAsync().ConfigureAwait(false);

Thanks,
Michel

  1. When I enable Outbox on my MSMQ endpoint, nservicebus control message (from event subscription) fails

This seems to indicate that something is off with the outbox configuration of the MSMQ endpoint, can you share the code for that endpoint? (Or perhaps share the entire POC, you can send it to support@particular.net if it contains code that you can’t share publicly)

  1. If I remove the event subscription inside my bridge configuration, my event handler is still triggered (event published from MSMQ, handler inside AzureServiceBus endpoint)

NServiceBus doesn’t automatically unsubscribe so removing the config from the bridge would just mean that the subscription isn’t set up if missing.

See Manual unsubscribe • NServiceBus Samples • Particular Docs for a sample on how to manually unsubscribe

Cheers,

Andreas

Hi,

You can find the POC code zip file below. The code depends on two environment variables for Azure Service Bus(AzureServiceBus_ConnectionString) and Azure Table Storage (AzureTableStorage_ConnectionString). You should be able to reproduce the issue if you select the following projects to start:

  • NServiceBusOutboxPOC.Main

  • NServiceBusOutboxPOC.Bridge

  • NServiceBusOutboxPOC.AzureServiceBus.PubSubEndpointA

  • NServiceBusOutboxPOC.MSMQ.PubSubEndpoint

NServiceBusOutboxPOC.zip (503.4 KB)

Thanks,
Michel

Hi!

I can reproduce the issue with the code you sent, it seems like there is a problem with the AzureTableStorage outbox implementation since if I switch to NonDurable persistence everything seems to work as expected.

I’ll keep digging and let you know when I find the root cause.

Cheers,

Andreas

Hi again @Michel_Deblois

We’ve managed to confirm and reproduce the bug:

Until we get a fix released are you able to work around this for your POC by using the NonDurable storage option for your MSMQ endpoint?

Cheers,

Andreas

Hi,

Thank you for your time/reply.

That’s fine. I will actually use the SQL Persistence as our business data spreads over multiple DBs.

Regards,
Michel Deblois

The fix for this is now released NServiceBus.Persistence.AzureTable 3.2.2, 4.0.1, and 5.0.1 – Patch releases available

Thanks for helping us get this fixed @Michel_Deblois !

1 Like