我为Amazon MQ
创建了一个简单的使用者,但看起来我错过了一些东西,因为每当收到一条消息时,它都应该调用我的recevieMessage方法,但它不起作用。
但是我用apache active MQ尝试了这一点,它工作正常。
PS:我也尝试实现MessageListener
类来覆盖onMessage()
方法,但是不起作用。
我尝试使用receiveMessage
方法中的不同参数,例如Object
,Message
,ByteMessage
....
public class Receiver {
@JmsListener(destination = "Queue_Name")
public void receiveMessage(final Message consumerMessage) throws JMSException {
--some logic on data
}
}
我的配置:
@Configuration
@EnableJms//enable jms
public class ReceiverConfig {
@Bean//created a ActiveMQ Connection Factory
public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory =
new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(brokerUrl);
activeMQConnectionFactory.setUserName(userName);
activeMQConnectionFactory.setPassword(passWord);
return activeMQConnectionFactory;
}
@Bean// Uses default Jms Listener Container Factory
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
factory
.setConnectionFactory(receiverActiveMQConnectionFactory());
return factory;
}
@Bean
public Receiver receiver() {
return new Receiver();
}
}
每次我启动应用程序时都要对此进行设置:
WARN 12740 --- [206:61616@63304] o.a.activemq.ActiveMQSessionExecutor : Received a message on a connection which is not yet started. Have you forgotten to call Connection.start()? Connection: ActiveMQConnection
答案 0 :(得分:0)
我想在@jmsListner
注释中提及我的用户定义的jms lisner连接工厂名称。
@JmsListener(destination = "Queue-name",containerFactory ="jmsListenerContainerFactory" )
public void receiveMessage(@Payload final Message consumerMessage) throws JMSException {
LOGGER.info("Into receiveMessage Method");
}
但是我仍然找不到其他activeMQ的工作方式。