简体   繁体   中英

How can I use Azure Service Bus transactionaly with Azure DocumentDB

I want to be able to save/update a document in DocumentDB and then publish an event on Azure Service Bus, and I want these to happen atomically.

Azure Service Bus does not support distributed transactions, so with a SQL database, I save my record and place a record in a message queue table, all within a SQL transaction. A process then reads the message queue table and places the messages on the queue and removing them from the queue when successful (utilizing Service Bus' deduplication in case a message is added twice).

But DocumentDB does not support transactions across collections, so I cannot update a document and then add a document to a message queue collection.

How can I ensure my changes to documents are published on the bus?

I'm not entirely sure I understand the question, but... from a transactional standpoint, you can have both your data and your queue documents in the same collection (just make sure you have some type of differentiator such as a Type property, for filtering).

EDIT - to reflect triggers and transactions

Futher, DocumentDB supports pre- and post-trigger operations, so you could set up a post-trigger for writing an additional document after the data document insert is complete. As stated in the comments (per @Ryan): The post-trigger operations are included within the transaction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM