private String getName(RetryContext context) { return (String) context.getAttribute(RetryContext.NAME); } }
Object resource = context.getAttribute("backOffContext");
CircuitBreakerRetryPolicy.CIRCUIT_SHORT_COUNT }) { if (context.hasAttribute(key)) { accessor.setAttribute(key, context.getAttribute(key));
@Test public void testRecoveryCallbackConsumerOnly() { final AtomicReference<RetryContext> context = new AtomicReference<>(); RetryingMessageListenerAdapter<String, String> adapter = new RetryingMessageListenerAdapter<>( (ConsumerAwareMessageListener<String, String>) (r, c) -> { throw new RuntimeException(); }, new RetryTemplate(), c -> { context.set(c); return null; }); @SuppressWarnings("unchecked") ConsumerRecord<String, String> record = mock(ConsumerRecord.class); Consumer<?, ?> consumer = mock(Consumer.class); adapter.onMessage(record, mock(Acknowledgment.class), consumer); assertThat(context.get()).isNotNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_ACKNOWLEDGMENT)).isNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_RECORD)).isSameAs(record); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_CONSUMER)).isSameAs(consumer); }
@Test public void testRecoveryCallbackSimple() { final AtomicReference<RetryContext> context = new AtomicReference<>(); RetryingMessageListenerAdapter<String, String> adapter = new RetryingMessageListenerAdapter<>( r -> { throw new RuntimeException(); }, new RetryTemplate(), c -> { context.set(c); return null; }); @SuppressWarnings("unchecked") ConsumerRecord<String, String> record = mock(ConsumerRecord.class); adapter.onMessage(record, mock(Acknowledgment.class), mock(Consumer.class)); assertThat(context.get()).isNotNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_ACKNOWLEDGMENT)).isNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_RECORD)).isSameAs(record); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_CONSUMER)).isNull(); }
@Test public void testRecoveryCallbackAckAndConsumer() { final AtomicReference<RetryContext> context = new AtomicReference<>(); RetryingMessageListenerAdapter<String, String> adapter = new RetryingMessageListenerAdapter<>( (AcknowledgingConsumerAwareMessageListener<String, String>) (r, a, c) -> { throw new RuntimeException(); }, new RetryTemplate(), c -> { context.set(c); return null; }); @SuppressWarnings("unchecked") ConsumerRecord<String, String> record = mock(ConsumerRecord.class); Acknowledgment ack = mock(Acknowledgment.class); Consumer<?, ?> consumer = mock(Consumer.class); adapter.onMessage(record, ack, consumer); assertThat(context.get()).isNotNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_ACKNOWLEDGMENT)).isSameAs(ack); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_RECORD)).isSameAs(record); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_CONSUMER)).isSameAs(consumer); }
@Test public void testRecoveryCallbackAckOnly() { final AtomicReference<RetryContext> context = new AtomicReference<>(); RetryingMessageListenerAdapter<String, String> adapter = new RetryingMessageListenerAdapter<>( (AcknowledgingMessageListener<String, String>) (r, a) -> { throw new RuntimeException(); }, new RetryTemplate(), c -> { context.set(c); return null; }); @SuppressWarnings("unchecked") ConsumerRecord<String, String> record = mock(ConsumerRecord.class); Acknowledgment ack = mock(Acknowledgment.class); adapter.onMessage(record, ack, mock(Consumer.class)); assertThat(context.get()).isNotNull(); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_ACKNOWLEDGMENT)).isSameAs(ack); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_RECORD)).isSameAs(record); assertThat(context.get().getAttribute(RetryingMessageListenerAdapter.CONTEXT_CONSUMER)).isNull(); }
/** * Retrieve the {@link Message} from the context. * @param context the context. * @return the message. * @see #MESSAGE */ public static Message getMessage(RetryContext context) { return (Message) context.getAttribute(MESSAGE); }
/** * Retrieve the {@link Address} from the context. * @param context the context. * @return the address. * @see #ADDRESS */ public static Address getAddress(RetryContext context) { return (Address) context.getAttribute(ADDRESS); }
private String getName(RetryContext context) { return (String) context.getAttribute(RetryContext.NAME); } }
@Override public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { Object mappingName = context.getAttribute(MAPPING_NAME_RETRY_ATTRIBUTE); if (mappingName != null) { log.debug("Attempt {} to forward HTTP request using '{}' mapping has failed. {}", context.getRetryCount() + 1, mappingName, retrieveErrorMessage(throwable)); } }
@Override public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { Object mappingName = context.getAttribute(MAPPING_NAME_RETRY_ATTRIBUTE); if (mappingName != null) { if (throwable != null) { log.error("All {} attempts to forward HTTP request using '{}' mapping has failed. {}", context.getRetryCount(), mappingName, retrieveErrorMessage(throwable)); } else { log.debug("Attempt {} to forward HTTP request using '{}' mapping has succeeded", context.getRetryCount() + 1, mappingName); } } }
private void updateMetadataVersionFailureDetails( MetadataRetryContext retryContext ) { Object version = retryContext.getRetryContext().getAttribute( VERSION_KEY ); if ( version != null ) { MetadataVersion metadataVersion = (MetadataVersion) version; systemSettingManager.saveSystemSetting( SettingKey.METADATA_FAILED_VERSION, metadataVersion.getName() ); systemSettingManager.saveSystemSetting( SettingKey.METADATA_LAST_FAILED_TIME, new Date() ); } }
Object value = retryContext.getRetryContext().getAttribute( name ); Object report = retryContext.getRetryContext().getAttribute( MetadataSyncJob.METADATA_SYNC_REPORT );
private boolean isDatabaseAvailable(RetryContext context) { DescribeDBInstancesResult describeDBInstancesResult; try { describeDBInstancesResult = this.amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier((String) context.getAttribute(DB_INSTANCE_ATTRIBUTE_NAME))); } catch (DBInstanceNotFoundException e) { LOGGER.warn("Database Instance with name {} has been removed or is not configured correctly, no retry possible", getDbInstanceIdentifier()); //Database has been deleted while operating, hence we can not retry return false; } if (describeDBInstancesResult.getDBInstances().size() == 1) { DBInstance dbInstance = describeDBInstancesResult.getDBInstances().get(0); InstanceStatus instanceStatus = InstanceStatus.fromDatabaseStatus(dbInstance.getDBInstanceStatus()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Status of database to be retried is {}", instanceStatus); } return instanceStatus.isRetryable(); } else { throw new IllegalStateException("Multiple databases found for same identifier, this is likely an incompatibility with the Amazon SDK"); } }
private boolean isDatabaseAvailable(RetryContext context) { DescribeDBInstancesResult describeDBInstancesResult; try { describeDBInstancesResult = this.amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier((String) context.getAttribute(DB_INSTANCE_ATTRIBUTE_NAME))); } catch (DBInstanceNotFoundException e) { LOGGER.warn("Database Instance with name {} has been removed or is not configured correctly, no retry possible", getDbInstanceIdentifier()); //Database has been deleted while operating, hence we can not retry return false; } if (describeDBInstancesResult.getDBInstances().size() == 1) { DBInstance dbInstance = describeDBInstancesResult.getDBInstances().get(0); InstanceStatus instanceStatus = InstanceStatus.fromDatabaseStatus(dbInstance.getDBInstanceStatus()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Status of database to be retried is {}", instanceStatus); } return instanceStatus.isRetryable(); } else { throw new IllegalStateException("Multiple databases found for same identifier, this is likely an incompatibility with the Amazon SDK"); } }
Object resource = context.getAttribute("backOffContext");
CircuitBreakerRetryPolicy.CIRCUIT_SHORT_COUNT }) { if (context.hasAttribute(key)) { accessor.setAttribute(key, context.getAttribute(key));