Spring集成和多线程,丢失了所需的标头

时间:2013-12-30 08:07:19

标签: java multithreading spring spring-integration

我是Spring集成的新手,我想将一些数据导出到6个CSV文件中,我使用Spring集成它可以正常使用单线程,但是当我想实现多线程方法时,我有错误消息“必需的标题不可用:“,在6个文件中,我只生成了3个或2个文件。

enter image description here

<bean id="taskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="threadFactory" ref="threadFactory" />
    <property name="corePoolSize" value="20" />
</bean>


<bean id="threadFactory"
    class="com.sqli.hybris.fredhoppersearch.utils.ExportToFredhopperThreadFactory"
    scope="tenant">
    <constructor-arg
        value="#{T(de.hybris.platform.core.Registry).getCurrentTenant()}" />
</bean>


<int:gateway id="indexerGateway" default-request-channel="indexElementChannel"
    service-interface="com.sqli.hybris.fredhoppersearch.si.IndexerGateway" />



<int:channel id="indexElementChannel">
    <int:dispatcher task-executor="taskExecutor" />
</int:channel>

<!-- <int:channel id="indexElementChannel" /> -->

<int:filter input-channel="indexElementChannel"
    output-channel="itemFilteredChannel" ref="dataFilter" method="accept" />

<int:channel id="itemFilteredChannel" />

<int:header-value-router input-channel="itemFilteredChannel"
    header-name="mode">
    <int:mapping value="FULL" channel="fullChannel" />
    <int:mapping value="INCREMENTAL" channel="incrementalChannel" />
    <int:mapping value="RUPTURE" channel="deleteChannel" />
</int:header-value-router>

<int:channel id="fullChannel" />
<int:channel id="incrementalChannel" />
<int:channel id="deleteChannel" />

<!-- Data Transformer -->

<int:transformer input-channel="fullChannel"
    output-channel="itemTransformedChannel" ref="fullTransformer" method="transform" />

<int:transformer input-channel="incrementalChannel"
    output-channel="itemTransformedChannel" ref="incrementalTransformer"
    method="transform" />

<int:transformer input-channel="deleteChannel"
    output-channel="itemTransformedChannel" ref="deleteTransformer"
    method="transform" />


<int:aggregator input-channel="itemTransformedChannel"
    method="aggregateData" output-channel="aggregatedChannel"
    release-strategy="releaseBean" release-strategy-method="canRelease"
    send-timeout="12000" send-partial-result-on-expiry="false"
    expire-groups-upon-completion="true">
    <bean class="com.sqli.hybris.fredhoppersearch.si.FredhopperDataAggregator"
        scope="tenant" />
</int:aggregator>

<int:channel id="aggregatedChannel">
</int:channel>

<int:channel id="itemTransformedChannel" />
<int:header-value-router input-channel="aggregatedChannel"
    header-name="mode">
    <int:mapping value="FULL" channel="fullExportChannel" />
    <int:mapping value="INCREMENTAL" channel="fullExportChannel" />
    <int:mapping value="RUPTURE" channel="fullExportChannel" />
</int:header-value-router>


<int:channel id="fullExportChannel" />
<int:service-activator input-channel="fullExportChannel"
    ref="fullIndexer" method="index" />

<bean id="dataFilter"
    class="com.sqli.hybris.fredhoppersearch.si.FredhopperDataFilter"
    scope="tenant" />

<alias name="defaultReleaseBean" alias="releaseBean" />
<bean id="defaultReleaseBean"
    class="com.sqli.hybris.fredhoppersearch.si.FredhopperReleaseStrategy"
    scope="tenant" />

但是当我尝试让它在多线程中运行时。

我有这些消息

org.springframework.integration.MessageHandlingException: java.lang.IllegalArgumentException: required header not available:  exporterConfig
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:76)
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:64)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)

我也尝试将春豆的scop改为原型,但它没有用, 任何想法,

感谢您的帮助,

2 个答案:

答案 0 :(得分:1)

  

java.lang.IllegalArgumentException:必需的标头不可用:exporterConfig

MessagingMethodInvokerHelper用于方法参数之一时,@Header抛出此异常。在你的情况下,它是ServiceActivatingHandler

因此,您的一些<int:service-activator>使用该注释从方法参数的标头中提取值,但是您的消息没有{i} MessageHeaders的标头。而且我没有看到你把那个标题放到消息上的地方。

或者只是将其标记为@Header(required = false),或者尝试弄清楚,您不会提供exporterConfig标题。

答案 1 :(得分:0)

在header-value-router中,您尝试根据标题名称&#39;模式&#39;进行广告尝试,但没有可用的标题名称