-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement ContextHolderRequestHandlerAdvice #3869
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
Comments
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 4, 2022
…ice. spring-projectsGH-3869: Add unit tests. spring-projectsGH-3869: Create Advice. spring-projectsGH-3869: Correct typo.
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 4, 2022
…ice. spring-projectsGH-3869: Add unit tests. spring-projectsGH-3869: Create Advice. spring-projectsGH-3869: Correct typo.
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 4, 2022
…ice. spring-projectsGH-3869: Add unit tests. spring-projectsGH-3869: Create Advice. spring-projectsGH-3869: Correct typo.
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 21, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Dec 23, 2022
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Feb 12, 2023
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Feb 26, 2023
adel-haidar
added a commit
to adel-haidar/spring-integration
that referenced
this issue
Feb 26, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes we may have a context during message handling. See a
DelegatingSessionFactory
as an example. So, we store somekey
into the thread local, thenSftpMessageHandler
obtain the session and and performs respective logic.All this is done in the
SftpMessageHandler
transparently, but in case ofDelegatingSessionFactory
we just chose the target (S)FTP connection according previously mentionedkey
stored in the thread local.See more info in SO question and in docs.
So, current solution for the context holder is a bit involved, especially when we use one-way channel adapter for (S)FTP.
The proposed
ContextHolderRequestHandlerAdvice
could be a single way to inject into such an outbound endpoint.Its logic is pretty simple:
MessageHandler
finally
I feel like this advice can have these options:
keyProvider
- theFunction<Message<?>, Object>
to obtain the key from the message, or whatever source for the key is available. Could be as simple assetKeyProvider((m) -> m.getHeaders().get("myKey"));
contextSetHook
- aConsumer<Object>
- just delegates to the method on the target context holder. For example in case of the mentionedDelegatingSessionFactory
it could be like thissetContextSetHook(myDelegatingFactory::setThreadKey);
contextClearHook
- aConsumer<Object>
- just delegates to the method on the target context holder.For example in case of the mentionedDelegatingSessionFactory
it could be like thissetContextClearHook((key) -> myDelegatingFactory.clearThreadKey());
Probably internal logic could be implemented as a
try-with-resource
.The text was updated successfully, but these errors were encountered: