也许这是一个愚蠢的问题,我错过了一些非常简单的东西,但我真的被卡住了。我正在使用 ActiveMQ 5.5.1 和 SI 2.1.4
我的配置片段:
- -服务器 - -
<beans:bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<beans:property name="brokerURL" value="tcp://localhost:61616" />
</beans:bean>
<beans:bean id="listQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg name="name" value="LIST_QUEUE"/>
</beans:bean>
<beans:bean id="replyListQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg name="name" value="REPLY_LIST_QUEUE"/>
</beans:bean>
<channel id="replyListChannel"/>
<channel id="listIn" />
<channel id="listDriver"/>
<channel id="listStock"/>
<jms:inbound-channel-adapter id="listInJms"
connection-factory="connectionFactory"
destination="listQueue"
channel="listIn"
auto-startup="true">
<poller fixed-rate="3000"/>
</jms:inbound-channel-adapter>
<header-value-router input-channel="listIn" header-name="List"
default-output-channel="nullChannel">
<mapping value="Driver" channel="listDriver" />
<mapping value="Stock" channel="listStock" />
</header-value-router>
<jms:outbound-channel-adapter connection-factory="connectionFactory"
channel="replyListChannel"
destination="replyListQueue"
auto-startup="true">
</jms:outbound-channel-adapter>
- -客户 - -
<beans:bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<beans:property name="brokerURL" value="tcp://localhost:61616" />
</beans:bean>
<beans:bean id="requestListQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg value="LIST_QUEUE"/>
</beans:bean>
<beans:bean id="replyListQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg value="REPLY_LIST_QUEUE"/>
</beans:bean>
<channel id="requestListChannel">
<queue capacity="20"/>
</channel>
<channel id="listStockChannel">
<queue capacity="20"/>
</channel>
<channel id="listDriverChannel">
<queue capacity="20"/>
</channel>
<channel id="replyListChannel"/>
<jms:outbound-gateway id="outListGW"
connection-factory="connectionFactory"
request-destination="requestListQueue"
request-channel="requestListChannel"
reply-destination="replyListQueue"
reply-channel="replyListChannel"
reply-timeout="20000"
receive-timeout="20000">
<poller fixed-rate="5000" />
</jms:outbound-gateway>
<header-value-router input-channel="replyListChannel" header-name="List"
default-output-channel="nullChannel">
<mapping value="Driver" channel="listDriverChannel" />
<mapping value="Stock" channel="listStockChannel" />
</header-value-router>
然后在代码中的某个地方,我手动执行请求并收听回复通道:
public static DriverList requestDriverList() {
Message<String> ldrm = MessageBuilder.withPayload("DriverList request").
setHeader("List", "Driver").build();
try {
ApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath:dmclnt/config/integ-context.xml");
MessageChannel requestListChannel =
ctx.getBean("requestListChannel", MessageChannel.class);
QueueChannel listDriverChannel =
ctx.getBean("listDriverChannel", QueueChannel.class);
logger.info("Request for DriverList is sent to channel");
Message dlm = listDriverChannel.receive(20000);
String xmlDL = (String)dlm.getPayload();
JAXBContext jaxbctx = JAXBContext.newInstance(DriverList.class);
DriverList dl = (DriverList)jaxbctx.createUnmarshaller().
unmarshal(newStringReader(xmlDL));
logger.info("DriverList objct unmarshalled: "+dl.toString());
return dl;
} catch (JAXBException e) {
logger.error("Error converting xmlDriverList to DriverList object",e);
return null;
} catch (RuntimeException e){
logger.error(e);
return null;
}
}
但我收到
"MessageTimeoutException: failed to receive JMS response within timeout of: 20000ms"
每时每刻。当我查看服务器日志时,我看到带有正确有效负载的回复已成功从服务器发送到客户端,此外,回复被放入 REPLY_LIST_QUEUE,正如我在 ActiveMQ 管理控制台中看到的那样。没有更多的事情发生!REPLY_LIST_QUEUE With_Correct_Payload中的消息在此队列中处于 Pending 和 Enqueued 状态。没有消息出列。看来,JmsOutboundGateway 没有从回复目标队列中提取消息,尽管接收超时 =“20000 毫秒”延迟远远超过获得回复。我究竟做错了什么?