Answer the question
In order to leave comments, you need to log in
How to implement ReplyToQueue?
Hello, I have application 1 and it has a method
@PostMapping
public ResponseEntity<String> createOrder(@RequestBody OrderRequest order) throws JMSException {
log.info("### 1 ### Order Service sending order message '{}' to the queue", order.getMessage());
MQQueue orderRequestQueue = new MQQueue("DEV.QUEUE.1");
jmsTemplate.convertAndSend(orderRequestQueue, order.getMessage(), textMessage -> {
textMessage.setJMSCorrelationID(order.getIdentifier());
return textMessage;
});
return new ResponseEntity(order, HttpStatus.ACCEPTED);
}
@JmsListener(destination = "DEV.QUEUE.1")
public void receive(Message message) throws JMSException {
TextMessage textMessage = (TextMessage) message;
final String textMessageBody = textMessage.getText();
log.info("### 2 ### Payment Service received message: {} with correlationId: {}",
textMessageBody,
textMessage.getJMSCorrelationID());
// some random logic to complete the order (80% of times it returns true)
Random random = new Random(); //message to convertAndSend
String orderCompleted = (random.nextInt(101) >= 20) ? "payment_ok" : "payment_failed";
// send response
log.info("### 3 ### Payment Service sending response");
MQQueue mqQueue = new MQQueue("DEV.QUEUE.1");
jmsTemplate.convertAndSend(mqQueue, orderCompleted, responseMessage -> {
responseMessage.setJMSCorrelationID(textMessage.getJMSCorrelationID());
return responseMessage;
});
}
Answer the question
In order to leave comments, you need to log in
It's all written here:
MQQueue mqQueue = new MQQueue("DEV.QUEUE.1");
jmsTemplate.convertAndSend(mqQueue, orderCompleted, responseMessage -> {
responseMessage.setJMSCorrelationID(textMessage.getJMSCorrelationID());
return responseMessage;
});
Destination destination = textMessage.getJMSReplyTo();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question