如何在Spring集成中取消订阅文件通道?

问题描述:

我想知道如何取消订阅文件通道。我试图在我的服务中引导频道并调用取消订阅方法,但我无法访问消息处理程序,因此我正在使用FileReadingMessageSource。有什么想法吗?如何在Spring集成中取消订阅文件通道?

您需要显示您的配置,但通常您要停止引用源的SourcePollingChannelAdapter来停止适配器。您不想取消订阅,除非适配器停止,否则会导致错误。

编辑

您的配置,如果入站适配器是在一个名为IntegrationCongfig类,它的bean名字会integrationConfig.test.inboundChannelAdapter(注意小写i)...

@Autowired 
@Qualifier("integrationConfig.test.inboundChannelAdapter") 
private SourcePollingChannelAdapter test; 

@Autowired 
private StandardIntegrationFlow processFileFlow; 

.. 。

this.test.stop();    // stop the adapter 
this.processFileFlow.stop(); // stops all components in the flow 

停止流程将取消订阅处理程序e频道;但你必须先停止适配器。

+0

这里是我的配置:@Bean \t公共MessageChannel fileInputChannel(){返回新DirectChannel();} // @豆 \t公共IntegrationFlow processFileFlow(){回报IntegrationFlows \t。从 “fileInputChannel” \t .handle(” incomingFileProcessor“,”validateAndStartJob“)。get(); \t} @Bean \t @InboundChannelAdapter(值= FILE_INPUT_CHANNEL,轮询器= @Poller(FIXEDDELAY = _1000)) 公共FileReadingMessageSource试验(@Value( “$ {dirPath}”)字符串目录){返回monitorDirectory(目录);} – ram533

+0

不要在评论中放置代码;你可以看到它很难阅读;在将来,编辑问题,并添加一个你已经这样做的评论。看到我的答案编辑。 –