Here is the code that creates and sends the message:
Code:
public boolean produce(String request)
{
ChannelResolver channelResolver =
new BeanFactoryChannelResolver(context);
MessageChannel requestChannel =
channelResolver.resolveChannelName("producerRequestChannel");
Message<String> message =
MessageBuilder.withPayload(request).build();
Object requestId = message.getHeaders().getId().toString();
boolean messageSentStatus = requestChannel.send(message);
if (messageSentStatus)
{
correlationIdMap.put(requestId.toString(), request);
logger.debug("Sent request with ID " + requestId);
}
else
{
logger.warn("Unable to send message");
}
return messageSentStatus;
}
Here is the code that receives the message, processes the message and sends the response (in a seperate JVM from the requester):
Code:
public Message<String> processRequest(Message<String> message)
{
Object requestId = message.getHeaders().getId();
logger.info("Processing request with ID " + requestId);
String response =
consumer.consume(message.getPayload().toString());
Message<String> responseMessage =
MessageBuilder.withPayload(response).setCorrelationId(requestId.toString()).build();
return responseMessage;
}
Here is the log from the producer:
Code:
DEBUG [main] Sent request with ID d135ad34-7202-4381-9c27-b6196cf586c5 (sandbox.ProducerGateway.java:48)
INFO [main] Sent 1 messages (sandbox.MessagingTest.java:34)
WARN [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] Unable to find request 18b3ed44-6c3e-4d6a-bcaf-082f137c52e5 (sandbox.ProducerGateway.java:73)
And the log from the consumer:
Code:
INFO [main] Starting Consumer (sandbox.Consumer.java:18)
INFO [main] Consumer started (sandbox.Consumer.java:22)
INFO [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] Processing request with ID 18b3ed44-6c3e-4d6a-bcaf-082f137c52e5 (sandbox.ConsumerGateway.java:26)
INFO [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] Consumer 8a52af99-56bc-4ae5-a5ea-d8df69f59eda sleeping for 10 sec (sandbox.Consumer.java:39)
INFO [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] Done processing request (sandbox.Consumer.java:32)
What I found interesting is that the message IDs of the message that was sent from the producer is different than the message ID of the message that the consumer received. With those IDs being different, I cannot match the response to the request.
I have also attached the XML config files. I can post more code if needed.
Thanks