Reputation: 458
I'm new to ActiveMQ, and doing a project that involves reading messages from a queue and then processing them in batches. (I'm shoveling them to a 3rd party API that can only handle 100 at a time, although less than 100 is fine)
Every sample I've found involves event-driven code that treats every message atomically. Is there a gem, plugin, or other approach that will allow pseudocode of the form
while(!queue.empty?) do
chunk = []
while(!queue.empty? && chunk.size < 100) do
chunk << queue.read
end
do_something_with(chunk)
end
Or is this a fool's errand or what?
Upvotes: 0
Views: 1008
Reputation: 22279
I think you could use message grouping for this case. That way, you can group messages in one batch, given the sender has set the grouping headers. Here is info on how ActiveMQ handles this: ActiveMQ on Message Grouping
I'm no ruby coder, but I assume you are using some "on_message" function when you talk about event driven API. IBM has a nice tutorial how to do receive JMS message groups in a message listener (MDB). It's java and WebSphere MQ, but the JMS concept should be consistent.
IBM on JMS message grouping in MDB
You might or might not be able to translate that into rails, but it might give some hints while waiting for the correct code sample to show up here! :)
Upvotes: 1