public void run() { try { releaseMessage(message); } catch (Exception e) { Exception exception = new MessageDeliveryException(message, "Failed to deliver Message after delay.", e); MessageChannel errorChannel = resolveErrorChannelIfPossible(message); if (errorChannel != null) { ErrorMessage errorMessage = new ErrorMessage(exception); boolean sent = channelTemplate.send(errorMessage, errorChannel); if (!sent && logger.isWarnEnabled()) { logger.warn("Failed to send MessageDeliveryException to error channel.", exception); } } else if (logger.isWarnEnabled()) { logger.warn("No error channel available. MessageDeliveryException will be ignored.", exception); } } } }, delay, TimeUnit.MILLISECONDS);
@Override public void handleError(final ErrorMessage message) { if (!(message.getPayload() instanceof MessagingException)) { throw new RuntimeException( "received unexpected exception within ErrorMessage " + "containing headers: " + message.getHeaders(), message.getPayload()); final MessagingException ex = (MessagingException) message.getPayload(); final Message<?> failedMessage = ex.getFailedMessage(); final Exception cause = (Exception) ex.getCause();
private Message<?> sendAndReceiveMessage(Message<?> message) { this.initializeIfNecessary(); Assert.notNull(message, "request message must not be null"); if (this.requestChannel == null) { throw new MessageDeliveryException(message, "No request channel available. Cannot send request message."); } if (this.replyChannel != null && this.replyMessageCorrelator == null) { this.registerReplyMessageCorrelator(); } Message<?> reply = this.channelTemplate.sendAndReceive(message, this.requestChannel); if (reply != null && this.shouldThrowErrors && reply instanceof ErrorMessage) { Throwable error = ((ErrorMessage) reply).getPayload(); if (error instanceof RuntimeException) { throw (RuntimeException) error; } throw new MessagingException("gateway received checked Exception", error); } return reply; }
public final void handle(Throwable t) { Message<?> failedMessage = (t instanceof MessagingException) ? ((MessagingException) t).getFailedMessage() : null; MessageChannel errorChannel = this.resolveErrorChannel(failedMessage); boolean sent = false; if (errorChannel != null) { try { if (this.sendTimeout >= 0) { sent = errorChannel.send(new ErrorMessage(t), this.sendTimeout); } else { sent = errorChannel.send(new ErrorMessage(t)); } } catch (Throwable errorDeliveryError) { // message will be logged only if (logger.isWarnEnabled()) { logger.warn("Error message was not delivered.", errorDeliveryError); } } } if (!sent && logger.isErrorEnabled()) { if (failedMessage != null) { logger.error("failure occurred in messaging task with message: " + failedMessage, t); } else { logger.error("failure occurred in messaging task", t); } } }