List of usage examples for org.springframework.amqp.rabbit.core RabbitTemplate convertSendAndReceive
@Override @Nullable public Object convertSendAndReceive(final Object message) throws AmqpException
From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java
@Test public void testAtomicSendAndReceiveWithConversion() throws Exception { final RabbitTemplate template = new RabbitTemplate(new CachingConnectionFactory()); template.setRoutingKey(ROUTE);/* w w w . ja v a 2 s . co m*/ template.setQueue(ROUTE); ExecutorService executor = Executors.newFixedThreadPool(1); // Set up a consumer to respond to our producer Future<String> received = executor.submit(new Callable<String>() { public String call() throws Exception { Message message = null; for (int i = 0; i < 10; i++) { message = template.receive(); if (message != null) { break; } Thread.sleep(100L); } assertNotNull("No message received", message); template.send(message.getMessageProperties().getReplyTo(), message); return (String) template.getMessageConverter().fromMessage(message); } }); String result = (String) template.convertSendAndReceive("message"); assertEquals("message", received.get(1000, TimeUnit.MILLISECONDS)); assertEquals("message", result); // Message was consumed so nothing left on queue result = (String) template.receiveAndConvert(); assertEquals(null, result); }