I have an application that has a ServiceBusTrigger Azure Function. In the handler of this function, after I receive a queue message in my "QueueA" I need to do some business logic and, in the end, I have to do this:
- publish a message to a "TopicA" that another systems will consume
- publish another kind of message to my "QueueB", the "QueueB" will save the content to a database, updating the status of my event
- move a file from one folder to another inside a file share storage
- save the content of message received in "QueueA" to a database
I need to do all this stuff inside a Transaction Scope, because if one item fail, any of the other items can't go on.
My cenário was working just fine without the second item, thus after I tried to publish to a topic AND to a queue inside the same transaction I got this error message:
"Local transactions cannot span multiple top-level entities such as queue or topic."
From Microsoft's documentation I found this:
Service Bus supports grouping operations against a SINGLE messaging entity (queue, topic, subscription) within the scope of a transaction. For example, you can send several messages to one queue from within a transaction scope, and the messages will only be committed to the queue's log when the transaction successfully completes.
I'm just stuck here and don't know how can I do it and keep it thread safe. Anyone passed through it and can help me to post to a queue and a topic inside a transaction scope?