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()
- 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?
- 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?
- Perhaps there is a more beautiful solution?