Java Reference
In-Depth Information
receiving a message, adds a header indicating the name of the error channel. Spring Integration will use
that header and forward errors encountered in the processing of this message to that channel.
package com.apress.springenterpriserecipes.springintegration;
import org.apache.log4j.Logger;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.message.MessageBuilder;
public class ServiceActivatorThatSpecifiesErrorChannel {
private static final Logger logger = Logger.getLogger(
ServiceActivatorThatSpecifiesErrorChannel.class);
@ServiceActivator
public Message<?> startIntegrationFlow(Message<?> firstMessage)
throws Throwable {
return MessageBuilder.fromMessage(firstMessage).
setHeaderIfAbsent( MessageHeaders.ERROR_CHANNEL,
"errorChannelForMySolution").build();
}
}
Thus, all errors that come from the integration in which this component is used will be directed to
customErrorChannel , to which you can subscribe any component you like.
8-8. Forking Integration Control: Splitters and Aggregators
Problem
You want to fork the process flow from one component to many, either all at once or to a single one
based on a predicate condition.
Solution
You can use a splitter component (and maybe its cohort, the aggregator component) to fork and join
control, respectively.
How it Works
One of the fundamental cornerstones of an ESB is routing. You've seen how components can be chained
together to create sequences in which progression is mostly linear. Some solutions require the capability
to split a message into many constituent parts.
Splitter
It's often more useful to divide large payloads into separate messages with separate processing flows.
In Spring Integration, this is accomplished by using a splitter component. A splitter takes an input
message and asks you, the user of the component, on what basis it should split the Message : you're
responsible for providing the split functionality. Once you've told Spring Integration how to split a
 
Search WWH ::




Custom Search