我编写了一个小测试,将消息发送到现有的 ActiveMQ FORWARD 队列。不幸的是,消息已发送到队列但未收到。下面您会发现我两次尝试接收此消息:通过 MyMessageListener 和通过 MessageService。两种方法都失败了。这是我的测试:
Map<Parameter, String> params = new HashMap<Parameter, String>();
params.put(key1, "601");
params.put(key2, "3000");
Map<String,String> headers = Collections.singletonMap("method-name","prepareHotDrink");
Message<?> msg = MessageBuilder.withPayload(params)
.copyHeaders(headers)
.build();
boolean i = inputChannel.send(msg);
这是我的配置文件:
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${jms.primary.server}"/>
</bean>
<!-- spring integration beans -->
<int-jms:channel id="inputChannel" queue-name="FORWARD"
connection-factory="connectionFactory" auto-startup="true">
</int-jms:channel>
<!-- Consumers -->
<int-jms:message-driven-channel-adapter
id="jmsIn"
container="messageListenerContainer"
channel="inputChannel"
extract-payload="true" />
<int:service-activator input-channel="inputChannel"
ref="messageService"
method="processMessage"/>
<bean id="messageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="destination" ref="requestQueue"/>
<property name="exposeListenerSession" value="false"/>
<property name="messageListener" ref="messageListener" />
</bean>
<bean id="messageListener" class="com.ucware.ucpo.forward.mess.MyMessageListener"/>
<bean id="messageService" class="com.ucware.ucpo.forward.jms.MessageService"/>
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg name="name" value="FORWARD"/>
</bean>