我正在使用ActiveMQ和JMS
我在队列中创建了一个ObjectMessage。我无法收到它。
我的接收消息代码是
public class RecieveObjectQueue {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
try {
ConnectionFactory connFactory=(ConnectionFactory) ctx.getBean("connectionFactory");
Connection connection=connFactory.createConnection();
connection.start();
Session session=connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = new ActiveMQQueue(SendObjectQueue.OBJECT_QUEUE);
MessageConsumer messageConsumer=session.createConsumer(queue);
// messageConsumer.receive();
messageConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
ActiveMQObjectMessage activeMsg=(ActiveMQObjectMessage) message;
/*if(message instanceof Car){
Car car=(Car) message;
System.out.println("Recieved Car=>"+car);
}else{
System.out.println("Message is not a car object!!!");
}*/
}
});
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
如果需要更多清晰度或代码,请提出要求。
答案 0 :(得分:0)
您正在使用此代码消费(并丢弃)消息...
messageConsumer.receive();