The application should poll the database, send the received entities to the web service and process the response. The remote web service requires a cookie for authentication, which can be obtained or updated by calling http-endpoint / login. Cookie has a lifetime limit.

@Bean fun compoundTriggerAdvice() = CompoundTriggerAdvice(compoundTrigger(), secondaryTrigger()) @Bean fun compoundTrigger() = CompoundTrigger(primaryTrigger()) @Bean fun primaryTrigger() = PeriodicTrigger(15, TimeUnit.SECONDS) @Bean fun secondaryTrigger()= PeriodicTrigger(1, TimeUnit.SECONDS) @Bean fun authMessageSource() = MessageSource<String> { GenericMessage("auth-data") } @Bean fun cookieUpdateFlow(cookieStore: CookieStore): IntegrationFlow = IntegrationFlows .from(authMessageSource(), Consumer { it.poller(Pollers.trigger(compoundTrigger()).advice(compoundTriggerAdvice())) }) .gateway(httpFlow()) .transform(...) .handle(cookieStore) .get() @Bean fun httpFlow() = IntegrationFlow { f -> f .handle(Http.outboundGateway("httpL//localhost:8081/{path}") .httpMethod(HttpMethod.POST) .uriVariable<Any>("path") { ... } .transferCookies(true) .expectedResponseType(String::class.java)) } @Bean fun dbFlow(em: EntityManager, cookieStore: CookieStore): IntegrationFlow = IntegrationFlows .from(Jpa.inboundAdapter(em).entityClass(TestEntity::class.java)) { it.poller(Pollers.fixedDelay(30, TimeUnit.SECONDS)) } .enrichHeaders { it.headerFunction<Any>(DefaultHttpHeaderMapper.COOKIE) { cookieStore.cookie } } .gateway(httpFlow()) .transform(...) .handle(...) .get() 
  1. The cookie is updated every 15 seconds, but if the authentication fails, the application should attempt to update the cookie once a second. The problem is that the CompoundTriggerAdvice is triggered when a message is received from the MessageSource, and not the entire flow. How to make a change trigger at the end of treatment?
  2. dbFlow should not start if there is no cookie yet. Is it possible to start it on an event without resorting to spel in controlBus and also to stop it if the cookie has not yet been updated and authentication does not occur?
  3. Perhaps there is a more beautiful solution?

    1 answer 1

    I think that Contol Bus is good enough for Jpa.inboundAdapter() to control its activity. Just send the stop() or start() command for the corresponding bean.

    If this option does not suit you, then you can try implementing the AbstractMessageSourceAdvice and its beforeReceive() to check the system status before trying to call the target JpaPollingChannelAdapter .

    To change the polling policy, you can implement something like CompoundTriggerAdvice , but with your own method of changing the state of CompoundTrigger and call that method where necessary.

    I don't understand the use case, so I don’t see how it could be better, but you can look in the direction of RequestHandlerRetryAdvice and apply it to the Http.outboundGateway volume. Or in the form of some partial implementation of the AbstractRequestHandlerAdvice , when we check cookies before calling the service, etc.

    Some documentation to help:

    https://docs.spring.io/spring-integration/docs/current/reference/html/#message-handler-advice-chain

    https://docs.spring.io/spring-integration/docs/current/reference/html/#polling-consumer-change-polling-rate