JmsTemplate doesn't have build-in API to support JMS 2.0 async sending. I use the ProducerCallback object and call JMS 2.0 async sending API directly on JMS MessageProducer.
The message sent successfully. But if I send 2 large messages (2M message), the second sending will take more time than sending the first message.
From my testing, the first sending takes 133ms, the second sending takes 10417ms. Looks it sends the second message until completed sending first message.
But if I use raw JMS 2.0 async sending API directly (doesn't use JmsTemplate), no block on second sending. From my testing, the first sending takes 50ms, the second sending takes 63ms.
The following code is the JmsTemplate that I used, is there any special handling in Spring JMS that blocks second message sending?
public void sendQueueMsgAsync(String msg, CompletionListener completionListener) {
jmsQueueTemplate.execute(new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
TextMessage txtMsg = session.createTextMessage();
txtMsg.setText(msg);
producer.send(txtMsg, completionListener);
return null;
}
});
}
Than I call it twice to send 2 messages.
start = System.currentTimeMillis();
springJmsService.sendQueueMsgAsync(msgToSend, listener1);
end = System.currentTimeMillis();
timeTaken = end - start;
logger.info("send async queue msg taken1=" + timeTaken);
start = System.currentTimeMillis();
springJmsService.sendQueueMsgAsync(msgToSend, listener2);
end = System.currentTimeMillis();
timeTaken = end - start;
logger.info("send async queue msg taken2=" + timeTaken);