Reputation: 1513
I'm struggling with picking up the right way to poll server with constant interval (eg ~1 second).
The flow goes as follows
We can have multiple threads, as the client application might receive multiple message in the short time - polling should start immediately
I don't want to reinvent the wheel, maybe there is a proper tool that works with java/spring that I can use?
Key features
I was going through various libs like Apache Camel or Spring Integration PollableChannel, but I feel like none of these is going to give me the right solution out of the box.
If there is no lib like this - I'm going to write it on my own using redis and simple loop, but maybe someone has faced similar problem.
Upvotes: 4
Views: 2164
Reputation: 121177
If I understand your architecture correctly, the point is to call the same HTTP endpoint from the client application until expected result. In this case I would suggest something like RequestHandlerRetryAdvice
with an AlwaysRetryPolicy
and a FixedBackOffPolicy
(1 second by default).
To simulate an exception I would suggest an ExpressionEvaluatingRequestHandlerAdvice
with the propagateOnSuccessEvaluationFailures = true
option to re-throw an exception from the onSuccessExpression
when reply from the server is pending
.
Both of these advises (in the exact RequestHandlerRetryAdvice
, ExpressionEvaluatingRequestHandlerAdvice
) you need to apply to @ServiceActivator
for the HttpRequestExecutingMessageHandler
.
See more info in the Reference Manual: https://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#message-handler-advice-chain
Upvotes: 3