MessageSessionCallback

从 Spring Integration 版本 4.2 开始,你可以使用 <int-sftp:outbound-gateway/> (SftpOutboundGateway) 中的 MessageSessionCallback<F, T> 实现,在具有 requestMessage 上下文的 Session<SftpClient.DirEntry> 上执行任何操作。你可以将其用于任何非标准或底层 SFTP 操作(或多个操作),例如允许从集成流定义或函数式接口(lambda)实现注入中进行访问。以下示例使用 lambda:

Starting with Spring Integration version 4.2, you can use a MessageSessionCallback<F, T> implementation with the <int-sftp:outbound-gateway/> (SftpOutboundGateway) to perform any operation on the Session<SftpClient.DirEntry> with the requestMessage context. You can use it for any non-standard or low-level SFTP operation (or several), such as allowing access from an integration flow definition, or functional interface (lambda) implementation injection. The following example uses a lambda:

@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler sftpOutboundGateway(SessionFactory<SftpClient.DirEntry> sessionFactory) {
    return new SftpOutboundGateway(sessionFactory,
         (session, requestMessage) -> session.list(requestMessage.getPayload()));
}

另一个示例可能是预处理或后处理正在发送或检索的文件数据。

Another example might be to pre- or post-process the file data being sent or retrieved.

在使用 XML 配置时,<int-sftp:outbound-gateway/> 提供了一个 session-callback 属性,可让您指定 MessageSessionCallback bean 名称。

When using XML configuration, the <int-sftp:outbound-gateway/> provides a session-callback attribute that lets you specify the MessageSessionCallback bean name.

session-callbackcommandexpression 属性互斥。使用 Java 配置时,SftpOutboundGateway 类提供了不同的构造函数。

The session-callback is mutually exclusive with the command and expression attributes. When configuring with Java, the SftpOutboundGateway class offers different constructors.