List of usage examples for org.springframework.amqp.rabbit.support RabbitExceptionTranslator convertRabbitAccessException
public static RuntimeException convertRabbitAccessException(Throwable ex)
From source file:org.kurento.rabbitmq.RabbitTemplate.java
@Override public <T> T execute(final ChannelCallback<T> action) { if (this.retryTemplate != null) { try {// w ww. j ava2s. co m return this.retryTemplate.execute(new RetryCallback<T, Exception>() { @Override public T doWithRetry(RetryContext context) throws Exception { return RabbitTemplate.this.doExecute(action); } }); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw RabbitExceptionTranslator.convertRabbitAccessException(e); } } else { return this.doExecute(action); } }
From source file:org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.java
/** * Send the given response message to the given destination. * @param channel the Rabbit channel to operate on * @param replyTo the Rabbit ReplyTo string to use when sending. Currently interpreted to be the routing key. * @param messageIn the Rabbit message to send * @throws Exception if thrown by Rabbit API methods * @see #postProcessResponse(Message, Message) *///from ww w. j a va 2 s. co m protected void sendResponse(Channel channel, Address replyTo, Message messageIn) throws Exception { Message message; if (this.replyPostProcessor == null) { message = messageIn; } else { message = this.replyPostProcessor.postProcessMessage(messageIn); } postProcessChannel(channel, message); try { this.logger.debug("Publishing response to exchange = [" + replyTo.getExchangeName() + "], routingKey = [" + replyTo.getRoutingKey() + "]"); channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish, this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), this.encoding), message.getBody()); } catch (Exception ex) { throw RabbitExceptionTranslator.convertRabbitAccessException(ex); } }
From source file:org.springframework.integration.amqp.inbound.AmqpMessageSource.java
@Override protected AbstractIntegrationMessageBuilder<Object> doReceive() { Connection connection = this.connectionFactory.createConnection(); // NOSONAR - RabbitUtils Channel channel = connection.createChannel(this.transacted); try {/*w ww.jav a 2 s .c o m*/ GetResponse resp = channel.basicGet(this.queue, false); if (resp == null) { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); return null; } AcknowledgmentCallback callback = this.ackCallbackFactory .createCallback(new AmqpAckInfo(connection, channel, this.transacted, resp)); MessageProperties messageProperties = this.propertiesConverter.toMessageProperties(resp.getProps(), resp.getEnvelope(), StandardCharsets.UTF_8.name()); messageProperties.setConsumerQueue(this.queue); Map<String, Object> headers = this.headerMapper.toHeadersFromRequest(messageProperties); org.springframework.amqp.core.Message amqpMessage = new org.springframework.amqp.core.Message( resp.getBody(), messageProperties); Object payload = this.messageConverter.fromMessage(amqpMessage); AbstractIntegrationMessageBuilder<Object> builder = getMessageBuilderFactory().withPayload(payload) .copyHeaders(headers) .setHeader(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, callback); if (this.rawMessageHeader) { builder.setHeader(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage); } return builder; } catch (IOException e) { RabbitUtils.closeChannel(channel); RabbitUtils.closeConnection(connection); throw RabbitExceptionTranslator.convertRabbitAccessException(e); } }