如何从不同会话中的临时队列中获取消息 [英] How to get the message from temporary Queue in Different session

查看:149
本文介绍了如何从不同会话中的临时队列中获取消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jms和activemq的新手。我在activemq中向一个静态队列生成一条消息,并使用getJMSReplyTo回复临时队列。代码如下:

i am new to jms and activemq. i produce one message to one static queue in activemq and get reply back to temporary queue using getJMSReplyTo. the code is following

ActiveMQConnectionFactory connectionFactory = new  ActiveMQConnectionFactory("tcp://localhost:61616");

    // Create a Connection
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // Create a Session
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);


    // Create the destination (Topic or Queue)
    Destination destination = (Destination)   session.createQueue("PostWithParameter_Queue");

    // Create a MessageConsumer from the Session to the Topic or Queue
    MessageConsumer consumer = session.createConsumer(destination);
    //consumer.setMessageListener(new StaticQueueListener());
    // Wait for a message
    Message message = (Message) consumer.receive();
    MessageConsumer consumer1 = session.createConsumer(message.getJMSReplyTo());
    consumer1.setMessageListener(new ReplyHandler()); 
    consumer.close();
    session.close();

我的回复处理程序如下

@Override
public void onMessage(Message message) {

    try
    {

        System.out.println(message.getStringProperty("status"));
    }
    catch (JMSException e) 
    {
            e.printStackTrace();
    }
}  

现在我从临时队列中获取结果。因为它在同一个会话中。
我的问题是我想使用临时队列名称从不同会话中的临时队列中获取消息。如果我想使用临时队列名称从不同客户端的临时队列中获取消息我将如何做到这一点? 。

Now i am getting the result from temporary queue. because its in the same session. my question is i want to get the message from temporary queue in differesnt session using temporary queue name. if i want to get the message from temporary queue in different client using temporary queue name how i will do that ? .

推荐答案

通常,您可以设置回复jms标头,然后设置消息的消息(例如,肯定在不同的会话..)你可以拉出那个临时目的地的JMSReplyTo标题,然后回复那个。

Usually, you would set the reply-to jms header, and then wherever you consume the message (eg, certainly in a different session..) you can pull out that JMSReplyTo header which would be the temp destination and just reply to that.

你应该查看ActiveMQ维基:

You should check the ActiveMQ wiki:

http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html

这篇关于如何从不同会话中的临时队列中获取消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆