If the REST API you’re building is under development, a way to handle this scenario is to delay saving the state changes in the local database. Instead, you would just send out a message as part of the REST API. When processing that message, you could store any necessary state changes and send additional messages if needed. At that point, since you’re in the context of a message handler, you can rely on the Outbox guarantees.
However, there are scenarios in which this is not feasible. We sometimes see large codebases in which this practice is not followed, at which point retroactively introducing this change is a considerable effort. This is especially true when messaging is introduced in an already running system. Sometimes there are other valid reasons for not delaying storing the data.
We’re working on filling that gap with the new package mentioned.