Your consumer is not sending a result...
@Override
public void onMessage(Message message) {
System.out.println("consumer output: " + message);
}
Change it to a simple POJO; the container's MessageListenerAdapter
will take care of the conversion for you, and send the result.
@Override
public String handleMessage(String message) {
System.out.println("consumer output: " + message);
return "result";
}
EDIT:
You also haven't set up any exchange or routing to your queue. If you want to use default exchange/routing, use...
convertSendAndReceive("", queueName, item.toString());
EDIT2:
Or, set the routingKey
on the template to the queue name and then you can use the simpler method.
The ...sendAndReceive()
methods are meant for request/reply scenarios so blocking is required. To do it asynchronously, you have to use one of the ...send()
methods, and wire up your own SimpleListenerContainer
to receive the replies; you will have to do your own correlation. Use
public void convertAndSend(Object message, MessagePostProcessor postProcessor)
and in your message post processor, set the replyTo
and correlationId
headers...
message.getMessageProperties().setReplyTo("foo");
message.getMessageProperties().setCorrelationId("bar");
Or, build the Message
object yourself (e.g by using the MessageBuilder
) and use the send
method...
template.send(MessageBuilder.withBody("foo".getBytes())
.setReplyTo("bar")
.setCorrelationId("baz".getBytes())
.build());
Each request needs a unique correlationId
so you can correlate the response.