0

我编写了一个小测试,将消息发送到现有的 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>
4

1 回答 1

0

原来 ActiveMQ 不支持通道。所以我必须定义一个<jms:lintener-container>并且<jms:listener>能够使用这些消息。此外,我创建了一个消息生产者,将消息发送到现有的 ActiveMQ 队列。

    <!-- RECEIVER -->
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="${jms.primary.server}"/>

<bean id="messageListener" class="com.ucware.ucpo.forward.jms.ProductMessageListener"/>

<jms:listener-container connection-factory="connectionFactory" concurrency="2" acknowledge="auto">
    <jms:listener destination="FORWARD" ref="messageListener" method="onMessage"/>
</jms:listener-container>

 <!-- SENDER -->

<!-- A cached connection to wrap the ActiveMQ connection --> 

<bean id="cachedConnectionFactory" 
     class="org.springframework.jms.connection.CachingConnectionFactory" 
     p:targetConnectionFactory-ref="connectionFactory"      
     p:sessionCacheSize="10" />

<!-- A destination in ActiveMQ --> 

<bean id="destination" 
    class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="FORWARD" />
</bean>

<!-- A JmsTemplate instance that uses the cached connection and destination --> 

<bean id="producerTemplate" 
    class="org.springframework.jms.core.JmsTemplate" 
    p:connectionFactory-ref="cachedConnectionFactory"
    p:defaultDestination-ref="destination" />
</beans>
于 2013-07-12T11:09:41.733 回答