7
votes

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

1
Need code, better explanation of the problem and the use case etc. - Tim Bish
@TimBish my question is activemq able to push the message to any consumer ? . there should be one consumer for consume the message .if i am wrong please correct me. - nichu09

1 Answers

16
votes

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
    }
}