Enable outbox, Isolated worker, .NET7

Hi!

We are stuck when trying to enable outbox during endpoint configuration.

We can recreate the issue using the downloadable example named service-bus-worker_asbfunctionsworker_4_net7_0.zip

We are getting the following error:

Outbox requires transport to be running in ReceiveOnly mode. Use the TransportTransactionMode property on the transport definition to specify the transaction mode.

We saw the known limitation regarding AdvancedConfiguration.UseTransport(..), and instead use the .Transport property.

The added code compared to the downloaded example code is:

        .UseNServiceBus((configuration, endpointConfiguration) =>
        {
            var persistence = endpointConfiguration.AdvancedConfiguration.UsePersistence<SqlPersistence>();
            persistence.SqlDialect<SqlDialect.MsSqlServer>();
            persistence.ConnectionBuilder(() => new SqlConnection("<connection string>"));
            persistence.TablePrefix("_NSB_");
            
            endpointConfiguration.Transport.TransportTransactionMode = TransportTransactionMode.ReceiveOnly;
            endpointConfiguration.AdvancedConfiguration.EnableOutbox();
        })

And except for the packages provided with the example, the follwing are added:

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.11" />
<PackageReference Include="NServiceBus.Persistence.Sql" Version="7.0.2" />

Do you have any advice to give us?

Kind regards,
Robert Sandberg

Or can we omit the two lines below altogether and outbox will be enabled by default when configuring persistance?

endpointConfiguration.Transport.TransportTransactionMode = TransportTransactionMode.ReceiveOnly;
endpointConfiguration.AdvancedConfiguration.EnableOutbox();

When we omit those two lines, and we shutdown our database before sending out the FollowupMessage() in the TriggerMessageHandler, then it fails because as we understood, it tries to write to the outbox in database. Is this assumption correct?

Hi Robert!

I think we have a bug, I was able to repro your issue and fix it in Force transaction mode to receive only to allow outbox to be used by andreasohlund · Pull Request #383 · Particular/NServiceBus.AzureFunctions.Worker.ServiceBus · GitHub

I’ll discuss this further and let you know when we can get a fix out, I’ll keep you posted on this thread.

Cheers,

Andreas

2 Likes

Okey, great to know. We were going insane not knowing if we where doing things completely off. I almost had to call Jens on his vacation :slight_smile:

We are somewhat blocked by this, so looking forward to your fix.

Kind Regards,
Robert

Hi Robert!

I’ve done some more testing and I can confirm that the workaround to set

endpointConfiguration.Transport.TransportTransactionMode = TransportTransactionMode.ReceiveOnly;

works on version 4.1.0. Would you be able to upgrade to it? (since the sample use 4.* nuget will default to 4.0.0 :poop: )

Cheers,

Andreas

Hi Andreas!

We just checked, and even though have have set NServiceBus.AzureFunctions.Worker.ServiceBus to 4.* we get 4.1.0. It seems that * respects our wish to get the highest stable version.

So we have the issue with 4.1.0. We’ve tested it on two machines (Mac + Windows).

Regards,
Robert

Sorry for the confusion, we have now released 4.1.1 and 4.2.1 to address this issue. Let us know if you have any further issues!

Cheers,

Andreas

Thanks for the quick response and fixes! We’ve verified it as working in 4.2.1.

Kind regards,
Robert

Hi Andreas,
We are using “NServiceBus.AzureFunctions.Worker.ServiceBus” Version=“4.2.3”.
When trying to set the transportTransactionMode to receiveOnly, we are getting the following error at compile time.
“Transport TransactionMode is controlled by the Azure Service Bus trigger and cannot be configured via NServiceBus transport configuration API when using Azure Functions.”

We are trying to do the following, in Nservicebus v8.2.
ServiceBusTriggeredEndpointConfiguration.Transport.TransportTransactionMode = TransportTransactionMode.ReceiveOnly;

NSB documentation suggests that we must set it to ReceiveOnly, since we are using outboxing.

Can you please advise on how to proceed?
Thanks

Hi Rishabh,

You are correct that outbox requires transaction mode to be set to ReceiveOnly.

When NServiceBus runs on top of azure functions transactionality is determined by the azure function since NServicBus is not involved in receiving the message. Since isolated worker only supports ReceiveOnly mode it is set by default so you don’t have to set anything, it will work with the outbox “out of the box” :drum:

See Azure Functions with Service Bus (Isolated Worker) • NServiceBus.AzureFunctions.Worker.ServiceBus • Particular Docs for more details.

Hope this makes sense!

Cheers,

Andreas

Hi Anreas,

Thanks for the reply and looking into it!
Not sure if that documentation needs to be updated or the code needs to be fixed.
However, when we debug, with outbox enabled endpoint in Azure function, the default value that TransportTransactionMode is set to is SendsAtomicWithReceive.

Hence we are trying to set it explicitly.

Hi!

What you are seeing in the debugger is the default Azure ServiceBus transport transaction mode which is SendsAtomicWithReceive.

Our function support is wrapping the transport and lowers the default to ReceiveOnly.

Are you getting any exceptions when running the endpoint or are you seeing that the outbox is not in use?

Cheers,

Andreas

Hi Andreas,

Thanks for your help.
Yes, we were able to verify that in the NSB diagnostics the mode was getting set to ReceiveOnly.

Regards,
Rishabh