System.InvalidOperationException: 'Local transactions cannot span multiple entities or partitions.
See original GitHub issueI’m trying to use the “send via” feature to be able to send messages to more than one entity inside a transaction.
I have the following entities:
- Topic:
mytesttopic
, which has one subscription:input_subscription
- Topic:
output_1
- Topic:
output_2
- Queue:
transferqueue
I’m trying to receive sessions from input_subscription
and for each received message:
- Send a new message to
output_1
(viatransferqueue
) - Send another message to
output_2
(viatransferqueue
) - Complete the received message
All within one transaction, meaning, if the transaction doesn’t complete, then the received message should be restored in the input_subscription
and no messages should have been send.
Visually:
┌⟶ output_1
input_subscription ⟶ Handler ⟶ transferqueue ─┤
└⟶ output_2
This is the code:
var incomingSubscriptionClient = new SubscriptionClient(connection, "mytesttopic", "input_subscription", ReceiveMode.PeekLock, new NoRetry());
var output1sender = new MessageSender(connection, "output_1", "transferqueue");
var output2sender = new MessageSender(connection, "output_2", "transferqueue");
incomingSubscriptionClient.RegisterSessionHandler(async (receivedMessage, message, cancellation) =>
{
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
await output1sender .SendAsync(new Message
{
Body = Encoding.UTF8.GetBytes("something"),
SessionId = "mySessionId"
});
await output2sender .SendAsync(new Message
{
Body = Encoding.UTF8.GetBytes("something else"),
SessionId = "mySessionId"
});
await session.CompleteAsync(receivedMessage.SystemProperties.LockToken);
transaction.Complete();
}
}, new SessionHandlerOptions(exception =>
{
Console.WriteLine("session Receiver exception: " + exception.Exception.Message);
return Task.CompletedTask;
}));
But I’m getting this exception when completing the received message:
System.InvalidOperationException: ‘Local transactions cannot span multiple entities or partitions.’
I’m not sure if this is a bug or if I’m doing something wrong.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (5 by maintainers)
Top Results From Across the Web
Azure service bus - Post to a queue and a topic inside ...
"Local transactions cannot span multiple top-level entities such as queue or topic." From Microsoft's documentation I found this: Service Bus ...
Read more >Azure Service Bus .NET SDK Deep Dive – Send Via
With SendVia, it is possible to create an atomic transaction between ... 'Local transactions cannot span multiple entities or partitions'.
Read more >Create partitioned Azure Service Bus queues and topics
Each partitioned queue or topic consists of multiple partitions. ... a transaction, Service Bus returns an invalid operation exception.
Read more >Azure Functions Transaction Mode Error - .NET 6.0
Private.CoreLib: Exception while executing function: zp_adapt_box. Azure.Messaging.ServiceBus: Local transactions cannot span multiple entities ...
Read more >Transactional Messaging in the Windows Azure Service Bus
There are some limitations in the transactional model, transactions can only include one top level messaging entity (such as a queue or topic, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@axisc Yes, that seems to work!! That’s awesome.
Thanks
there is some overhead because the service requires compute to accept messages on the transfer entity and then forward it to the actual destination. I’d recommend using it only when there is a need for cross entity transactions.