Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:47:34+00:00 2026-06-09T21:47:34+00:00

If I use the following code to create a sender and receiver qsender =

  • 0

If I use the following code to create a sender and receiver

qsender = qsession.createSender((Queue)msg.getJMSDestination());
qreceiver=qsession.createReceiver((Queue)msg.getJMSDestination());

and then do this

qsender.send(msg);

Does it just send the message to the queue and will it remain in the queue forever? Do I need to call the receive() method on the receiver or implement the MessageListener interface to get it to the receiver?

Edit: more info

qsender = qsession.createSender((Queue)msg.getJMSDestination());
qreceiver=qsession.createReceiver((Queue)msg.getJMSDestination());

temp1 = qsession.createTemporaryQueue();
responseConsumer = qsession.createConsumer(temp1);
msg.setJMSReplyTo(temp1);

responseConsumer.setMessageListener(responseListener);
msg.setJMSCorrelationID(msg.getJMSCorrelationID()+i);

qsender.send(msg);

In the above code, what is the temporary queue used for? Is it for receiving the messages? Is it the receiver? And if yes, whats the use of msg.setJMSReplyTo(temp1) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:47:35+00:00Added an answer on June 9, 2026 at 9:47 pm

    Yes, send(..) method will send message to the destination queue. And this message will remain in the queue until your program will receive it using receiver or until your message broker is running (as I know).

    About your second question then the difference between two approaches consist in next:

    receive(..) method is synchronous (and this is a downside of this approach). This means that the receiver must wait patiently for the message to arrive, as the receive() message will block until a message is available (or until a timeout condition occurs). From other side consuming messages with listener is asynchronous process. Your receiver will not wait. Listener will call your receiving method only when message will be put to the query.

    UPDATE:

    Temporary destination is used for sending a reply on a message by consumer. For example can be situation that your server get message from client and you need to send response to him. In such case you should use temporary destination. Server application will use this temporary destination (queue in your case) for sending a response message to client. Such queues have a scope limited to the connection that created it, and are removed on the server side as soon as the connection is closed.

    More details you can find in this article and in officila java tutorial. In second article also describes how and when to use JMSCorrelationID.

    Here is interesting part from official doc that describes how to send response message using temporary destination:

    You can use temporary destinations to implement a simple request/reply
    mechanism. If you create a temporary destination and specify it as the
    value of the JMSReplyTo message header field when you send a message,
    then the consumer of the message can use the value of the JMSReplyTo
    field as the destination to which it sends a reply. The consumer can
    also reference the original request by setting the JMSCorrelationID
    header field of the reply message to the value of the JMSMessageID
    header field of the request. For example, an onMessage method can
    create a session so that it can send a reply to the message it
    receives. It can use code such as the following:

    producer = session.createProducer(msg.getJMSReplyTo());
    replyMsg = session.createTextMessage("Consumer " +
        "processed message: " + msg.getText());
    replyMsg.setJMSCorrelationID(msg.getJMSMessageID());
    producer.send(replyMsg);
    

    UPDATE 2:

    I want to clarify my unswer about message expiration time in the queue (or topic). By default message will never expire. But you can set expiration time for message:

    producer.setTimeToLive(60000);
    

    After this all messages produced by this MessageProducer will have specified expiration time.

    Also you can specify expiration tyme for concrete message during it’s sending:

    producer.send(message, DeliveryMode.NON_PERSISTENT, 3, 10000);
    

    where 10000 means 10 seconds

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use following code: Create a retry policy, when error, retry after 1 second,
I use the following code try to create an array of string vectors, I
I just use following code to add an image to my project, var paper
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
I use the following code to crop an image according to a rectangular selection
I use the following code to copy a particular directory and its contents to
I use the following code to fill all empty keys in sub-arrays with ``
I use the following code... $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP
I use the following code to add a Music player in my site, <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.