如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

Apache Mina FTP Server 事件

ApacheMinaFtplet(在 5.2 版本中引入)会监听某些 Apache Mina FTP 服务器事件,并将它们发布为ApplicationEvent,这些事件可由任何ApplicationListener bean、@EventListener bean 方法或事件入站通道适配器接收。spring-doc.cadn.net.cn

目前支持的事件包括:spring-doc.cadn.net.cn

这些类都是 ApacheMinaFtpEvent 的子类;您可以配置一个单一的监听器来接收所有类型的事件。 每个事件的 source 属性是一个 FtpSession,您可以从中获取诸如客户端地址等信息;抽象事件上提供了一个便捷的 getSession() 方法。spring-doc.cadn.net.cn

除会话打开/关闭之外的事件具有另一个属性 FtpRequest,该属性包含命令和参数等属性。spring-doc.cadn.net.cn

To configure the server with the listener (which must be a Spring bean), add it to the server factory:spring-doc.cadn.net.cn

FtpServerFactory serverFactory = new FtpServerFactory();
...
ListenerFactory factory = new ListenerFactory();
...
serverFactory.addListener("default", factory.createListener());
serverFactory.setFtplets(new HashMap<>(Collections.singletonMap("springFtplet", apacheMinaFtpletBean)));
server = serverFactory.createServer();
server.start();

要使用 Spring Integration 事件适配器来消费这些事件:spring-doc.cadn.net.cn

@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
    ApplicationEventListeningMessageProducer producer =
        new ApplicationEventListeningMessageProducer();
    producer.setEventTypes(ApacheMinaFtpEvent.class);
    producer.setOutputChannel(eventChannel());
    return producer;
}