I am implementing integration with a third party system, that I don't have a control over it, and use rabbitmq as message queue to publish a message after doing some updates on the third party system, my implementation as the following scenario
await createItemOnProvider()
await queue.publishMessage()
If I implement a database update and want to publish a message after it succeeds, I use the outbox pattern to handle that case, but in the current case, I need to make it atomic but there is no transaction wrapper that handles doing both or not, I am not sure what pattern should be used in that case, for example if publishing a message failed, what to do?
Don't reinvent the wheel. Use an orchestrator like temporal.io to implement your logic. You can write code exactly as per your requirements:
and Temporal is going to ensure that both lines complete execution in the presence of any failures including process crashes and network outages.