0

我一直在尝试为活动 MQ 编写消费者客户端。但我一直无法消费消息。即使我设置了错误的用户名和密码,我仍然没有得到任何异常。有人可以检查我的配置:

    <beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL">
            <value>nio://localhost:61616</value> 
        </property>
        <property name="userName"><value>saffsd</value></property>
        <property name="password"><value>asdfa</value></property>
    </bean>
<bean id="pooledJmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
    <property name="connectionFactory">
        <ref local="jmsFactory"/>
    </property>
</bean>



<bean id="LV_TOPIC" class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
    <constructor-arg value="TOPIC.LV_REPORTING" />
  </bean>





 <bean id="LV_QUEUE" class="org.apache.activemq.command.ActiveMQQueue" autowire="constructor">
    <constructor-arg value="QUEUE.LV_REPORTING" />
  </bean> 





<bean id="portfolioListener" class="com.oneinterface.enterprise.tradinggateway.listeners.Listener">
  </bean>



<bean id="javaConsumer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="pooledJmsFactory"/>
    <property name="destination" ref="LV_TOPIC" />
    <property name="messageListener" ref="portfolioListener" />
  </bean>




<bean id="ionaConsumer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="pooledJmsFactory"/>
    <property name="destination" ref="LV_QUEUE" />
    <property name="messageListener" ref="portfolioListener" />
  </bean>



</beans>

我的Java代码是:

public static void main(String[] args) {
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("config/LVConsumer.xml");
    DefaultMessageListenerContainer defaultListen = (DefaultMessageListenerContainer) context.getBean("javaConsumer");
    defaultListen.start();
    System.err.println("Consuming message from Topic >>" + defaultListen.getDestination().toString());

    DefaultMessageListenerContainer queueListen = (DefaultMessageListenerContainer) context.getBean("ionaConsumer");
    queueListen.start();
    System.err.println("Consuming message from Queue >>" + queueListen.getDestination().toString());

}

谢谢 :)

4

1 回答 1

0

尝试像这样将 jmsFactory 包装在 org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter 中

<bean id="userCredentialsConnectionFactory"
        class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
        <property name="targetConnectionFactory">
            <ref bean="jmsFactory" />
        </property>
        <property name="username">
            <value>user</value>
        </property>
        <property name="password">
            <value>password</value>
        </property>
    </bean>

并使用 userCredentialsConnectionFactory 代替 jmsFactory

于 2012-05-24T09:03:44.313 回答