I am working with ActiveMQ and JMS
I have created a ObjectMessage in queue. I am not able to recieve it.
Take a look at message already available at Queue.
My code for Receiving message is
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();
}
}
}
If any more clarity or code is required, Please ask for it.
您正在使用此代码使用(并丢弃)消息...
messageConsumer.receive();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.