发布JMS消息后获得响应

时间:2022-11-25 20:17:17

The following block of code is used to post a set of JMS messages to an EMS server

以下代码块用于将一组JMS消息发布到EMS服务器

            for(int i=1;i<=200;i++)
            {

                msg=myMessages.get(i); // myMessages is an Arraylist of TextMessages
                qsender = qsession.createSender((Queue)msg.getJMSDestination());
                qreceiver=qsession.createReceiver((Queue)msg.getJMSDestination());
                temp1 = qsession.createTemporaryQueue();
                responseConsumer = qsession.createConsumer(temp1);
                msg.setJMSReplyTo(temp1);
                msg.setJMSCorrelationID(msg.getJMSCorrelationID()+i);
                qsender.send(msg);

            }

Since this was not developed by me, I have some queries on it.

由于这不是我开发的,我对它有一些疑问。

  1. What does the query actually do? Does it just post the messages without a response?
  2. 查询实际上做了什么?是否只是在没有回复的情况下发布消息?

  3. If yes, how do we know when the response comes back and how do we calculate the time taken?
  4. 如果是,我们如何知道响应何时返回以及我们如何计算所花费的时间?

  5. And how do we calculate the total time the message takes to reach there and the response to come back?
  6. 我们如何计算消息到达那里的总时间以及回复的响应?

Please let me know if any more info is required.

如果需要更多信息,请告诉我。

2 个解决方案

#1


0  

Does it just post the messages without a response?

是否只是在没有回复的情况下发布消息?

yes. it also creates a sender to send the message and a receiver which it doesn't appear to use.

是。它还创建了一个发送消息的发送者和一个它似乎没有使用的接收者。

If yes, how do we know when the response comes back and how do we calculate the time taken?

如果是,我们如何知道响应何时返回以及我们如何计算所花费的时间?

It creates a temporary queue and a receiver for that. It expect the other end will send a message to the queue name stored in "JMSReplyTo"

它为此创建一个临时队列和接收器。它期望另一端将消息发送到存储在“JMSReplyTo”中的队列名称

And how do we calculate the total time the message takes to reach there and the response to come back?

我们如何计算消息到达那里的总时间以及回复的响应?

You can have the consumer get the time and match it to the time the first message was sent.

您可以让消费者获得时间并将其与发送第一条消息的时间相匹配。

IMHO A simpler approach is to add the time sent as a property and have the service return this back. This way you have all the information you need in the message coming back.

恕我直言更简单的方法是添加作为属性发送的时间并让服务返回此状态。这样,您就可以在消息中找到所需的所有信息。

#2


0  

To answer your questions :

回答你的问题:

  1. Yes, it only post messages ;

    是的,它只发布消息;

  2. You do know when a message comes back by implementing a MessageListener then each times the onMessage() method is invoked a new message will be ready for processing ;

    您知道何时通过实现MessageListener返回消息,然后每次调用onMessage()方法时,都会准备好处理新消息;

  3. To answer the third question is a bit more complicated but you may want to log or write in some kind of persistent storage the time when the message was posted, and when the response was received (based on the correlationId, you may then be able to know how much time was elapse for each message) ;

    回答第三个问题有点复杂,但是你可能想要在发布消息的时候记录或写入某种持久性存储,并且当收到响应时(基于correlationId,你可以然后能够知道每条消息已经过了多少时间);

Regards,

Y.

#1


0  

Does it just post the messages without a response?

是否只是在没有回复的情况下发布消息?

yes. it also creates a sender to send the message and a receiver which it doesn't appear to use.

是。它还创建了一个发送消息的发送者和一个它似乎没有使用的接收者。

If yes, how do we know when the response comes back and how do we calculate the time taken?

如果是,我们如何知道响应何时返回以及我们如何计算所花费的时间?

It creates a temporary queue and a receiver for that. It expect the other end will send a message to the queue name stored in "JMSReplyTo"

它为此创建一个临时队列和接收器。它期望另一端将消息发送到存储在“JMSReplyTo”中的队列名称

And how do we calculate the total time the message takes to reach there and the response to come back?

我们如何计算消息到达那里的总时间以及回复的响应?

You can have the consumer get the time and match it to the time the first message was sent.

您可以让消费者获得时间并将其与发送第一条消息的时间相匹配。

IMHO A simpler approach is to add the time sent as a property and have the service return this back. This way you have all the information you need in the message coming back.

恕我直言更简单的方法是添加作为属性发送的时间并让服务返回此状态。这样,您就可以在消息中找到所需的所有信息。

#2


0  

To answer your questions :

回答你的问题:

  1. Yes, it only post messages ;

    是的,它只发布消息;

  2. You do know when a message comes back by implementing a MessageListener then each times the onMessage() method is invoked a new message will be ready for processing ;

    您知道何时通过实现MessageListener返回消息,然后每次调用onMessage()方法时,都会准备好处理新消息;

  3. To answer the third question is a bit more complicated but you may want to log or write in some kind of persistent storage the time when the message was posted, and when the response was received (based on the correlationId, you may then be able to know how much time was elapse for each message) ;

    回答第三个问题有点复杂,但是你可能想要在发布消息的时候记录或写入某种持久性存储,并且当收到响应时(基于correlationId,你可以然后能够知道每条消息已经过了多少时间);

Regards,

Y.