Customizing Messages
Custom Identifiers
At this point you already know how to use the Request Reply pattern with temporary queues and fixed queues, but what happens when you need to assign a custom correlation ID or message ID from the Client? Remember that by default the correlation ID is null and the message ID is autogenerated by broker when sending the request message.
In some scenarios, the correlation identifier used by default may not be suitable for your application's needs. To address this, you can implement a custom MQMessageCreator when sending messages. This allows you to set a specific correlation ID or message ID that aligns with your application's requirements.
Here is an example of how to implement a custom MQMessageCreator to set a specific correlation ID:
public Mono<Result> doRequest(String request) {
// return sender.send(...) for sending without expecting a reply
return requestReplyTmp.requestReply(context -> {
Message message = context.createTextMessage(request);
String customId = MQUtils.generateUniqueId();
MQUtils.setMessageId(message, customId);
MQUtils.setCorrelationId(message, customId);
return message;
}, Duration.ofSeconds(5))
.map(...);
}