Announcement Announcement Module
No announcement yet.
Understanding needed on use of <delayer> Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Understanding needed on use of <delayer>


    I would like to understand how can I use <delayer> element as a conditional delay.

    My use case is as below:
    An external service invokes my servlet by passing few details as query parameters.
    I then use these query parameters in further processing. However, further processing should get invoked only based on a condition [the condition is - check for a column value in a db table. If the column value is null, do not process the query parameters else start processing it. The value of this column gets populated by a separate thread]

    I'm thinking of below approach:
    Once the service invokes servlet, get the query parameters and populate them in a Java value object. Create a Spring Integration Message using MessageBuilder and place this Java value object as its payload.
    Place the Message on the input-channel of a chain.
    The first component of this chain will be a <delayer> element that will delay the Message to be processed.

    What I want to know is how can I use the <delayer> element to delay the processing of Message by the chain until a business logic condition is met ?
    I've a separate POJO that connects to db and checks for the column value of a table and returns the value.
    I want the <delayer> to invoke this POJO after every few milliseconds in knowing the returned value of column. If its null, it should keep delaying the message. If its not null, it should pass the Message further in the chain.

    Is this approach possible using a <delayer> element ? If not, does Spring Integration provides any other out-of-box solution to handle my use case defined above ? Or the only way is to handle this via code using Thread.sleep ?

    Thanks to guide.

    Best Regards

  • #2
    Instead of using a delayer, simply invoke your POJO using a <service-activator/> as the first element in the chain.

    Now, configure the <service-activator/> with a <request-handler-advice-chain/> using a RequesHandlerRetryAdvice.

    Configure the RequestHandlerRetryAdvice to use a RetryTemplate with a FixedBackofPolicy (with the backOffPeriod set the number of the milliseconds you want to wait after a failure), and a SimpleRetryPolicy with maxAttempts set to the number of times you want to try - or an AlwaysRetryPolicy if you want to try forever.

    Now, in your POJO, if the column is null, throw an exception and the retry will be invoked (after the backOffPeriod).