Spring and multithreading integration, loss of required header

advertisements

I'm new with Spring integration, i want to export some data into 6 CSV files, i used Spring integration it works fine with Single thread, but when i want to implement a multi threading approach i have Error Message "required header not available:", and in 6 files i got only 3 or 2 files generated .

<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" />

but when i try to make it to run in multithreading.

i have these message

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)

I tried also to change scop of spring beans to prototype but it didn't work , Any idea ,

Thanks for your help,


java.lang.IllegalArgumentException: required header not available: exporterConfig

This Exception is thrown by MessagingMethodInvokerHelper, when you use @Header for one of method argument. And in your case it is to ServiceActivatingHandler.

So, some of your <int:service-activator> use that annotation to extract a value from header for that a method argument, but you Message doesn't have that header withih MessageHeaders. And I don't see a place where you put that header to the Message.

Or just mark it as @Header(required = false), or try to figure out, where you don't provide exporterConfig header.