Class AsyncRetryScheduler

java.lang.Object
org.axonframework.messaging.core.retry.AsyncRetryScheduler
All Implemented Interfaces:
DescribableComponent, RetryScheduler

public class AsyncRetryScheduler extends Object implements RetryScheduler, DescribableComponent
RetryScheduler implementation that schedules retries on a ScheduledExecutorService based on a given policy.
Author:
Allard Buijze
  • Constructor Details

    • AsyncRetryScheduler

      public AsyncRetryScheduler(RetryPolicy retryPolicy, ScheduledExecutorService executor)
      Initialize the retry scheduler using given retryPolicy and execute retries on given executor.

      This implementation will schedule retry tasks in memory.

      Parameters:
      retryPolicy - The policy indicating if and when to perform retries
      executor - The executor service on which retries are scheduled
  • Method Details

    • scheduleRetry

      public <M extends Message, R extends Message> MessageStream<R> scheduleRetry(@Nonnull M message, @Nullable ProcessingContext processingContext, @Nonnull Throwable cause, @Nonnull RetryScheduler.Dispatcher<M,R> dispatcher)
      Description copied from interface: RetryScheduler
      Schedules the given message to retry dispatching using the given dispatching function.

      Implementations may execute the retries immediately or schedule them later retry. The returned MessageStream may complete after several retry attempts or immediately, depending on whether retries are configured or if the cause indicates that a retry could possibly provide a different outcome.

      If the scheduler determines that a retry can not lead to a different outcome, it must return immediately with a failed MessageStream holding the original given cause as its failure.

      Specified by:
      scheduleRetry in interface RetryScheduler
      Type Parameters:
      M - The type of message to (re)dispatch
      R - The type of message expected as a result of dispatching
      Parameters:
      message - The Message being dispatched
      processingContext - The context under which the message is dispatched
      cause - The cause of the failure.
      dispatcher - The function to execute individual retries
      Returns:
      a MessageStream representing the result of the last attempt
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.