org.springframework.retry.RecoveryCallback Java Examples
The following examples show how to use
org.springframework.retry.RecoveryCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleDemo.java From retry with Apache License 2.0 | 8 votes |
public static void main(String[] args) throws Exception { RetryTemplate template = new RetryTemplate(); // 策略 SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(2); template.setRetryPolicy(policy); String result = template.execute( new RetryCallback<String, Exception>() { @Override public String doWithRetry(RetryContext arg0) { throw new NullPointerException(); } } , new RecoveryCallback<String>() { @Override public String recover(RetryContext context) { return "recovery callback"; } } ); LOGGER.info("result: {}", result); }
Example #2
Source File: RocketMQInboundChannelAdapter.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public void onMessage(Message message) { boolean enableRetry = RocketMQInboundChannelAdapter.this.retryTemplate != null; if (enableRetry) { RocketMQInboundChannelAdapter.this.retryTemplate.execute(context -> { RocketMQInboundChannelAdapter.this.sendMessage(message); return null; }, (RecoveryCallback<Object>) RocketMQInboundChannelAdapter.this.recoveryCallback); } else { RocketMQInboundChannelAdapter.this.sendMessage(message); } }
Example #3
Source File: DefaultPollableMessageSource.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
public void setRecoveryCallback(RecoveryCallback<Object> recoveryCallback) { this.recoveryCallback = context -> { if (!shouldRequeue((MessagingException) context.getLastThrowable())) { return recoveryCallback.recover(context); } throw (MessagingException) context.getLastThrowable(); }; }
Example #4
Source File: TestChannelBinder.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void accept(Message<?> message) { try { if (IntegrationBinderInboundChannelAdapter.this.retryTemplate == null) { try { processMessage(message); } finally { attributesHolder.remove(); } } else { IntegrationBinderInboundChannelAdapter.this.retryTemplate .execute(context -> { processMessage(message); return null; }, (RecoveryCallback<Object>) IntegrationBinderInboundChannelAdapter.this.recoveryCallback); } } catch (RuntimeException e) { if (getErrorChannel() != null) { getMessagingTemplate() .send(getErrorChannel(), buildErrorMessage(null, new IllegalStateException( "Message conversion failed: " + message, e))); } else { throw e; } } }
Example #5
Source File: RocketMQInboundChannelAdapter.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
public void setRecoveryCallback(RecoveryCallback<? extends Object> recoveryCallback) { this.recoveryCallback = recoveryCallback; }
Example #6
Source File: TestChannelBinder.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") // Temporarily unused until DLQ strategy for this binder becomes a requirement public void setRecoveryCallback( RecoveryCallback<? extends Object> recoveryCallback) { this.recoveryCallback = recoveryCallback; }
Example #7
Source File: AbstractMessageChannelBinder.java From spring-cloud-stream with Apache License 2.0 | 2 votes |
/** * Implementations can override the default {@link ErrorMessageSendingRecoverer}. * @param errorInfrastructure the infrastructure. * @param properties the consumer properties. * @return the recoverer. */ protected RecoveryCallback<Object> getPolledConsumerRecoveryCallback( ErrorInfrastructure errorInfrastructure, C properties) { return errorInfrastructure.getRecoverer(); }