'How can I acknowledge a JMS message on another thread and request for redelivery of unacknowledged messages?

Step 1: I need to receive message by one thread.

Step 2: Process and sending ack and redelivery request (throwing exception) by another thread.

Sample code:

List<Message> list=new ArrayList();

@JmsListener(destination = "${jms.queue-name}", concurrency = "${jms.max-thread-count}")
public void receiveMessage(Message message) throws JMSException,UnsupportedEncodingException {
   list.add(message)
}
  
void run() {
   foreach(Message message:list) {
      //need to send ack or throw exception for redeliver if error
   }
}

Now another thread will start and process the list which contains data then how can I send an acknowledgement or throw an exception for redelivery?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source