Producer:
1) Create a connection toAMQ
ActiveMQConnectionFactoryconnectionFactory =newActiveMQConnectionFactory(user,password,url);
connection =connectionFactory.createConnection();
2)Start the connection
connection.start();
3)Connection Create a session
Session session= connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
4)Session Createa topic
destination= session.createTopic("TOOL.DEFAULT");
5)Session createa producer
MessageProducerproducer = session.createProducer(destination);
6)Session createa message
TextMessagemessage = session.createTextMessage("111111111111111111");
7) Producer sendthe message
producer.send(message);
Consumer
1)Create a connection to AMQ
ActiveMQConnectionFactoryconnectionFactory =newActiveMQConnectionFactory(user,password,url);
Connectionconnection = connectionFactory.createConnection();
2)Start theconnection
connection.start();
3)ConnectionCreate a session
session= connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
4)SessionCreate a topic
destination=session.createTopic("TOOL.DEFAULT");
MessageConsumerconsumer =null;
5)Sessioncreate a consumer
MessageConsumerconsumer =session.createConsumer(destination);
6)Consumerlisten the message
consumer.setMessageListener(newMessageListener(){
publicvoidonMessage(Message message) {}
}