// Set up a consumer to respond to our producer
Future<Message> received = executor.submit(new Callable<Message>() {
@Override
public Message call() throws Exception {
Message message = null;
for (int i = 0; i < 10; i++) {
message = template.receive(ROUTE);
if (message != null) {
break;
}
Thread.sleep(100L);
}
assertNotNull("No message received", message);
template.send(message.getMessageProperties().getReplyTo(), message);
return message;
}
});
Message message = new Message("test-message".getBytes(), new MessageProperties());
Message reply = template.sendAndReceive("", ROUTE, message);
assertEquals(new String(message.getBody()), new String(received.get(1000, TimeUnit.MILLISECONDS).getBody()));
assertNotNull("Reply is expected", reply);
assertEquals(new String(message.getBody()), new String(reply.getBody()));
// Message was consumed so nothing left on queue
reply = template.receive(ROUTE);
assertEquals(null, reply);
cachingConnectionFactory.destroy();
}