1
简单的基于消息的RPC很容易创建。服务器端导出服务,客户端使用代理。基于消息的RPC与主题
什么是最好的方法,使多个repliers同样的事情?
我想发送来自客户端的请求。然后客户端等待收到所有(可能超时)回复。
简单的基于消息的RPC很容易创建。服务器端导出服务,客户端使用代理。基于消息的RPC与主题
什么是最好的方法,使多个repliers同样的事情?
我想发送来自客户端的请求。然后客户端等待收到所有(可能超时)回复。
您可以使用aggregator以及适当的关联和释放策略(以及组超时)。
编辑:
下面是一个使用JMS主题版本...
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
</bean>
<bean id="requestTopic" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="topic.demo"/>
</bean>
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.reply"/>
</bean>
<int-stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<int:channel id="stdinToJmsoutChannel"/>
<int:chain input-channel="stdinToJmsoutChannel">
<int:header-enricher>
<int:header name="jms_replyTo" ref="replyQueue" />
</int:header-enricher>
<int-jms:outbound-channel-adapter destination="requestTopic" />
</int:chain>
<int-jms:message-driven-channel-adapter channel="jmsReplyChannel"
destination="replyQueue"/>
<int:channel id="jmsReplyChannel" />
<int:chain input-channel="jmsReplyChannel">
<int:aggregator group-timeout="5000" expire-groups-upon-timeout="false"
send-partial-result-on-expiry="true"
discard-channel="logLateArrivers"
correlation-strategy-expression="headers['jms_correlationId']"
release-strategy-expression="size() == 2"/>
<int-stream:stdout-channel-adapter append-newline="true"/>
</int:chain>
<int:logging-channel-adapter id="logLateArrivers" />
<!-- Subscribers -->
<int-jms:inbound-gateway request-channel="upcase" request-destination="requestTopic" />
<int-jms:inbound-gateway request-channel="upcase" request-destination="requestTopic" />
<int:transformer input-channel="upcase" expression="payload.toUpperCase()" />
请求类型到控制台:
Please type something and hit <enter>
foo
[FOO, FOO]
bar
[BAR, BAR]
baz
[BAZ, BAZ]
嘿加里,感谢您的回答。我会尝试,但你能给我一个小例子吗?我从来没有使用聚合器:) – Smoothi
非常感谢。我会在下周尝试一下,并告诉你这个解决方案是否能解决我的问题。 :) – Smoothi