I'm new to this topic. I'm Using JMS listener to listen to an Active MQ which contains split messages. I need to listen to the queue till last message and then send it to UI all together. I'm able to listen to the queue and grab messages but I do not know how many split messages will be available so i'm not able to send it all together. Is there any way to make listener to do the above operation? Like if there is no more messages available in queue, will jms listener produces a null value? Any idea or help will be really helpful.
I'm Using the below code to listen to Queue using JMS Listener.
private static final String ORDER_RESPONSE_QUEUE = "mail-response-queue";
@JmsListener(destination = ORDER_RESPONSE_QUEUE)
public void receiveMessage(final Message<InventoryResponse> message) throws JMSException {
LOG.info("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
MessageHeaders headers = message.getHeaders();
LOG.info("Application : headers received : {}", headers);
InventoryResponse response = message.getPayload();
LOG.info("Application : response received : {}",response);
LOG.info("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
}
Can i get Queue information using JMS Listener?
by jmx you have access to informations about destinations, like this for example you can know how messages are pending in a Queue.
Note that this can change if new messages are sent
Why not consuming messages and when there is no messages received you display ?? You have method below which returns null after a timeout if there no messages received.
UPDATE
may be like this :
One solution is to update the acknowledgeMode to
org.apache.activemq.ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE
for sessions creation in your springDefaultMessageListenerContainer.sessionAcknowledgeModeName
and acknowledge each message individually and check after that if the size == 0 (size == 0 means all messages are dispatched and acknowledged).