Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Feature - Send-Via / TransferSender to send messages across entities in a transaction #438

Merged
merged 6 commits into from
May 5, 2018

Conversation

nemakam
Copy link
Contributor

@nemakam nemakam commented Apr 2, 2018

Description

This feature lets a user send messages across entities in a single transaction.

A single transaction cannot theoretically span across entities. So as to support cross-entity transaction, you can now send a message to a destination-queue via another queue. The transaction will be performed on the via-queue, and once successful, the message will be forwarded/transferred to its intended destination.
Resolves #423

Sample:

var viaQueueSender = new MessageSender(connection, viaQueueName);
var viaQueueReceiver = new MessageReceiver(connection, viaQueueName);
var destinationViaSender = new MessageSender(connection, destinationQueueName, viaQueueName);

var message1 = new Message(body) { MessageId = "1", PartitionKey = "pk1" };
var message2 = new Message(body) { MessageId = "2", PartitionKey = "pk2", ViaPartitionKey = "pk1" };

await viaQueueSender.SendAsync(message1);
var receivedMessage = await viaQueueReceiver.ReceiveAsync();

using (new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
	await viaQueueReceiver.CompleteAsync(receivedMessage.SystemProperties.LockToken);
	await destinationViaSender.SendAsync(message2);
}

In the above example, operations on both message1 and message2 (intended for different entities) are being performed within the same entity (i.e., the via-queue)

@nemakam nemakam added this to the 3.0 milestone Apr 2, 2018
@nemakam nemakam requested review from binzywu and vinaysurya April 2, 2018 23:12
@nemakam nemakam requested a review from a team as a code owner April 2, 2018 23:12
@nemakam nemakam removed the bug label Apr 2, 2018
@@ -252,6 +284,11 @@ public Task SendAsync(Message message)
"Cannot schedule messages in the past");
}

if (this.isViaSender && Transaction.Current != null)
{
throw new ServiceBusException(false, $"{nameof(ScheduleMessageAsync)} method is not supported in a Via-Sender.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should exception message be more specific as per why it's not supported? There are two constraints, send-via and transaction.

@SeanFeldman
Copy link
Collaborator

@nemakam while waiting for @binzywu's review, should the test on .NET Standard be addressed?

@nemakam
Copy link
Contributor Author

nemakam commented Apr 11, 2018

@SeanFeldman
This requires service side changes that are yet to be deployed. The send-via test will fail meanwhile. And once a test fails, it drags down other tests as well as the queue is reused.
That's why I've put the 'onhold' tag :)

@SeanFeldman
Copy link
Collaborator

We need a patience-sean tag 😆

@nemakam
Copy link
Contributor Author

nemakam commented Apr 12, 2018

nemakam added patience-sean label 5 minutes ago

@SeanFeldman
Copy link
Collaborator

Epic! 😂

@SeanFeldman
Copy link
Collaborator

@nemakam any updates? Thanks.

@nemakam
Copy link
Contributor Author

nemakam commented Apr 25, 2018

@SeanFeldman
ETA - for preview build - a week or so. We are still waiting for the release to finish.
Then once internal long running tests pass, we can open it up. Needs couple of days for this as well.

@nemakam nemakam merged commit ebfe7eb into dev May 5, 2018
@nemakam nemakam added feature and removed on hold labels May 5, 2018
@nemakam nemakam deleted the sendvia branch May 5, 2018 02:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants