2016-03-21 6 views
1

https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/tcp-client-server-multiplex この例を見ました。だから、私はアーキテクチャが変更されました。ゲートウェイにメッセージを配信する方法を転送しますか?

  • センドモデル enter image description here
  • は、モデル enter image description here を受けて、私は疑問を持っています。 私はsendモデルでtransferの役割を理解していません。 転送するアグリゲータ配信メッセージを理解しています。 しかし、私はゲートウェイにメッセージを配信する方法を理解していません。 お届け方法?

これは私の春の統合設定です。

それは私がgw.send(MSG)を呼び出すと、それを、

<!-- telegram bean --> 
    <bean id="byteArrayRawSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer"> 
    <property name="maxMessageSize" value="2000"/> 
    </bean> 
    <bean id="myCorrelationStrategy" class="com.test.util.MyCorrelationStrategy"/> 
    <!-- online connection factory --> 
    <int-ip:tcp-connection-factory id="server" type="server" port="20001" single-use="false" lookup-host="false" so-timeout="60000" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 
    <int-ip:tcp-connection-factory id="client" type="client" host="localhost" port="10001" single-use="false" so-timeout="60000" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 

    <!-- Send --> 
    <int:gateway id="sendGateway" 
     service-interface="com.test.MySendGateway" 
     default-reply-timeout="20000" 
     default-request-channel="sendChannel"/> 

    <int:publish-subscribe-channel id="sendChannel" /> 

    <int-ip:tcp-outbound-channel-adapter id="sendAdapter" order="2" channel="sendChannel" connection-factory="client" /> 

    <int:bridge input-channel="batchSendChannel" output-channel="toSendAggregator" order="1"/> 

    <int:channel id="toSendAggregator" datatype="byte[]"/> 

    <int:aggregator input-channel="toSendAggregator" 
     output-channel="toSendTransformer" 
     expire-groups-upon-completion="true" 
     correlation-strategy="myCorrelationStrategy" 
     correlation-strategy-method="getCorrelationKey" 
     release-strategy-expression="size() == 2" /> 

    <int:transformer input-channel="toSendTransformer" expression="payload.get(1)"/> 

    <int-ip:tcp-inbound-channel-adapter id="sendReplyAdapter" channel="toSendAggregator" connection-factory="client" /> 

    <!-- Receive --> 
    <int-ip:tcp-inbound-channel-adapter id="inboundAdapter" channel="batchInboundChannel" connection-factory="batchReceiveServer" /> 
    <int-ip:tcp-outbound-channel-adapter id="outboundAdapter" channel="batchOutboundChannel" connection-factory="batchReceiveServer"/> 

    <int:channel id="batchInboundChannel" /> 

    <int:channel id="batchOutboundChannel"/> 

    <int:service-activator id="myReceiveServiceActivator" method="receive" input-channel="batchInboundChannel"> 
    <bean class="com.test.endpoint.MyReceiveServiceActivator" /> 
    </int:service-activator> 

をアプリの設定を送信し、それは配達のアプリの設定(画面中央)で、

<!-- Bean load --> 
    <bean id="byteArrayRawSerializer" class="org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer"> 
    <property name="maxMessageSize" value="2000"/> 
    </bean> 

    <!-- Connection factory --> 
    <int-ip:tcp-connection-factory id="server" type="server" port="30001" using-nio="true" single-use="false" lookup-host="false" so-timeout="10000" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 
    <int-ip:tcp-connection-factory id="client" type="client" host="${RemoteTarget.ip}" port="${RemoteTarget.port}" using-nio="true" single-use="false" so-timeout="10000" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 

    <!-- Connection factory --> 
    <int-ip:tcp-connection-factory id="inboundServer" type="server" port="10001" using-nio="true" single-use="false" lookup-host="false" so-timeout="${server.outbound.connectionTimeout}" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 
    <int-ip:tcp-connection-factory id="inboardClient" type="client" host="localhost" port="20001" using-nio="true" single-use="false" so-timeout="10000" serializer="byteArrayRawSerializer" deserializer="byteArrayRawSerializer" /> 

    <int-ip:tcp-inbound-channel-adapter id="receiveAdapter" channel="receiveChannel" connection-factory="server" auto-startup="true"/> 
    <int-ip:tcp-inbound-channel-adapter id="sendReplyAdapter" channel="sendReplyChannel" connection-factory="client" auto-startup="true"/> 

    <int:channel id="receiveChannel"/> 
    <int:channel id="sendReplyChannel"/> 

    <int-ip:tcp-outbound-channel-adapter id="receiveAdapter.inboard" channel="receiveChannel" connection-factory="inboundServer" /> 
    <int-ip:tcp-outbound-channel-adapter id="sendReplyAdapter.inboard" channel="sendReplyChannel" connection-factory="inboardClient" /> 

    <int-ip:tcp-outbound-channel-adapter id="sendAdapter" channel="sendChannel" connection-factory="client" /> 
    <int-ip:tcp-outbound-channel-adapter id="receiveReplyAdapter" channel="receiveReplyChannel" connection-factory="server" /> 

    <int:channel id="sendChannel" /> 

    <int:channel id="receiveReplyChannel"/> 

    <int:router id="outRouter" input-channel="toRouter" method="route" auto-startup="true"> 
     <bean class="com.test.endpoint.MyRouter"/> 
    </int:router> 

    <int:channel id="toRouter"/> 

    <int-ip:tcp-inbound-channel-adapter id="sendAdapter.inboard" channel="toRouter" connection-factory="inboundServer" auto-startup="true"/> 
    <int-ip:tcp-inbound-channel-adapter id="receiveReplyAdapter.inboard" channel="toRouter" connection-factory="inboardClient" auto-startup="true"/> 

しかしあります (正確には、タイムアウトとルータがこのメッセージを受け取るまでに、配送機の 'sendAdapter.inboard'でメッセージが止まります...)

答えて

1

わからないtransferあなたのar3アーキテクチャも。

あなたが表示されたサンプルをよると、私たちは持っている:

gatewayだけのため <publish-subscribe-channel id="input" />の、TCPアウトバウンド・チャネル・アダプターとアグリゲータの両方にその要求を送信
gateway -> outbound-channel-adapter 
     |-> aggregator 

inbound-channel-adapter->aggregator->transformer 

私たちが知っているように、gatewayは要求/応答コンポーネントです。それが要求を送信するとき、それはなぜなら契約、応答を待つ:

public interface SimpleGateway { 

    String send(String text); 

} 

この場合、ゲートウェイで応答を待機するreplyChannelヘッダとしてTemporaryReplyChannelを加えます。

最後のダウンストリームフローコンシューマにoutput-channelが指定されていない場合に応答が生成されます。

<transformer input-channel="toTransformer.client" 
    expression="payload.get(1)"/> <!-- The response is always second --> 

私はそれはあなたが探しているもののトリックだと思う:

は、私たちのケースでは、<transformer><aggregator>後に正確です。コンシューマロジックではreplyChannelヘッダーと呼ばれます。

+0

ありがとうございます。私はこのようにしています。しかし、それは仕事ではありません。 –

+1

あなたのアーキテクチャは分かりませんが、その 'multiplex'サンプルに従うなら、' tcp:outbound-channel-adapter'と同じ 'publish-subscribe-channel'を使う必要があります。 'aggregator'です。しかし、最後のコードのコードによれば、完全に異なるチャンネル、 'batchSendChannel'を使用します。コードに注意してください。私はあなたのために仕事をするべきかどうかはわかりません... –

+0

申し訳ありません。バッチセンドチャンネルは単にタイプミスです。正確な設定に変更します。 –

関連する問題