简体   繁体   中英

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

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.

在此输入图像描述

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM