@Override public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); /* * NOTE: The following IF and subsequent ELSE IF should never happen under normal interaction and * it should always go to the last ELSE * However, given that this is a handler subscribing to the public channel and that we can't control what * type of Message may be sent to that channel (user decides to send a Message manually) the 'IF/ELSE IF' provides * a safety net to handle any message properly. */ if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), null); } else if (amqpMessage == null) { logger.error("No raw message header in " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), amqpMessage); } else { this.recoverer.recover(amqpMessage, (Throwable) message.getPayload()); } }
@Override public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); /* * NOTE: The following IF and subsequent ELSE IF should never happen under normal interaction and * it should always go to the last ELSE * However, given that this is a handler subscribing to the public channel and that we can't control what * type of Message may be sent to that channel (user decides to send a Message manually) the 'IF/ELSE IF' provides * a safety net to handle any message properly. */ if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), null); } else if (amqpMessage == null) { logger.error("No raw message header in " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), amqpMessage); } else { this.recoverer.recover(amqpMessage, (Throwable) message.getPayload()); } }