default UnaryOperator<SimpleMessageListenerContainer> setRetryOpertations(Optional<Integer> maxAttempts, Optional<BackoffOptions> backoffOptions) { StatelessRetryInterceptorBuilder builder = RetryInterceptorBuilder.stateless(); if (maxAttempts.isPresent()) { builder.maxAttempts(maxAttempts.get()); } if (backoffOptions.isPresent()) { BackoffOptions options = backoffOptions.get(); builder.backOffOptions(options.getInitialInterval(), options.getMultiplier(), options.getMaxInterval()); } builder.recoverer(new RejectAndDontRequeueRecoverer()); return setRetryOpertations(builder.build()); } }
@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()); } }
@Bean public RetryOperationsInterceptor rabbitSourceRetryInterceptor() { return RetryInterceptorBuilder.stateless() .maxAttempts(this.properties.getMaxAttempts()) .backOffOptions(this.properties.getInitialRetryInterval(), this.properties.getRetryMultiplier(), this.properties.getMaxRetryInterval()) .recoverer(new RejectAndDontRequeueRecoverer()) .build(); }
@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()); } }
@Bean public RetryOperationsInterceptor rabbitSourceRetryInterceptor() { return RetryInterceptorBuilder.stateless() .maxAttempts(this.properties.getMaxAttempts()) .backOffOptions(this.properties.getInitialRetryInterval(), this.properties.getRetryMultiplier(), this.properties.getMaxRetryInterval()) .recoverer(new RejectAndDontRequeueRecoverer()) .build(); }
retryTemplate.setRetryContextCache(cache); fb.setRetryOperations(retryTemplate); fb.setMessageRecoverer(new RejectAndDontRequeueRecoverer());
retryTemplate.setRetryContextCache(cache); fb.setRetryOperations(retryTemplate); fb.setMessageRecoverer(new RejectAndDontRequeueRecoverer());
private final RejectAndDontRequeueRecoverer recoverer = new RejectAndDontRequeueRecoverer();
private final RejectAndDontRequeueRecoverer recoverer = new RejectAndDontRequeueRecoverer();