使用 MessageSessionCallback
MessageSessionCallback
从 Spring Integration 4.2 开始,你可以将 MessageSessionCallback<F, T> 实现与 <int-ftp:outbound-gateway/>(Java 中的 FtpOutboundGateway)结合使用,在 Session<FTPFile> 中结合 requestMessage 上下文执行任何操作。它可用于任何非标准或低层级的 FTP 操作,并允许访问集成流定义和函数式接口(Lambda)实现注入,如下例所示:
@Bean
@ServiceActivator(inputChannel = "ftpChannel")
public MessageHandler ftpOutboundGateway(SessionFactory<FTPFile> sessionFactory) {
return new FtpOutboundGateway(sessionFactory,
(session, requestMessage) -> session.list(requestMessage.getPayload()));
}
另一个例子可能是在发送或检索文件数据时进行预处理或后处理。
在使用XML配置时,<int-ftp:outbound-gateway/> 提供了一个 session-callback 属性,允许您指定 MessageSessionCallback bean的名称。
备注
session-callback 与 command 和 expression 属性是互斥的。在使用 Java 进行配置时,FtpOutboundGateway 类中提供了不同的构造函数。