Skip to content

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

Closed
artembilan opened this issue Aug 4, 2022 · 0 comments
Closed

Implement ContextHolderRequestHandlerAdvice #3869

artembilan opened this issue Aug 4, 2022 · 0 comments

Comments

@artembilan
Copy link
Member

Sometimes we may have a context during message handling. See a DelegatingSessionFactory as an example. So, we store some key into the thread local, then SftpMessageHandler obtain the session and and performs respective logic.
All this is done in the SftpMessageHandler transparently, but in case of DelegatingSessionFactory we just chose the target (S)FTP connection according previously mentioned key 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:

  1. Take a key from the request message
  2. Store the value into the context holder
  3. Invoke the MessageHandler
  4. Clean the value from the context holder in the finally

I feel like this advice can have these options:

  1. keyProvider - the Function<Message<?>, Object> to obtain the key from the message, or whatever source for the key is available. Could be as simple as setKeyProvider((m) -> m.getHeaders().get("myKey"));
  2. contextSetHook - a Consumer<Object> - just delegates to the method on the target context holder. For example in case of the mentioned DelegatingSessionFactory it could be like this setContextSetHook(myDelegatingFactory::setThreadKey);
  3. contextClearHook - a Consumer<Object> - just delegates to the method on the target context holder.For example in case of the mentioned DelegatingSessionFactory it could be like this setContextClearHook((key) -> myDelegatingFactory.clearThreadKey());

Probably internal logic could be implemented as a try-with-resource.

@artembilan artembilan added type: enhancement status: waiting-for-triage The issue need to be evaluated and its future decided labels Aug 4, 2022
@artembilan artembilan added ideal-for-user-contribution An issue that would ideal for a user to get started with contributing. and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Sep 21, 2022
@artembilan artembilan added this to the Backlog milestone Sep 21, 2022
adel-haidar added a commit to adel-haidar/spring-integration that referenced this issue Dec 4, 2022
adel-haidar added a commit to adel-haidar/spring-integration that referenced this issue Dec 4, 2022
adel-haidar added a commit to adel-haidar/spring-integration that referenced this issue Dec 4, 2022
@artembilan artembilan modified the milestones: Backlog, 6.1.0-M1 Dec 5, 2022
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
@artembilan artembilan modified the milestones: 6.1.0-M1, 6.1.x Feb 21, 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
@artembilan artembilan modified the milestones: 6.1.x, 6.1.0-RC1 Mar 31, 2023
@artembilan artembilan added in: core and removed ideal-for-user-contribution An issue that would ideal for a user to get started with contributing. labels Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant