camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > SpringIntegration
Date Mon, 29 Mar 2010 01:31:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/SpringIntegration">SpringIntegration</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~njiang">willem
jiang</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="SpringIntegration-SpringIntegrationComponent"></a>Spring
Integration Component</h2>

<p>The <b>spring-integration:</b> component provides a bridge for Camel
components to talk to <a href="http://camel.apache.org/springintegration.html" rel="nofollow">spring
integration endpoints</a>.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-spring-integration&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="SpringIntegration-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
spring-integration:defaultChannelName[?options]
</pre>
</div></div>
<p>Where <b>defaultChannelName</b> represents the default channel name which
is used by the Spring Integration Spring context. It will equal to the <tt>inputChannel</tt>
name for the Spring Integration consumer and the <tt>outputChannel</tt> name for
the Spring Integration provider.</p>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="SpringIntegration-Options"></a>Options</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Example </th>
<th class='confluenceTh'> Required </th>
<th class='confluenceTh'> Default Value </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>inputChannel</tt> </td>
<td class='confluenceTd'> The Spring integration input channel name that this endpoint
wants to consume from, where the specified channel name is defined in the Spring context.
</td>
<td class='confluenceTd'> <tt>inputChannel=requestChannel</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>outputChannel</tt> </td>
<td class='confluenceTd'> The Spring integration output channel name that is used to
send messages to the Spring integration context. </td>
<td class='confluenceTd'> <tt>outputChannel=replyChannel</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inOut</tt> </td>
<td class='confluenceTd'> The exchange pattern that the Spring integration endpoint
should use. </td>
<td class='confluenceTd'> <tt>inOut=true</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>inOnly</tt> for the Spring integration consumer
and <tt>outOnly</tt> for the Spring integration provider </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> Delay in milliseconds between each poll. </td>
<td class='confluenceTd'> <tt>consumer.delay=60000</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>500</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> Milliseconds before polling starts. </td>
<td class='confluenceTd'> <tt>consumer.initialDelay=10000</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.userFixedDelay</tt> </td>
<td class='confluenceTd'> Specify <tt>true</tt> to use fixed delay between
polls, otherwise fixed rate is used. See the Java<a href="http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/lang/Character.html"
rel="nofollow">ScheduledExecutorService</a> class for details. </td>
<td class='confluenceTd'> <tt>consumer.userFixedDelay=false</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> <tt>false</tt> </td>
</tr>
</tbody></table>

<h3><a name="SpringIntegration-Usage"></a>Usage</h3>

<p>The Spring integration component is a bridge that connects Camel endpoints with Spring
integration endpoints through the Spring integration's input channels and output channels.
Using this component, we can send Camel messages to Spring Integration endpoints or receive
messages from Spring integration endpoints in a Camel routing context.</p>

<h3><a name="SpringIntegration-Examples"></a>Examples</h3>

<h4><a name="SpringIntegration-UsingtheSpringintegrationendpoint"></a>Using
the Spring integration endpoint</h4>
<p>You can set up a Spring integration endpoint using a URI, as follows: </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
	<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
	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://camel.apache.org/schema/spring
			http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
	
	<span class="code-tag">&lt;channel id=<span class="code-quote">"inputChannel"</span>/&gt;</span>
   	<span class="code-tag">&lt;channel id=<span class="code-quote">"outputChannel"</span>/&gt;</span>
   	<span class="code-tag">&lt;channel id=<span class="code-quote">"onewayChannel"</span>/&gt;</span>

	&lt;service-activator input-channel=<span class="code-quote">"inputChannel"</span>
          
	          ref=<span class="code-quote">"helloService"</span>
	          method=<span class="code-quote">"sayHello"</span>/&gt;
	          	      
	&lt;service-activator input-channel=<span class="code-quote">"onewayChannel"</span>
          
	          ref=<span class="code-quote">"helloService"</span>
	          method=<span class="code-quote">"greet"</span>/&gt;
	          
	<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"helloService"</span>
class=<span class="code-quote">"org.apache.camel.component.spring.integration.HelloWorldService"</span>/&gt;</span>
    
    <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:twowayMessage"</span>/&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- Using the
&amp;amp; as the separator of &amp; --&gt;</span></span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"spring-integration:inputChannel?inOut=true&amp;amp;inputChannel=outputChannel"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>      
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:onewayMessage"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"spring-integration:onewayChannel?inOut=false"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;channel id=<span class="code-quote">"requestChannel"</span>/&gt;</span>
<span class="code-tag">&lt;channel id=<span class="code-quote">"responseChannel"</span>/&gt;</span>

<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"myProcessor"</span>
class=<span class="code-quote">"org.apache.camel.component.spring.integration.MyProcessor"</span>/&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- Using the &amp;amp;
as the separator of &amp; --&gt;</span></span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"spring-integration://requestChannel?outputChannel=responseChannel&amp;amp;inOut=true"</span>/&gt;</span>
    <span class="code-tag">&lt;process ref=<span class="code-quote">"myProcessor"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>Or directly using a Spring integration channel name:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
	<span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
	<span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
	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://camel.apache.org/schema/spring
			http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
	<span class="code-tag">&lt;channel id=<span class="code-quote">"outputChannel"</span>/&gt;</span>

    <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
      <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- camel will
create a spring integration endpoint automatically --&gt;</span></span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"outputChannel"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h4><a name="SpringIntegration-TheSourceandTargetadapter"></a>The Source
and Target adapter</h4>

<p>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.</p>

<p>This example uses the following namespaces:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans:beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/integration"</span>
       <span class="code-keyword">xmlns:beans</span>=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel-si</span>=<span class="code-quote">"http://camel.apache.org/schema/spring/integration"</span>
       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://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
    "&gt;
</pre>
</div></div>

<p>You can bind your source or target to a Camel endpoint as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!--
Create the camel context here --&gt;</span></span>
<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camelTargetContext"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:EndpointA"</span>
/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>
/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:EndpointC"</span>/&gt;</span>
        <span class="code-tag">&lt;process ref=<span class="code-quote">"myProcessor"</span>/&gt;</span>
      <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- We can bind the
camelTarget to the camel context's endpoint by specifying the camelEndpointUri attribute --&gt;</span></span>
<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetA"</span>
camelEndpointUri=<span class="code-quote">"direct:EndpointA"</span> expectReply=<span
class="code-quote">"false"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span
class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetB"</span>
camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> replyChannel=<span
class="code-quote">"channelC"</span> expectReply=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span
class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;camel-si:camelTarget id=<span class="code-quote">"camelTargetD"</span>
camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> expectReply=<span
class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelTargetContext<span
class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelTarget&gt;</span>

<span class="code-tag">&lt;beans:bean id=<span class="code-quote">"myProcessor"</span>
class=<span class="code-quote">"org.apache.camel.component.spring.integration.MyProcessor"</span>/&gt;</span>
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camelSourceContext"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:OneWay"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:EndpointB"</span>
/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
    	   <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:TwoWay"</span>/&gt;</span>
        <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:EndpointC"</span>
/&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- camelSource will
redirect the message coming for direct:EndpointB to the spring requestChannel channelA --&gt;</span></span>

<span class="code-tag">&lt;camel-si:camelSource id=<span class="code-quote">"camelSourceA"</span>
camelEndpointUri=<span class="code-quote">"direct:EndpointB"</span> requestChannel=<span
class="code-quote">"channelA"</span> expectReply=<span class="code-quote">"false"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelSourceContext<span
class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelSource&gt;</span>

&lt;!-- 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
--&gt;

<span class="code-tag">&lt;camel-si:camelSource id=<span class="code-quote">"camelSourceB"</span>
camelEndpointUri=<span class="code-quote">"direct:EndpointC"</span> requestChannel=<span
class="code-quote">"channelB"</span> replyChannel=<span class="code-quote">"channelC"</span>
expectReply=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;camel-si:camelContextRef&gt;</span>camelSourceContext<span
class="code-tag">&lt;/camel-si:camelContextRef&gt;</span>
<span class="code-tag">&lt;/camel-si:camelSource&gt;</span>
</pre>
</div></div>


<h3><a name="SpringIntegration-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/SpringIntegration">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=86379&revisedVersion=7&originalVersion=6">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/SpringIntegration?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message