2012-05-24 113 views
0

我一直在嘗試爲活動MQ編寫消費者客戶端。但我一直無法使用消息。即使我設置了錯誤的用戶名和密碼,但我仍然沒有發現任何異常。可有人請檢查我的配置:無法使用來自activeMQ的消息

<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()); 

} 

謝謝你:)

回答

0

嘗試內org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter包裹你的jmsFactory這樣

<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> 

並使用userCredentialsConnectionFac tory取代jmsFactory

+0

嗨Coder,我試過了,但它不起作用。 :( – user381878