I have a stream of object deltas (that is, JSON objects describing changes to other objects) coming from a third party's messaging queue. I need to apply these to the appropriate objects in a database (translating deltas to state). The deltas are inherently ordered.
As it is, I intend to pipe these deltas into our own RabbitMQ cluster, whence a group of Java servers will pull them and then apply them to the database (the Java is where the database update logic is centralized).
The application of the deltas needs to be multithreaded, but I want to ensure that the deltas for a given object are always applied in order. To truly guarantee this, only one thread can ever process deltas for a given object.
To that end, as I read them off the third party queue and before I place them in RabbitMQ, I figured I could split the deltas into queues by the uuid of the corresponding object. Basically, each delta has an object_uuid field, and I'd modulo that uuid by say, 50, and then use the result as the routing key, so that I would have 50 queues of ordered deltas within RabbitMQ.
At that point, it is simply (heh) a matter of ensuring that I have a single consumer per queue (although I can still have multiple queues per consumer). I thought the 'exclusive' parameter to queue declarations in AMQP might give me the desired behavior, and it kind of does, but unfortunately it comes with the prohibitive side effect that the queue is deleted when the consumer disconnects (this is a fleet of Java servers that come up and down with every release -- queues must persist between releases).
This can't be an uncommon dilemma, but I don't see anything that quite fits the problem. Is there no construct in RabbitMQ or AMQP that I can use to my advantage here? Is there a way I can rethink this problem that avoids the issue? Or do I need to look at distributed locking solutions?
object deltasmean? Any chance you could give an example of what these deltas are and if they're all applicable to a single object or they apply to multiple objects, each with multiple deltas? - kha