I was able to get an example of what I'm looking for to work using Spring AMQP, but not with Integration.
Is there a working Spring Integration sample available that has the following features:
- A client that initiates message specifying a return address
- The client monitors the named queue (specified in the return address) for the reply
- An endpoint that receives the message
- The message is sent back on the queue specified by the client as the return address
- The client getting the message it was waiting for
Surprisingly I have not been able to make this happen.
My client looks like this when it sends the message:
Code:
template.convertAndSend( msg, new MessagePostProcessor() {
public Message postProcessMessage(Message message) throws AmqpException {
message.getMessageProperties().setReplyTo("sms-reply-queue");
try {
message.getMessageProperties().setCorrelationId(UUID.randomUUID().toString().getBytes("UTF-8"));
}
catch (UnsupportedEncodingException e) {
throw new AmqpException(e);
}
return message;
}
});
This specifies the queue name as The client monitors messages on the reply queue like this:
Code:
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory((ConnectionFactory) context.getBean("rabbitConnFactory"));
container.setQueueNames("sms-inbound-queue");
container.setMessageListener(new MessageListenerAdapter(new MessageListenerAdapter() {
public void handleMessage(String text) {
System.out.println("Message received: " + text);
}
}));
I can't get my integration solution to call back onto this reply queue, though I can get a similar solution to work without integration. This is a simple matter of semantics. Can anyone tell me what my spring integration config should look like to make this happen?
As a starting point, here is what I have right now:
Code:
<amqp:inbound-channel-adapter channel="smsInboundChannel"
queue-names="sms-inbound-queue" connection-factory="rabbitConnectionFactory" />
<channel id="smsInboundChannel"/>
<service-activator input-channel="smsInboundChannel" ref="smsRestAdaptor" method="handleMessage" />
<channel id="smsOutputChannel"/>
<!-- <stream:stdout-channel-adapter id="smsOutputChannel"/> -->
<rabbit:queue name="sms-inbound-queue"/>
<rabbit:queue name="sms-reply-queue"/>
I haven't defined anything to associate with the smsOutputChannel and so I have an error. You can see that I've commented out the stdout-channel-adapter line, which I've done because I want the reply to go to queue the client named. So what I have definitely won't work; what I need is the last piece of the puzzle. How do I define an output channel for my service-activator.
Keep in mind too that this is a simplified case. Later there will be several chained steps leading up to and away from my service activator. I will want to maintain the reply queue name throughout and send back to that named queue when the chain is complete.
Thanks,
Scott