|
如需使用最新稳定版本,请使用 Spring Integration 7.0.4! |
Apache Mina SFTP 服务器事件
ApacheMinaSftpEventListener(在 5.2 版本中引入)会监听某些 Apache Mina SFTP 服务器事件,并将它们发布为 ApplicationEvent,这些事件可由任何 ApplicationListener Bean、@EventListener Bean 方法或 事件入站通道适配器 接收。
目前支持的事件包括:
-
SessionOpenedEvent- 已打开客户端会话 -
DirectoryCreatedEvent- 已创建目录 -
FileWrittenEvent- 文件已写入 -
PathMovedEvent- 文件或目录已被重命名 -
PathRemovedEvent- 文件或目录已被删除 -
SessionClosedEvent- 客户端已断开连接
这些类都是 ApacheMinaSftpEvent 的子类;您可以配置一个单一的监听器来接收所有类型的事件。
每个事件的 source 属性是一个 ServerSession,您可以从中获取诸如客户端地址等信息;抽象事件上提供了一个便捷的 getSession() 方法。
要使用监听器(必须是一个 Spring bean)配置服务器,只需将其添加到 SftpSubsystemFactory 中:
server = SshServer.setUpDefaultServer();
...
SftpSubsystemFactory sftpFactory = new SftpSubsystemFactory();
sftpFactory.addSftpEventListener(apacheMinaSftpEventListenerBean);
...
要使用 Spring Integration 事件适配器来消费这些事件:
@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
ApplicationEventListeningMessageProducer producer =
new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ApacheMinaSftpEvent.class);
producer.setOutputChannel(eventChannel());
return producer;
}