|
Page Edited :
CAMEL :
SpringIntegration
SpringIntegration has been edited by willem jiang (Jul 16, 2008). Change summary: Added consumer. Unknown macro: {delay|initialDelay|userFixedDelay} optionsSpring Integration ComponentThe spring-integration: component provides a bridge for Camel components to talk to spring integration endpoints URI formatspring-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.
UsageSpring 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. ExamplesUsing the Spring Integration EndpointYou 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" ref="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 & as the separator of & --> <to uri="spring-integration:inputChannel?inOut=true&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 & as the separator of & --> <from uri="spring-integration://requestChannel?outputChannel=responseChannel&inOut=true&consumer.delay=5000"/> <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 adapterSpring 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:OneWay"/> <to uri="direct:EndpointB" /> </route> <route> <from uri="direct:TwoWay"/> <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 |
Unsubscribe or edit your notifications preferences
