Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push message from Activemq

i am new to activemq. i read some article and doing this.please help me to solve the following task. i produce one message to activemq from my java application and i have a consumer for that message in another java application.so i will get the message from activemq. every time this consumer(listener) looking for the message in activemq. my question is activemq can push the message to consumer(listener).

activemq only for storing the message ? it will do any push or pull operation ? activemq always need producer(produce the message) and consumer(consume the message) ?

can anyone help me

thanks

like image 557
nichu09 Avatar asked Oct 25 '13 11:10

nichu09


1 Answers

ActiveMq, WebLogic, IBM MQ, and any JMS compatible provider are destination-based messaging systems; the destination, or subject, is a queue or topic. When sending a message, producer can send the message and disconnect immediately; ActiveMq will store message on queue. When receiving, message consumer can receive sync or async, independent of sender.

enter image description here

Send Message

Message producer sends message to destination; it's job is done.

QueueSender queueSender = queueSession.createSender(myQueue);
queueSender.send(message);

Receive Message

Message consumer can receive message one of two ways:
Synchrounous, here you call receive() explicitly

QueueReceiver queueReceiver = queueSession.createReceiver(myQueue);
queueConnection.start();
Message m = queueReceiver.receive();

Asynchronous, here you implement callback method from MessageListener interface:

class MyQueueReceiver implements javax.jms.MessageListener {

    QueueReceiver queueReceiver = queueSession.createReceiver(myQueue);
    queueReceiver.setMessageListener(this);
    ...
    public void onMessage(Message msg){
      //consume message here
    }
}
like image 153
raffian Avatar answered Oct 21 '22 22:10

raffian