如何记录空通道

How to log null channel

在spring boot - integration中,有一个重命名文件的过滤器,如果实例成功重命名文件,它应该继续流程,否则它将被传递到空通道。

想登录null频道查看未成功重命名的文件名。

已尝试以下 solution.But 应用程序启动期间出现异常。你能建议实现这个的解决方案吗?

<integration:filter input-channel="filesInChannel" expression="headers['file_originalFile'].renameTo(new java.io.File(headers['file_originalFile'].absolutePath + '.lock'))" 
        output-channel="filesHeaderEnricher" discard-channel="nullChannel" throw-exception-on-rejection="false">
</integration:filter> 
<integration:channel id="nullChannel">
  <integration:interceptors>
    <integration:wire-tap channel="logNullChannel"/>
 </integration:interceptors>
</integration:channel>
<integration:logging-channel-adapter id="logNullChannel" level="DEBUG"/>

如果为 nullchannel 添加了 logging-channel-adapter 则异常:

  java.lang.IllegalStateException: The bean name 'nullChannel' is reserved.
    at org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor.registerNullChannel(DefaultConfiguringBeanFactoryPostProcessor.java:112) ~[spring-integration-core-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
    at org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor.postProcessBeanFactory(DefaultConfiguringBeanFactoryPostProcessor.java:63) ~[spring-integration-core-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
    at 

nullChannel根本无法拦截。您需要为您的用例考虑一些其他渠道或为 NullChannel 类别打开调试日志记录:

 if (this.loggingEnabled && this.logger.isDebugEnabled()) {
        this.logger.debug("message sent to null channel: " + message);
    }