接收:MessageDeliveryException:Dispatcher没有订户在2个不同的spring集成模块中使用inbound-channel-adapter

时间:2014-08-27 13:51:57

标签: java spring spring-batch spring-integration

我使用类似的基于文件的集成模式有 2 spring integration context 文件。两个扫描目录都在查找消息,如果自己部署则都可以工作。如果我将这两个模块包含在另一个弹簧上下文中,则它们会正常加载但是只有第二个正在运行,第一个正在运行: MessageDeliveryException:Dispatcher没有订阅者。我试图将它们组合成一个没有正增益的上下文文件。我们目前正在使用Spring Integration的2.1.3版和Spring Integration File的2.1版。非常感谢任何想法!

inpayment-context.xml:

<!-- START of in-bound message implementation -->
<int:channel id="file-inpayment-channel" datatype="java.io.File" />
<bean id="xmlPatternFileListFilter" class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
    <constructor-arg value="*.xml" />
</bean>

<task:executor id="batchInBoundExecuter" pool-size="1-1" queue-capacity="20" rejection-policy="CALLER_RUNS" />
<int-file:inbound-channel-adapter directory="file:${inpayment.inbox}" filter="xmlPatternFileListFilter"
    channel="file-inpayment-channel">
    <int:poller id="inPaymentrPoller" fixed-delay="1000" task-executor="batchInBoundExecuter" default="true" />
</int-file:inbound-channel-adapter>

<bean id="inPaymentService" class="com.somepackage.InPaymentBootstrapService" />
<int:service-activator id="batchJobLaunchService" ref="inPaymentService" input-channel="file-inpayment-channel"
    method="schedule" />

<!-- START of out-bound message implementation -->
<int:channel id="inpayment-file-out-channel" datatype="java.io.File" />
<int:gateway id="inboundPaymentGateway" service-interface="com.somepackage.InboundPaymentGateway"
    default-request-channel="inpayment-file-out-channel" />

<int-file:outbound-channel-adapter directory="file:${inpayment.inprocess}" channel="inpayment-file-out-channel"
    auto-create-directory="true" delete-source-files="true" />
<!-- END of out-bound message implementation -->


scheduler-context.xml:
<!-- START of in-bound message implementation -->
<int:channel id="scheduler-file-in-channel" datatype="java.io.File" />
<bean id="simplePatternFileListFilter" class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
    <constructor-arg value="*.xml" />
</bean>

<task:executor id="batchJobRunExecuter" pool-size="1-1" queue-capacity="20" rejection-policy="CALLER_RUNS"/>
<int-file:inbound-channel-adapter directory="file:${scheduler.inbox}" filter="simplePatternFileListFilter"
    channel="scheduler-file-in-channel">
    <int:poller id="schedulerPoller" fixed-delay="5000" task-executor="batchJobRunExecuter" default="true" />
</int-file:inbound-channel-adapter>

<bean id="launchService" class="com.somepackage.BatchJobLaunchService" />
<int:service-activator id="batchJobLaunchService" ref="launchService" input-channel="scheduler-file-in-channel"
    method="schedule" />
<!-- END of in-bound message implementation -->

<!-- START of out-bound message implementation -->
<int:channel id="scheduler-file-out-channel" datatype="java.io.File" />
<int:channel id="scheduler-xml-out-channel" datatype="com.somepackage.ScheduledJob" />

<int:gateway id="batchJobSchedulerGateway" service-interface="com.innovation.customers.guideone.scheduler.integration.SchedulerGateway"
    default-request-channel="scheduler-xml-out-channel" />

<int:transformer input-channel="scheduler-xml-out-channel" output-channel="scheduler-file-out-channel" ref="schedulerFileTransformer"
    method="transformToFile" />
<int-file:outbound-channel-adapter directory="file:${scheduler.completed}" channel="scheduler-file-out-channel"
    auto-create-directory="true" delete-source-files="true" />
<!-- END of out-bound message implementation -->


Common Spring Context:

<context:component-scan base-package="com.somepackage" /> 
<import resource="classpath:g1-scheduler-context.xml"/>
<import resource="classpath:g1-inpayment-context.xml"/> 

编辑

2014-08-27 11:01:01,530 ERROR [batchJobRunExecuter-1][:] org.springframework.integration.handler.LoggingHandler : org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers. at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(Unica‌​stingDispatcher.java:108) at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(Unicast‌​ingDispatcher.java:101)

1 个答案:

答案 0 :(得分:2)

我在配置中看到了这个问题:

<int:service-activator id="batchJobLaunchService" ref="inPaymentService" input-channel="file-inpayment-channel"
    method="schedule" />

<int:service-activator id="batchJobLaunchService" ref="launchService" input-channel="scheduler-file-in-channel"
    method="schedule" />

他们假设是不同的服务,但同时使用相同的id - batchJobLaunchService

Spring默认允许这样做,但只有具有相同id的最后一个bean定义才会获胜。这就是为什么<service-activator>的{​​{1}}没有被贬低的原因,因此launchService bean没有订阅EventDrivenConsumer

小心并为所有豆类使用唯一ID。

在复制案例中投入预测并不容易,但如果您为scheduler-file-in-channel类别打开INFO,则会显示一个bean覆盖另一个bean的消息。