vmeghani
vmeghani

Reputation: 85

How to deliver multiple messages together to the Listener in ActiveMQ?

I want 100 messages to be delivered together to a consumer through activemq, but at the same time producer will be producing messages one at a time.

Reason I want this is because I don't want to handle the overhead of processing each message individually on delivery, instead we want to do bulk processing on delivery.

Is it possible to achieve this through ActiveMQ or should i write my own modifications to achieve this.

Upvotes: 0

Views: 2537

Answers (2)

Tim
Tim

Reputation: 2027

You could achieve your goal by placing every message into a buffer and only doing your processing when the buffer contains N messages. To make it work, you'd want to use an acknowledgement mode such as CLIENT_ACKNOWLEDGE that allows you to not acknowledge the messages that are sitting in the buffer until they are processed; that way if your client crashed with some messages in its memory, they would be re-delivered when the client comes back up.

Upvotes: 1

Tim Bish
Tim Bish

Reputation: 18366

ActiveMQ is a JMS 1.1 client / broker implementation therefore there is no API to deliver messages in bulk, the async listener dispatches them one at a time. The client does prefetch more than one message though so the overhead of processing them using async listeners is quite low.

Upvotes: 1

Related Questions