0

Iam working on ActiveMQ application where iam using a consumer which uses Session.CLIENT_ACKNOWLEDGE.

Iam sending the messages received from queue in consumer to a webservice.Assume if i don do message.acknowledge() all the messages sent to webservice are back on the queue in enqueued state.

My question is how to retrieve the messages again from the queue and use it.I used retroactive=true and tried redelivery also but all of them are failing.

How to avoid this.

gtonic
  • 2,295
  • 1
  • 24
  • 32
Chetan Sistla
  • 165
  • 2
  • 16

1 Answers1

0

if you use message.acknowledge() all consumed messages are not available again in the same queueu because the are considered as delivered!

can you explain why you need to consume again the messages already consumed. retroactive is for consumers who was offline and when starting connection to receive messages sent before the connection.

You need to setup the prefetch policy for the consumer to 400 in this case. You can read to understand the concept http://activemq.apache.org/what-is-the-prefetch-limit-for.html

If you want to treat messages one by one with counter you need to set prefetch to 1 and acknowledge each message when you treat 200 you don't acknowledge.

Hassen Bennour
  • 3,885
  • 2
  • 12
  • 20
  • The logic is simple I get message from activemq send it to webservice if i get 200OK i do message.acknowledge() and if i get anything other than 200 OK i dont want to perform message.acknowledge() which makes the message goes back to the enqueued state and i want to retry sending the message again.How to do this – Chetan Sistla Oct 14 '16 at 11:28
  • I updated my response, the defaults are : persistent queues (default value: 1000) non-persistent queues (default value: 1000). This means if you don't acknowledge the 500 first messages the broker will not send to your consumer any message until acknowledgment – Hassen Bennour Oct 14 '16 at 11:37
  • Is there any other way to dequeue old messages which are enqueued?Actually i just faced the same above problem while dealing with expired messages also. – Chetan Sistla Oct 14 '16 at 12:26
  • can you explain, because if the consumer is connected normally he had received the enqueued old messages – Hassen Bennour Oct 14 '16 at 12:48
  • public void onMessage(Message msg){ if (msg instanceof ActiveMQMessage){ try { //Send text message to process(message) } catch (JMSException e) { log.error("Failed to process message: " + msg); } } } – Chetan Sistla Oct 14 '16 at 13:45
  • Process() method is where I do not do a message.acknowledge().if I do not do it all the messages which the onMessage() receives are sent back to the queue and the messages are in enqueued state and are in DispatchedQueue.My question is how to retrieve these messages which are in DispatchedQueue and which are in enqueued state. – Chetan Sistla Oct 14 '16 at 13:50