Examples

Talend ESB Mediation Developer Guide

EnrichVersion
6.2
EnrichProdName
Talend ESB
task
Installation and Upgrade
Design and Development
EnrichPlatform
Talend ESB

Using the Spring integration endpoint

You can set up a Spring integration endpoint using a URI, as follows:

<beans:beans xmlns="http://www.springframework.org/schema/integration"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:beans="http://www.springframework.org/schema/beans"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/integration
      http://www.springframework.org/schema/integration/spring-integration.xsd
      http://camel.apache.org/schema/spring
      http://camel.apache.org/schema/spring/camel-spring.xsd">

   <!-- Spring integration channels -->
   <channel id="inputChannel"/>
   <channel id="outputChannel"/>
   <channel id="onewayChannel"/>

   <!-- Spring integration service activators -->
   <service-activator input-channel="inputChannel" ref="helloService" 
      method="sayHello"/>
   <service-activator input-channel="onewayChannel" ref="helloService" 
      method="greet"/>

   <!-- custom bean -->
   <beans:bean id="helloService" class=
      "org.apache.camel.component.spring.integration.HelloWorldService"/>

   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
      <route>
         <from uri="direct:twowayMessage"/>
         <to uri="spring-integration:inputChannel?inOut=true&
            inputChannel=outputChannel"/>
      </route>
      <route>
         <from uri="direct:onewayMessage"/>
         <to uri="spring-integration:onewayChannel?inOut=false"/>
      </route>
   </camelContext>

<!-- Spring integration channels -->
<channel id="requestChannel"/>
<channel id="responseChannel"/>

<!-- custom Camel processor -->
<beans:bean id="myProcessor" 
   class="org.apache.camel.component.spring.integration.MyProcessor"/>

<!-- Camel route -->
<camelContext  xmlns="http://camel.apache.org/schema/spring">
   <route>
      <from uri=
         "spring-integration://requestChannel?outputChannel=responseChannel
&inOut=true"/>
      <process ref="myProcessor"/>
   </route>
</camelContext>

Or directly using a Spring integration channel name:

<beans:beans xmlns="http://www.springframework.org/schema/integration"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:beans="http://www.springframework.org/schema/beans"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

<!-- Spring integration channel -->
<channel id="outputChannel"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">
   <route>
      <from uri="outputChannel"/>
      <to uri="mock:result"/>
   </route>
</camelContext>

The Source and Target adapter

Spring integration also provides the Spring integration's source and target adapters, which can route messages from a Spring integration channel to a Camel endpoint or from a Camel endpoint to a Spring integration channel.

This example uses the following namespaces:

<beans:beans xmlns="http://www.springframework.org/schema/integration"
   xmlns:beans="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:camel-si="http://camel.apache.org/schema/spring/integration"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/integration
      http://www.springframework.org/schema/integration/spring-integration.xsd
      http://camel.apache.org/schema/spring/integration       
      http://camel.apache.org/schema/spring/integration/  \\
         camel-spring-integration.xsd
      http://camel.apache.org/schema/spring
      http://camel.apache.org/schema/spring/camel-spring.xsd">

You can bind your source or target to a Camel endpoint as follows:

<!-- Create the Camel context here -->
<camelContext id="camelTargetContext" 
   xmlns="http://camel.apache.org/schema/spring">
   <route>
      <from uri="direct:EndpointA" />
      <to uri="mock:result" />
   </route>
   <route>
      <from uri="direct:EndpointC"/>
      <process ref="myProcessor"/>
   </route>
</camelContext>

<!-- We can bind the camelTarget to the Camel context's endpoint by -->
<!-- specifying the camelEndpointUri attribute -->
<camel-si:camelTarget id="camelTargetA" 
   camelEndpointUri="direct:EndpointA" expectReply="false">
   <camel-si:camelContextRef>
      camelTargetContext
   </camel-si:camelContextRef>
</camel-si:camelTarget>

<camel-si:camelTarget id="camelTargetB" 
   camelEndpointUri="direct:EndpointC" replyChannel="channelC"
   expectReply="true">
   <camel-si:camelContextRef>
      camelTargetContext
   </camel-si:camelContextRef>
</camel-si:camelTarget>

<camel-si:camelTarget id="camelTargetD" 
   camelEndpointUri="direct:EndpointC" expectReply="true">
   <camel-si:camelContextRef>
      camelTargetContext
   </camel-si:camelContextRef>
</camel-si:camelTarget>

<beans:bean id="myProcessor" 
   class="org.apache.camel.component.spring.integration.MyProcessor"/>