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

时间:2018-03-02 17:08:38

标签: spring-integration polling

从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>

New Java Config:

@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 :(得分:0)

您所指的完全在AbstractPollingEndpoint

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

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

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

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

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

您可以将@ServiceActivator(inputChannel="theInput", outputChannel="jobRequestsChannel")移至Pojo方法,只需使用@BeanPojo声明一个bean。或者,因为您已经在该类上使用@MessageEndpoint,您可以考虑启用@ComponentScan让应用程序上下文为您的类提取一个bean。

另一种方式非常类似MessageHandler实施,需要调用Pojo

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