Class StoreMessageForRetryService

All Implemented Interfaces:
AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, ConnectedService, MessageEventGenerator, Service, StateManagedComponent

@ComponentProfile(summary="Wraps an interlok service and gives the option to store the message in a retry store in the event of an exception.", since="4.9.0", tag="retry") public class StoreMessageForRetryService extends RetryServiceImp

Service which stores unacknowledged messages for future retry.

This class supports both synchronous and asynchronous acknowledgement. This is controlled by the field StoreMessageForRetryServiceTest#setAsynchronousAcknowledgment(boolean).

A message is deemed to be synchronously acknowledged if the wrapped service completes normally. In such cases it is not added to the retry store. If an exception occurs the message is added to the retry store and normal error handling is not invoked.

Where asynchronous acknowledgment is required and a message causes an exception, then the behaviour is determined by the async-auto-retry-on-fail setting. If set to true, then the message is added to the retry store for future retrying and message error handling is not invoked. If set to false, then normal message error handling is invoked. Where no exception occurs the message is added to the retry store to wait for asynchronous acknowledgment.

The following metadata keys control the behaviour of the underlying datastore:

  • "retryAckId" contains the ID that will be used to correlate this message against any asynchronous confirmations; if not specified will default to the messages unique-id
  • "retryAckInterval" contains the number of milliseconds between each retry attempt; if not specified then this service will fail.
  • "retryRetries" contains the maximum number of retries (-1 for forever); if not specified then this service will fail.

  • Constructor Details

    • StoreMessageForRetryService

      public StoreMessageForRetryService()

      Creates a new instance.

      • Default service is NullService
      • asynchronousAcknowledgment is false
      • asyncAutoRetryOnFail is true
  • Method Details

    • start

      public void start() throws CoreException
      Description copied from interface: ComponentLifecycle
      Starts the component.

      Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer, calling start will begin message delivery.

      Specified by:
      start in interface ComponentLifecycle
      Overrides:
      start in class RetryServiceImp
      Throws:
      CoreException - wrapping any underlying Exceptions
      See Also:
    • stop

      public void stop()
      Description copied from interface: ComponentLifecycle
      Stop the component

      A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer, calling stop will pause message delivery. Throwing a RuntimeException may cause unintended consequences

      Specified by:
      stop in interface ComponentLifecycle
      Overrides:
      stop in class JdbcService
      See Also:
    • performService

      protected void performService(AdaptrisMessage msg) throws ServiceException
      Specified by:
      performService in class RetryServiceImp
      Throws:
      ServiceException
      See Also:
      • RetryServiceImpTest#performService(com.adaptris.core.AdaptrisMessage)
    • getService

      public Service getService()

      Returns the Service to use.

      Returns:
      the Service to use
    • setService

      public void setService(Service s)
      Set the service which will initially produce the message to the remote system.
      Parameters:
      s - the Service to use
    • getAsynchronousAcknowledgment

      public boolean getAsynchronousAcknowledgment()

      Returns true if asynchronous acknowledgment is required, otherwise false.

      Returns:
      true if asynchronous acknowledgment is required, otherwise false
    • setAsynchronousAcknowledgment

      public void setAsynchronousAcknowledgment(boolean b)

      Sets whether asynchronous acknowledgment is required.

      Parameters:
      b - true if asynchronous acknowledgment is required, otherwise false
    • getAsyncAutoRetryOnFail

      public boolean getAsyncAutoRetryOnFail()
      Returns:
      the retryOnFail
    • setAsyncAutoRetryOnFail

      public void setAsyncAutoRetryOnFail(boolean b)
      Flag for setting whether to store asynchronous acknolwedgement messages for retrying rather than invoking normal message error handling.
      Parameters:
      b - the retryOnFail to set
    • stopService

      protected void stopService()
      Description copied from class: JdbcService
      Stop the service.

      This is called after before the connection is stopped

      Specified by:
      stopService in class JdbcService