question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidOperationException: 'Local transactions cannot span multiple entities or partitions.

See original GitHub issue

I’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:

  1. Send a new message to output_1 (via transferqueue)
  2. Send another message to output_2 (via transferqueue)
  3. 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:closed
  • Created 3 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
johnknoopcommented, Jan 30, 2021

@axisc Yes, that seems to work!! That’s awesome.

Thanks

0reactions
axisccommented, Feb 3, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found