I have two queues that both have distinct data types that affect one another as they're being processed by my application, therefore processing messages from the two queues asynchronously would cause a data integrity issue.
I'm curious as to the best practice for making sure only one consumer is consuming at any given time. Here is a summary of what I have so far:
EventMessages
receive information about external events that may or may not have an impact on the enqueued/existing PurchaseOrderMessages
.
Since we anticipate we'll be consuming more PurchaseOrderMessage
than EventMessage
, maybe we should just ensure the EventMessage
Queue is empty (via the API) before we process anything in PurchaseOrderMessage
Queue - but that gets into the question of wait times, etc. and this all needs to happen as close to real time as possible.
If there's a way to simply pause a Consumer A
until Consumer B
is at rest that might be the simplest solution, I'm just not quite sure which direction I need to go in.
UPDATE
To provide some additional context, a PurchaseOrderMessage
will contain a Origin and Destination.
A EventMessage
also contains location data.
Each time a PurchaseOrderMessage
is processed, it will query the current EventMessage
records for any Event
locations that match the Origin and Destination of that PurchaseOrder
and create an association.
Each time an EventMessage
is processed, it will query the current PurchaseOrderMessage
records for any Origins of Destinations that match that Event
and create an association.
If synchronous queues aren't a good solution, what's an alternative that would insure none of the associations are missed when EventMessages
and PurchaseOrderMessages
are getting published to the app at the same time?
UPDATE 2
Ultimately this data will serve a UI which will have a list of PurchaseOrders
and the events that might be affecting their delivery dates. It would be too slow to do the "Event Check" as the PurchaseOrder
data was being rendered/retrieved by the end user which is why we're wanting to do it as they're processed/consumed.