0
votes

I am using stomp client on node.js with ActiveMQ. Currently the producer pushes the message into queue and if client (consumer) is connected then it consumes the message. If client is not connected then messages are pending in queue until or unless some consumer is connected.

In my case, each operation performed by consumer is expensive and can take up to 2 hours. I want to consume a message and then stop consuming messages from queue until that operation is complete. Currently as soon message is pushed into queue, client pulls all messages from queue automatically. What I want is to pull one message wait for its completion and then pull again from queue and so on. This is to avoid race conditions.

For example if I have three tasks in a queue: A | B | C

The current flow is that all messages are consumed in queue leaving it empty.

What I want is to consume 1 message i.e

A | B | (C is consumed)

Perform actions on C.

After everything is completed by consumer then take next message

A | (B is consumed)

And so on...

Reason for which I'm using ActiveMQ for communicating is that it is reliable for delivering messages if in case node app crashes, or my server is down etc.

1
@JustinBertram package being used is npmjs.com/package/stomp-clientAbdullah Amin
@JustinBertram Currently as soon message is pushed into queue, client pulls all messages from queue automatically. What I want is to pull one message. Wait for it's completion, then pull again from queue and so on.Abdullah Amin
What version of ActiveMQ are you using?Justin Bertram

1 Answers

0
votes

With ActiveMQ 5 based solutions the client can configure the prefetch size that the broker will then fill with available messages. If you use the activemq.prefetchSize header on the STOMP subscribe and set the value to one the broker would send one message at a time assuming you've used either the client or client-individual acknowledgement mode. In your case you could use client acknowledgement and then send the ACK when you've processed the message and the broker would then dispatch another message if one is available.