此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1! |
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Integration 6.3.1! |
从版本 6.1 开始,引入了 。
此建议从请求消息中获取一些值,并将其存储在上下文持有者中。
当在目标上完成执行时,该值从上下文中是明确的。
考虑此建议的最佳方式类似于编程流程,我们将一些值存储到 ,从目标调用访问它,然后在执行后清理。
需要以下构造函数参数:a 作为值提供程序、作为上下文集回调和作为上下文清理钩子。ContextHolderRequestHandlerAdvice
MessageHandler
ThreadLocal
ThreadLocal
ContextHolderRequestHandlerAdvice
Function<Message<?>, Object>
Consumer<Object>
Runnable
下面是一个示例,如何将 a 与 a 结合使用:ContextHolderRequestHandlerAdvice
o.s.i.file.remote.session.DelegatingSessionFactory
@Bean
DelegatingSessionFactory<?> dsf(SessionFactory<?> one, SessionFactory<?> two) {
return new DelegatingSessionFactory<>(Map.of("one", one, "two", two), null);
}
@Bean
ContextHolderRequestHandlerAdvice contextHolderRequestHandlerAdvice(DelegatingSessionFactory<String> dsf) {
return new ContextHolderRequestHandlerAdvice(message -> message.getHeaders().get("FACTORY_KEY"),
dsf::setThreadKey, dsf::clearThreadKey);
}
@ServiceActivator(inputChannel = "in", adviceChain = "contextHolderRequestHandlerAdvice")
FtpOutboundGateway ftpOutboundGateway(DelegatingSessionFactory<?> sessionFactory) {
return new FtpOutboundGateway(sessionFactory, "ls", "payload");
}
只需将标头设置为 或 向频道发送消息就足够了。
将该标头中的值设置为 via its .
然后,在执行命令时,根据其 .
当 生成结果时,将根据 对 的调用清除 中的值。
有关更多信息,请参见委派会话工厂。in
FACTORY_KEY
one
two
ContextHolderRequestHandlerAdvice
DelegatingSessionFactory
setThreadKey
FtpOutboundGateway
ls
SessionFactory
DelegatingSessionFactory
ThreadLocal
FtpOutboundGateway
ThreadLocal
DelegatingSessionFactory
clearThreadKey()
ContextHolderRequestHandlerAdvice