Home > OS >  Service Bus transaction across namespaces?
Service Bus transaction across namespaces?

Time:10-14

I understand Service Bus transactions across entities within a namespace. Does Azure provide transactions within two or more namespaces? As I can see I am thrown an exception when I try it, and also I doubt if it is documented somewhere.

ServiceBusClient client1 = new ServiceBusClient("xxx", new ServiceBusClientOptions { EnableCrossEntityTransactions = true });
ServiceBusClient client2 = new ServiceBusClient("yyy", new ServiceBusClientOptions { EnableCrossEntityTransactions = true });

ServiceBusReceiver receiver = client1.CreateReceiver("queue");
ServiceBusSender sender = client2.CreateSender("queue");

using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
    try
    {
        var message = await receiver.ReceiveMessageAsync();
        await receiver.CompleteMessageAsync(message);
        await sender.SendMessageAsync(new ServiceBusMessage(message));
        transaction.Complete();
    }
    catch (Exception ex)
    {
        transaction.Dispose();
    }
}

Exception: Azure.Messaging.ServiceBus.ServiceBusException: 'Transaction hasn't been declared yet, or has already been discharged (GeneralError).

CodePudding user response:

Does Azure provide transactions within two or more namespaces?

Currently, Azure Service Bus does not support cross-namespace transactions.

A transaction spanning multiple namespaces might be tricky. There's a feature request for cross-namespace forwarding, which could be the first step in that direction or at least help with processing messages from more than a single namespace.

  • Related