List of usage examples for org.springframework.amqp AmqpException AmqpException
public AmqpException(String message, Throwable cause)
From source file:org.springframework.amqp.rabbit.AsyncRabbitTemplate.java
private void sendDirect(Channel channel, String exchange, String routingKey, Message message, CorrelationData correlationData) { message.getMessageProperties().setReplyTo(Address.AMQ_RABBITMQ_REPLY_TO); try {//w ww . java 2 s.c o m if (channel instanceof PublisherCallbackChannel) { this.template.addListener(channel); } this.template.doSend(channel, exchange, routingKey, message, this.template.isMandatoryFor(message), correlationData); } catch (Exception e) { throw new AmqpException("Failed to send request", e); } }
From source file:org.springframework.amqp.rabbit.connection.RabbitResourceHolder.java
public void commitAll() throws AmqpException { try {/*w w w. j a va2s . c om*/ for (Channel channel : this.channels) { if (deliveryTags.containsKey(channel)) { for (Long deliveryTag : deliveryTags.get(channel)) { channel.basicAck(deliveryTag, false); } } channel.txCommit(); } } catch (IOException e) { throw new AmqpException("failed to commit RabbitMQ transaction", e); } }
From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java
@Test public void testAtomicSendAndReceiveWithConversionAndMessagePostProcessor() throws Exception { final RabbitTemplate template = new RabbitTemplate(new CachingConnectionFactory()); template.setRoutingKey(ROUTE);//from w w w . j ava 2 s . c om 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((Object) "message", new MessagePostProcessor() { public Message postProcessMessage(Message message) throws AmqpException { try { byte[] newBody = new String(message.getBody(), "UTF-8").toUpperCase().getBytes("UTF-8"); return new Message(newBody, message.getMessageProperties()); } catch (Exception e) { throw new AmqpException("unexpected failure in test", e); } } }); 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); }
From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java
@Test public void testAtomicSendAndReceiveWithConversionAndMessagePostProcessorUsingRoutingKey() throws Exception { 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;/* w ww . j a v a 2s.co m*/ 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 (String) template.getMessageConverter().fromMessage(message); } }); String result = (String) template.convertSendAndReceive(ROUTE, (Object) "message", new MessagePostProcessor() { public Message postProcessMessage(Message message) throws AmqpException { try { byte[] newBody = new String(message.getBody(), "UTF-8").toUpperCase().getBytes("UTF-8"); return new Message(newBody, message.getMessageProperties()); } catch (Exception e) { throw new AmqpException("unexpected failure in test", e); } } }); assertEquals("MESSAGE", received.get(1000, TimeUnit.MILLISECONDS)); assertEquals("MESSAGE", result); // Message was consumed so nothing left on queue result = (String) template.receiveAndConvert(ROUTE); assertEquals(null, result); }
From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java
@Test public void testAtomicSendAndReceiveWithConversionAndMessagePostProcessorUsingExchangeAndRoutingKey() throws Exception { 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;//from www. j a va 2s .c om 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 (String) template.getMessageConverter().fromMessage(message); } }); String result = (String) template.convertSendAndReceive("", ROUTE, "message", new MessagePostProcessor() { public Message postProcessMessage(Message message) throws AmqpException { try { byte[] newBody = new String(message.getBody(), "UTF-8").toUpperCase().getBytes("UTF-8"); return new Message(newBody, message.getMessageProperties()); } catch (Exception e) { throw new AmqpException("unexpected failure in test", e); } } }); assertEquals("MESSAGE", received.get(1000, TimeUnit.MILLISECONDS)); assertEquals("MESSAGE", result); // Message was consumed so nothing left on queue result = (String) template.receiveAndConvert(ROUTE); assertEquals(null, result); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.java
private void checkStartState() { if (!this.isRunning()) { try {//w ww.j a v a 2 s . c om Assert.state(this.startedLatch.await(60, TimeUnit.SECONDS), "Container is not started - cannot adjust queues"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new AmqpException("Interrupted waiting for start", e); } } }