0
votes

I currently have a splitter that is splitting a message into similar messages where I only add a header value that will result in different responses when it goes through the orchestration.

Finally, these messages are sent to an aggregator to aggregate the response together.

Currently, these are working in a multithreaded fashion, but the issue arises when a runtime exception is thrown when inside the splitter/aggregator orchestration and it sends a message to the errorChannel that was set when I instantiated the MessageGatewaySupport class.

I was wondering if there was a way to instead have the exception be sent to the aggregator instead, this would allow my program to continue and would be set as a multistatus response on my side.

Below you can find a simplified setup of the splitter/aggregator orchestration.

<bean id="Splitter" class="com.MessageSplitter">
   <property name="splitFieldName" value="boundIndexList" />
</bean>

<bean id="Aggregator" class="com.MessageAggregator">
   <property name="wrapperNode" value="container" />
</bean>

<int:channel id="splitter_input" />
<int:channel id="splitter_output">
   <int:dispatcher task-executor="executor"/>
</int:channel>

<task:executor id="executor" pool-size="4"/>
<int:channel id="aggregator_input" />

<int:splitter id="splitter" input-channel="splitter_input" output-channel="splitter_output"
      ref="Splitter" method="splitHeaderParamByFieldName" />

<int:chain input-channel="splitter_output" output-channel="aggregator_input">
   <!-- ***RuntimeException thrown here sometimes*** -->
   <int-xml:xslt-transformer xsl-templates="XsltTemplate">
      <int-xml:xslt-param name="customHeader" expression="headers.boundIndexList" />
   </int-xml:xslt-transformer>

   <int:gateway request-channel="outbound_gateway" error-channel="exception_errorChannel" />

</int:chain>

<bean id="messageStore" class="org.springframework.integration.store.SimpleMessageStore" />


<int:aggregator input-channel="aggregator_input" output-channel="aggregator_output" ref="Aggregator"
      method="aggregateMessages" send-partial-result-on-expiry="false" expire-groups-upon-completion="true" message-store="viewResRemoveMessageFromStore" />

Splitter

public List<Message<String>> splitHeaderParamByFieldName(Message<String> message) throws XPathExpressionException {

   List<Message<String>> result = new ArrayList<Message<String>>();

   Object paramValue = message.getHeaders().get(splitFieldName);

   if (paramValue instanceof List<?>) {
      for (Object value : (List<?>) paramValue) {
         Message<String> newMessage = MessageBuilder.withPayload(message.getPayload())
                  .copyHeaders(message.getHeaders()).setHeader("customHeader", value).setHeader("receiveTimeout", 60000).build();
         result.add(newMessage);

      }
   } else {
      result.add(message);
   }

   return result;
}

Right now I have only had runtime exceptions be thrown in the xslt that is transforming the message into a request to a 3rd party application. When this exception happens it causes it to be sent across the channel that was defined as the error channel in the MessagingGatewaySupport class, is there a way to make it so that this exception instead goes to the aggregator?

Secondly, I have a gateway below the xslt, will the output channel of that gatway have to be the aggregator as well? I have yet to have an exception be thrown from that gateway.

Please let me know if you require any more information to help me with this request. I appreciate you taking a look and helping me with various problems.

1

1 Answers

0
votes

You need another gateway between the splitter and chain, with a flow on its error channel to transform and send the failure to the aggregator.

The reply from your inner gateway will go to the chain's output channel.