[CONF] Apache Camel: SpringIntegration (page edited)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[CONF] Apache Camel: SpringIntegration (page edited)

Dhiraj Bokde (Confluence)

SpringIntegration has been edited by willem jiang (Jun 10, 2008).

Change summary:

Added examples to show how to use spring integration component

(View changes)

Content:

Spring Integration Component

The spring-integration: component provides a bridge for Camel components to talk to spring integration endpoints.

URI format

spring-integration:defaultChannelName[?options]

Where defaultChannelName represents the default channel name which is used by the Spring Integration Spring context. It will equal to the inputChannel name for the Spring Integration consumer and the outputChannel name for the Spring Integration provider.

Options

Name Description Example Required default value
inputChannel The spring integration input channel name this endpoint wants to consume from that is defined in the spring context inputChannel=requestChannel No  
outputChannel The spring integration output channel name to send message to the spring integration context outputChannel=replyChannel No  
inOut The exchange pattern that spring integration endpoint should use inOut=true No inOnly for the spring integration consumer and outOnly for the spring integration provider

Usage

Spring Integration component is a bridge which connects Spring Integration endpoints through the Spring integration's input and output channels with the Camel endpoints. In this way, we can send out the Camel message to Spring Integration endpoints or receive the message from Spring Integration endpoint in Camel routing context.

Examples

Using the Spring Integration Endpoint

You could setup the Spring Integration Endpoint by using the URI

<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-2.5.xsd
			http://www.springframework.org/schema/integration
			http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
			http://activemq.apache.org/camel/schema/spring
			http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

	<message-bus auto-create-channels="true"/>

	<handler-endpoint input-channel="inputChannel"
	          output-channel="outputChannel"
	          handler="helloService"
	          method="sayHello"/>

	<beans:bean id="helloService" class="org.apache.camel.component.spring.integration.HelloWorldService"/>
    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
      <route>
        <from uri="direct:start"/>
        <!-- Using the &amp; as the separator of & -->
        <to uri="spring-integration:inputChannel?inOut=true&amp;inputChannel=outputChannel"/>
      </route>
    </camelContext>
<message-bus auto-create-channels="true"/>

   <channel id="requestChannel"/>
   <channel id="responseChannel"/>

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

   <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
     <route>
       <!-- Using the &amp; as the separator of & -->
       <from uri="spring-integration://requestChannel?outputChannel=responseChannel&amp;inOut=true"/>
       <process ref="myProcessor"/>
     </route>
   </camelContext>

or by the 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-2.5.xsd
			http://www.springframework.org/schema/integration
			http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
			http://activemq.apache.org/camel/schema/spring
			http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
	<message-bus auto-create-channels="true"/>

    <channel id="outputChannel"/>

    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
      <route>
        <!-- camel will create a spring integration endpoint automatically -->
        <from uri="outputChannel"/>
        <to uri="mock:result"/>
      </route>
    </camelContext>

The Source and Target adapter

Spring Integartion also provides the Spring Integration's Source and Target adapters which could route the message from the Spring Integration channel to a camel context endpoint or from a camel context endpoint to a Spring Integration Channel.

Here is the name spaces header

<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://activemq.apache.org/camel/schema/spring/integration"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/integration
	   http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
       http://activemq.apache.org/camel/schema/spring/integration
       http://activemq.apache.org/camel/schema/spring/integration/camel-spring-integration.xsd
       http://activemq.apache.org/camel/schema/spring
       http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
    ">

Now you could bind your source or target to camel context endpoint

<!-- Create the camel context here -->
<camelContext id="camelTargetContext" xmlns="http://activemq.apache.org/camel/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" requestChannel="channelA" expectReply="false">
    <camel-si:camelContextRef>camelTargetContext</camel-si:camelContextRef>
</camel-si:camelTarget>

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

<beans:bean id="myProcessor" class="org.apache.camel.component.spring.integration.MyProcessor"/>
<camelContext id="camelSourceContext" xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
        <from uri="direct:EndpointA"/>
        <to uri="direct:EndpointB" />
    </route>
    <route>
    	   <from uri="direct:EndpointA"/>
        <to uri="direct:EndpointC" />
    </route>
</camelContext>

<!-- camelSource will redirect the message coming for direct:EndpointB to the spring requestChannel channelA -->

<camel-si:camelSource id="camelSourceA" camelEndpointUri="direct:EndpointB" requestChannel="channelA" expectReply="false">
    <camel-si:camelContextRef>camelSourceContext</camel-si:camelContextRef>
</camel-si:camelSource>

<!-- camelSource will redirect the message coming for direct:EndpointC to the spring requestChannel channelB
 then it will pull the response from channelC and put the response message back to direct:EndpointC -->

<camel-si:camelSource id="camelSourceB" camelEndpointUri="direct:EndpointC" requestChannel="channelB" replyChannel="channelC" expectReply="true">
    <camel-si:camelContextRef>camelSourceContext</camel-si:camelContextRef>
</camel-si:camelSource>

See Also