ESB-configuration-example

Request Flow ——————

# EIP service engine

<beans xmlns:eip="http://servicemix.apache.org/eip/1.0"
xmlns:esb="http://esbinaction.com/examples">
<!-- input, if s.o. send msg to endpoint, automatically send to output. -->
<eip:static-recipient-list service="esb:bookRecipientPipeline"
endpoint="bookRecipientPipelineEndpoint">
<!-- output -->
<eip:recipients>
<eip:exchange-target service="esb:loggerComponent"/>
<eip:exchange-target service="esb:amazonRequest"/>
<eip:exchange-target service="esb:transformBarnesPipeline"/>
</eip:recipients>
</eip:static-recipient-list>
</beans>

# SM-Saxon

<beans xmlns:saxon="http://servicemix.apache.org/saxon/1.0"
xmlns:esb="http://esbinaction.com/examples">
<!-- service name -->
<saxon:xslt service="esb:transformToBarnes"
endpoint="toBarnesEndpoint"
resource="classpath:IsbnToBarnes.xslt" />
</beans>

# Pipeline

<!-- input -->
<eip:pipeline service="esb:transformBarnesPipeline"
endpoint="transformBarnesPipelineEndpoint">
<eip:transformer>
<eip:exchange-target service="esb:transformToBarnes" />
</eip:transformer>
<eip:target>
<eip:exchange-target service="esb:barnesRequest" />
</eip:target>
</eip:pipeline>

# AggregatorMessageLogger SM-Bean

public void onMessageExchange(MessageExchange exchange)
throws MessagingException {
if (exchange.getStatus() != ExchangeStatus.ACTIVE) {
logger.info("state is not active so ignoring call");
return;
}
Element payloadElem = null;
try {
Source contentSource = getInMessage(exchange).getContent();
payloadElem = sourceTransformer.toDOMElement(          Converts message
contentSource);                                   to DOM object
} catch(Exception e) {
logger.error("error while reading payload", e);
throw new MessagingException(e);
}
BookQuote bookQuote = QuoteMessageHelper.                Transforms to
unmarshallQuote(payloadElem);                       BookQuote
logger.info("received quote " + bookQuote.getIsbn() + ", "
+ bookQuote.getPrice() + ", " + bookQuote.getCompanyName());
NormalizedMessage outMessage =                          Creates response
exchange.createMessage();                          message
try {
outMessage.setContent(new StringSource(
QuoteMessageHelper.marshallQuote(bookQuote)));
} catch(Exception e) {
logger.error("error while setting content in out message", e);
throw new MessagingException(e);
}
outMessage.setProperty(                                 Sets correlation
"org.apache.servicemix.eip.splitter.corrid",       identifier
bookQuote.getIsbn());
Integer aggregatorIndex = null;
if("Amazon".equalsIgnoreCase(bookQuote.getCompanyName())) {
aggregatorIndex = new Integer(0);
} else if("BarnesAndNoble".equalsIgnoreCase(
bookQuote.getCompanyName())) {
aggregatorIndex = new Integer(1);
}
outMessage.setProperty(                         Sets message
"org.apache.servicemix.eip.splitter.index", index
aggregatorIndex);
outMessage.setProperty(                         Sets group
"org.apache.servicemix.eip.splitter.count", size
new Integer(2));
exchange.setMessage(outMessage, "out");
channel.send(exchange);
}
<eip:split-aggregator service="esb:quoteAggregator"
endpoint="quoteAggregatorEndpoint">
<eip:target>
<eip:exchange-target service="esb:cheapestPricePipeline"/>
</eip:target>
</eip:split-aggregator>
Advertisements