https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/tcp-client-server-multiplex 我看到了這個例子。所以,我改變了建築。轉移如何將消息傳遞給網關?
這是我的彈簧集成配置。
它是將應用程式設定,
<!-- 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"/>
但是,當我打電話gw.send(MSG),它是不行的,在送機的「sendAdapter.inboard」 (準確地說,消息停止,直到超時和路由器得到這個消息....
謝謝。我嘗試這種方式。但是,這是行不通的。 –
我不知道你的體系結構,但是如果你遵循'multiplex'示例,你真的必須使用與'tcp:outbound-channel-adapter'相同的'publish-subscribe-channel',以及'aggregator'。但根據你的最後一個代碼,你使用完全不同的通道 - 「batchSendChannel」。請小心代碼,我不知道我們應該爲你做這件事... –
對不起。batchSendChannel只是輸入錯誤。我將改爲確切的配置。 –