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 8984679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:09:55+00:00 2026-06-15T21:09:55+00:00

The following code snippet (standalone Java-application) will never find any messages on the queue

  • 0

The following code snippet (standalone Java-application) will never find any messages on the queue while the same client, when implemented using message listeners, does (Using Glassfish 3.1):

ctx = new InitialContext();
connectionFactory = (ConnectionFactory) ctx.lookup("foo.Factory");

partsQueue = (Queue) ctx.lookup("foo.PartsQueue");

conn = connectionFactory.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(partsQueue);

conn.start();

Message msg = null;
int cnt = -1;
do {
    cnt++;
    msg = consumer.receiveNoWait();
} while (msg != null);

        System.out.println("cnt: " + cnt);

If I use the following code after creating the consumer, the listener will find the messages and consume them successfully:

listener = new AssemblerListener(this);
consumer.setMessageListener(listener);
System.out.println("waiting for msgs...");
conn.start();

As mentioned, standalone Java client, I’m not trying to do something in MDBs synchronously. Any ideas? Did not find any hints why synchronous read should not work here. Using message listeners is not the best option in this case as I have to read two messages using different filters sometimes.

  • 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-15T21:09:57+00:00Added an answer on June 15, 2026 at 9:09 pm

    This is the way i receive Meessages:

        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(url);
    
        // Getting JMS connection from the server
        ConnectionFactory connectionFactory= activeMQConnectionFactory;
    
        Connection connection = connectionFactory.createConnection();
    
        // Creating session for sending messages
        Session session = connection.createSession(false,Session.CLIENT_ACKNOWLEDGE);
    
    
        // Getting the queue 'TESTQUEUE'
        Destination destination = session.createQueue("queue_name");
    
        // MessageConsumer is used for receiving (consuming) messages
    
        MessageConsumer consumer = session.createConsumer(destination);
    
        connection.start();        
    
        // Here we receive the message.
        // By default this call is blocking, which means it will wait
        // for a message to arrive on the queue.
        Message message= consumer.receive(500);
        while(message!= null)
        {
    
            // There are many types of Message and TextMessage
            // is just one of them. Producer sent us a TextMessage
            // so we must cast to it to get access to its .getText()
            // method.
            if (message instanceof TextMessage) 
            {
                TextMessage textMessage = (TextMessage) message;
           //     BytesMessage Byte
    
                System.out.println("Received message '"+ textMessage.getText() + "'");
            }           
            message = consumer.receive(1);
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code snippet generates some warning messages when compiling: Cluster& Myclass::getCluster(const Point &p)
In the following code snippet: NSMutableArray *tmpItemsArray =[[[NSMutableArray alloc] init] autorelease]; while (sqlite3_step(fetch_statement)==SQLITE_ROW){ int
Why does following code snippet doesn't work? It doesn't gives any error, but also
The following code snippet is taken from android JellyBean ReferenceQueue.java in the libcore project.
The following code snippet will result in a run-time: class Vehicle { public void
I am getting the following code snippet from Android's Pair.java public boolean equals(Object o)
The following code snippet on SQL server 2005 fails on the ampersand '&': select
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
The following code snippet attempts to create a Tib DaemonManager connecting to a particular
i have the following code snippet in my ANT File which compiles my project

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.