首页 文章

Spring集成InboundChannelAdapter从xml到Java导致新的轮询控制台日志

提问于
浏览
1

从xml到Java的Spring Integration Bean . 现在我为每个@InboundChannelAdapter获取新的控制台日志,这是我之前没有得到的:

AbstractPollingEndpoint task-scheduler-7 DEBUG在轮询期间没有收到消息,返回'false'

这是初始配置:

<file:inbound-channel-adapter id="the-file-input"
    directory="file:${import.file.dir.incomingFileDir}" channel="the-input" filter="customFilter" />
<si:channel id="the-input" />
<si:service-activator input-channel="the-input"
    output-channel="job-requests" ref="theJobLauncher" />

<bean id="theJobLauncher" class="com.example.POJO">

</bean>

新的Java配置:

@Bean(name="theInput")
public MessageChannel manifestInputChannel() {
    return new DirectChannel();
}

@Bean(name="theFileInput")
@InboundChannelAdapter(channel="theInput")
public MessageSource<File> filesInboundChannelAdapter(@Value("${import.file.dir.incomingFileDir}") String incomingDirectory){
    FileReadingMessageSource sourceReader = new FileReadingMessageSource();
    sourceReader.setDirectory(new File(incomingDirectory));
    sourceReader.setFilter(customFileFilter);

    sourceReader.afterPropertiesSet();

    return sourceReader;
}


@Bean
@ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")
public Pojo theJobLauncher() {
    Pojo theJobLauncher = new Pojo();

    return theJobLauncher;
}

theJobJaucher使用@MessageEndpoint注释和@ServiceActivator方法引用一个类

这个新的控制台日志行是否正常或我的配置有问题?

1 回答

  • 0

    您所指的完全在_2353341中:

    if (message == null) {
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Received no Message during the poll, returning 'false'");
            }
            result = false;
        }
    

    所以,这绝对意味着你已经以某种方式将 org.springframework.integration 类别的 Logger 配置为 DEBUG 级别 .

    尽管如此,这并没有伤害 . 您只是在以前的版本中没有该日志记录配置 .

    您无需亲自致电 sourceReader.afterPropertiesSet(); . 这是一个应用程序上下文回调,它确实会被调用,因为你将它声明为bean .

    您的 @ServiceActivator 定义不正确 . 仅当您使用 MessageHandler 实现时, @Bean 注释才可以存在 .

    您可以将 @ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel") 移动到 Pojo 方法,只需使用 @Bean 为该 Pojo 声明一个bean . 或者既然你已经在该类上使用了 @MessageEndpoint ,你可以考虑打开 @ComponentScan 让应用程序上下文为你的类提取一个bean .

    另一种方式真的像 MessageHandler 实现调用你的 Pojo

    @Bean
    @ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")
    public MessageHandler theJobLauncherServiceActivator(Pojo theJobLauncher) {
        return new MethodInvokingMessageHandler(theJobLauncher, (String) null);
    }
    

相关问题