QUEUE_INI use IBM MQ9, latest spring boot, and IBM's spring-boot-starter.
I'd like to receive a message with @JmsListner, then without committing it, send another message to another queue, receive response and then commit all.
So far I has next:
@JmsListener(destination = QUEUE_IN, selector = "type='com.example.MainRequest")
public void receiveMessage(Message message) throws JMSException {
LOG.info("Received {} <{}>", QUEUE_IN, message);
jmsTemplate2.convertAndSend(QUEUE_OUT, "SUB Request", requestMsg -> {
requestMsg.setStringProperty("type", "com.example.SubRequest");
return requestMsg;
});
LOG.info("Message sent");
Message reply = jmsTemplate2.receiveSelected(QUEUE_IN, "type='com.example.SubResponse'");
LOG.info("Received reply from {}: <{}>", QUEUE_IN, reply);
}
I'm stuck on 'Message sent'. It looks like sub-request hasn't really sent. I see in MQ UI that queue depth is 1 but there is no message inside, and my sub-request listener also doesn't see any messages.
I've also tried use sendAndReceive
method:
Message reply = jmsTemplate.sendAndReceive(QUEUE_OUT, session -> {
Message msg = session.createTextMessage();
msg.setStringProperty("type", "com.example.SubRequest");
LOG.info("Sending msg: <{}> to {}", msg, QUEUE_OUT);
return msg;
});
But I do not have permissions to access model queue.
Is there any way to make this work?
UPDATE:
I made this work with combined help from you all. I end up with separate service to only send sub request with @Transactional(propagation = Propagation.REQUIRES_NEW)
. All other logic remained within main listener.
Also turning on transactions start/end logs was helpful:
logging:
level:
org.springframework.transaction.interceptor: trace
Model queue
implies dynamic queues, is this correct are you using a dynamic queue for the output message. In your code you appear to be listening for a message inreceiveSelected
forQUEUE_IN
, should that not beQUEUE_OUT
? I think you should receive the same insufficient permissions on the model queue for both sets of code. - chughtsQUEUE_OUT
. Another service will receive it and send reply back toQUEUE_IN
. So it is correct (there was a mistake in logging) - Alexander Stepchkov