第160章 SpringIntegration
Spring Integration コンポーネント リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
spring-integration: コンポーネントは、Apache Camel コンポーネントが Spring インテグレーションエンドポイント と通信するためのブリッジを提供します。
URI 形式 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
spring-integration:defaultChannelName[?options]
defaultChannelName は、Spring Integration Spring コンテキストによって使用されるデフォルトのチャネル名を表します。Spring Integration コンシューマーの
inputChannel 名と Spring Integration プロバイダーの outputChannel 名と同じになります。
URI にクエリーオプションは
?option=value&option=value&.. の形式で追加できます。
オプション リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
| 名前 | 説明 | 例 | 必須 | デフォルト値 |
|---|---|---|---|---|
inputChannel
|
指定されたチャネル名が Spring コンテキストで定義される、このエンドポイントが使用する Spring インテグレーション入力チャネル名。 |
inputChannel=requestChannel
|
いいえ | |
outputChannel
|
メッセージを Spring インテグレーションコンテキストに送信するために使用される Spring インテグレーション出力チャネル名。 |
outputChannel=replyChannel
|
いいえ | |
inOut
|
Spring インテグレーションエンドポイントが使用する必要のある交換パターン。 |
inOut=true
|
いいえ |
Spring インテグレーションコンシューマーの場合は InOnly および Spring インテグレーションプロバイダーの outOnly
|
consumer.delay
|
各ポーリングの遅延(ミリ秒単位)。 |
consumer.delay=60000
|
いいえ |
500
|
consumer.initialDelay
|
ポーリングが開始するまでの時間(ミリ秒単位)。 |
consumer.initialDelay=10000
|
いいえ |
1000
|
consumer.userFixedDelay
|
true を指定してポーリング間の固定遅延を使用します。使用しない場合は固定レートが使用されます。詳細は、ScheduledExecutorService クラスを参照してください。
|
consumer.userFixedDelay=false
|
いいえ |
false
|
使用方法 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Spring インテグレーションコンポーネントは、Spring インテグレーションの入力チャネルおよび出力チャネルを介して Apache Camel エンドポイントを Spring インテグレーションエンドポイントに接続するブリッジです。このコンポーネントを使用すると、Camel メッセージを Spring Integration エンドポイントに送信したり、Camel ルーティングコンテキストの Spring インテグレーションエンドポイントからメッセージを受信したりできます。
Spring インテグレーションエンドポイントの使用 リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
以下のように、URI を使用して Spring インテグレーションエンドポイントを設定できます。
<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">
<channel id="inputChannel"/>
<channel id="outputChannel"/>
<channel id="onewayChannel"/>
<service-activator input-channel="inputChannel"
ref="helloService"
method="sayHello"/>
<service-activator input-channel="onewayChannel"
ref="helloService"
method="greet"/>
<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"/>
<!-- Using the &as the separator of & -->
<to uri="spring-integration:inputChannel?inOut=true&nputChannel=outputChannel"/>
</route>
<route>
<from uri="direct:onewayMessage"/>
<to uri="spring-integration:onewayChannel?inOut=false"/>
</route>
</camelContext>
<channel id="requestChannel"/>
<channel id="responseChannel"/>
<beans:bean id="myProcessor" class="org.apache.camel.component.spring.integration.MyProcessor"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- Using the &as the separator of & -->
<from uri="spring-integration://requestChannel?outputChannel=responseChannel&nOut=true"/>
<process ref="myProcessor"/>
</route>
</camelContext>
または、Spring インテグレーションチャネル名を直接使用 します。
<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">
<channel id="outputChannel"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<!-- camel will create a spring integration endpoint automatically -->
<from uri="outputChannel"/>
<to uri="mock:result"/>
</route>
</camelContext>
Source アダプターおよび Target アダプター リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Spring インテグレーションは、Spring インテグレーションのソースおよびターゲットアダプターも提供します。これは、Spring インテグレーションチャネルから Apache Camel エンドポイント、または Apache Camel エンドポイントから Spring インテグレーションチャネルにメッセージをルーティングできます。
この例では、以下の namespace を使用します。
<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
">
以下のように、ソースまたはターゲットを Apache Camel エンドポイントにバインドできます。
<!-- 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"/>
<!-- spring integration channels -->
<channel id="channelA"/>
<channel id="channelB"/>
<channel id="channelC"/>
<!-- spring integration service activator -->
<service-activator input-channel="channelB" output-channel="channelC" ref="helloService" method="sayHello"/>
<!-- custom bean -->
<beans:bean id="helloService" class="org.apache.camel.component.spring.integration.HelloWorldService"/>
<camelContext id="camelSourceContext" xmlns="http://camel.apache.org/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>