-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some way to pass context to scheduled threads when using PollerMetadata (or make it customizable, or let it pass a TaskDecorator, or use the passed TaskExecutor) #9524
Comments
Let's if this helps somehow: https://docs.spring.io/spring-integration/reference/6.4-SNAPSHOT/configuration/namespace-taskscheduler.html! In other words you can provide your own Also pay attention to this chapter: https://docs.spring.io/spring-integration/reference/6.4-SNAPSHOT/security.html#security-context-propagation. The point is that threads around Not sure, though, what kind of context could be propagated from the source polling channel adapter... |
Thanks for all the interesting info!! I would not like to expose a global TaskScheduler (or touch the autoconfigured one), because my needs are specific to this integrationflow, and because I think that exposing a TaskScheduler has also side-effects over other non-integration spring domains (like @Scheduleds) About the question on what kind of context propagate, for instance when using a filter that checks the message corresponds to your TenantContext, or simply use any bean that is scoped (@JobScoped or @RequestScoped in filter() or handle()). For this you need to decorate the task and propagate the contexts. If you use a fromSupplier() as a source, your taskexecutor is wrapped on a scheduler and the context is not propagated, so I think some convenient methods for dealing with this in the PollerMetadata could be helpful |
Yeah... I might need more info about your use-case. |
I'll check the first option! The other one I already disregarded! |
BTW, the documentation says When polling consumers provide an explicit task executor reference in their configuration, the invocation of the handler methods happens within that executor’s thread pool and not the main scheduler pool. However, when no task executor is provided for an endpoint’s poller, it is invoked by one of the main scheduler’s threads. And this does not seem the case, because it looks like the task is executed in the scheduler which wraps the call to the custom executor, instead of passing it to the latter directly |
Perhaps is easier if I explain my need. Basically I just need to create an IntegrationFlow from a supplier that is a @Request-Scoped List bean. IntegrationFlows cannot be Request-Scoped, so I need a way to set the context at supplier time before retrieving next value from the list in the supplier lambda |
Perhaps we look into different things.
So, scheduler triggers that simple You probably need to revise your solution into something what is really initiated from the request. See more info in docs: https://docs.spring.io/spring-integration/reference/gateway.html |
Thanks for the explanation @artembilan
Perhaps if the API allowed to set a TaskDecorator for the Scheduler... I even tried a backdoor like |
We may just expose the whole |
Doesn't look like you need a custom
The
|
So, since we have figured out what exactly is your need, I decided to go ahead and exposed Still want to here a use-case for that |
This is perfect! I am triggering a job on every REST request, and the polling source for my StandardIntegrationFlow is a @RequestScoped collection that i fill previously in every request. Then I start and stop the StandardIntegrationFlow manually at my convenience to process the input |
OK. Dynamic |
I need my integration flows to see parent thread context (threadlocals, requestcontext, securitycontext etc..) so I use the setDecoratorTask on the custom TaskExecutor. This works well when IntegrationFlow is built from a Jms.messageDrivenChannelAdapter for instance.
But I also have an IntegrationFlow.fromSupplier(supplier, spec -> spec.taskExecutor(custom)), and in this case, it looks like a TaskScheduler executor is built-in by default to wrap my custom TaskExecutor in PollerMetadata so it opens an intermediate thread that makes my TaskDecorator not being able to see the main thread context and therefore propagate it to spawned tasks.
TaskScheduler does not seem to be configurable and I can't find an option to pass a TaskDecorator to it's "sheduling-" name prefixed threads
The text was updated successfully, but these errors were encountered: