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