/** * This makes a <code>MessageProperties</code> with the specified properties. * * @param timestamp The timestamp. * @param correlationId The correlation identifier. * @param replyTo The reply to destination. * @since 1.0 */ public static MessageProperties makeMessageProperties(final Date timestamp, final String correlationId, final String replyTo) { final MessageProperties messageProperties = new MessageProperties(); messageProperties.setTimestamp(timestamp); messageProperties.setCorrelationIdString(correlationId); if (correlationId != null) { try { messageProperties.setCorrelationId(correlationId.getBytes("UTF-8")); } catch (UnsupportedEncodingException exception) { } } messageProperties.setReplyTo(replyTo); return messageProperties; }
/** * This makes a <code>MessageProperties</code> with the specified properties. * * @param timestamp The timestamp. * @param correlationId The correlation identifier. * @param replyTo The reply to destination. * @since 1.0 */ public static MessageProperties makeMessageProperties(final Date timestamp, final String correlationId, final String replyTo) { final MessageProperties messageProperties = new MessageProperties(); messageProperties.setTimestamp(timestamp); messageProperties.setCorrelationIdString(correlationId); if (correlationId != null) { try { messageProperties.setCorrelationId(correlationId.getBytes("UTF-8")); } catch (UnsupportedEncodingException exception) { } } messageProperties.setReplyTo(replyTo); return messageProperties; }
@Override public void recover(final Message message, final Throwable cause) { Map<String, Object> headers = message.getMessageProperties().getHeaders(); headers.put("x-exception-stacktrace", ExceptionUtils.getFullStackTrace(cause)); headers.put("x-exception-message", ExceptionUtils.getMessage(cause)); headers.put("x-exception-root-cause-message", ExceptionUtils.getRootCauseMessage(cause)); headers.put("x-original-exchange", message.getMessageProperties().getReceivedExchange()); headers.put("x-original-routingKey", message.getMessageProperties().getReceivedRoutingKey()); headers.put("x-original-queue", message.getMessageProperties().getConsumerQueue()); headers.put("x-recover-time", new Date().toString()); String deadLetterExchangeName = rabbitmqProperties.getDeadLetterConfig().getDeadLetterExchange().getName(); String deadLetterRoutingKey = rabbitmqProperties.getDeadLetterConfig().createDeadLetterQueueName(message.getMessageProperties().getConsumerQueue()); headers.put("x-dead-letter-exchange", deadLetterExchangeName); headers.put("x-dead-letter-queue", deadLetterRoutingKey); if(headers.containsKey("correlation-id")) { message.getMessageProperties().setCorrelationIdString((String) headers.get("correlation-id")); } headers.putAll(loadAdditionalHeaders(message, cause)); for (MessageExceptionHandler messageExceptionHandler : messageExceptionHandlers) { try { messageExceptionHandler.handle(message, cause); } catch (Exception e) { // To catch any exception in the MessageExceptionHandler to avoid the interruption in other MessageExceptionHandlers log.error("Exception occurred while processing '{}' message exception handler.", messageExceptionHandler, e); } } this.errorTemplate.send(deadLetterExchangeName, deadLetterRoutingKey, message); log.warn("Republishing failed message to exchange '{}', routing key '{}', message {{}} , cause {}", deadLetterExchangeName, deadLetterRoutingKey, message, cause); }
/** * {@inheritDoc} */ @Override public Message postProcessMessage(final Message message) throws AmqpException { if (message == null) { return message; } final MessageProperties messageProperties = message.getMessageProperties(); messageProperties.setTimestamp(this.properties.getTimestamp()); final byte[] correlationId = this.properties.getCorrelationId(); messageProperties.setCorrelationId(correlationId); messageProperties.setCorrelationIdString(this.properties.getCorrelationIdString()); messageProperties.setReplyTo(this.properties.getReplyTo()); messageProperties.setExpiration(this.properties.getExpiration()); return message; } }
/** * {@inheritDoc} */ @Override public Message postProcessMessage(final Message message) throws AmqpException { if (message == null) { return message; } final MessageProperties messageProperties = message.getMessageProperties(); messageProperties.setTimestamp(this.properties.getTimestamp()); final byte[] correlationId = this.properties.getCorrelationId(); messageProperties.setCorrelationId(correlationId); messageProperties.setCorrelationIdString(this.properties.getCorrelationIdString()); messageProperties.setReplyTo(this.properties.getReplyTo()); messageProperties.setExpiration(this.properties.getExpiration()); return message; } }