3 Replies Latest reply on Jun 7, 2010 10:57 AM by Tim Fox

    receiveNoWait problem in 2.1.0CR1

    Chris Stillwell Newbie

      I have a test that sends multiple messages to a queue, then loops performing a receiveNoWait until a null response is returned.  What I am seeing is that one message is read off of the queue and the second receiveNoWait returns null even thought there are still more messages on the queue.  I had seen issue HORNETQ-284 which dealt with receiveNoWait not working so I installed 2.1.0CR1.  Here's the out put from a test run that sends 4 messages, browses the queue, does the receiveNoWait loop, and then browses the queue again.

       

      HornetQMessage[ID:1b46fa55-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111
      HornetQMessage[ID:1b496b56-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111
      HornetQMessage[ID:1b4a0797-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222
      HornetQMessage[ID:1b4af1f8-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222
      4 messages on queue.
      Received message: HornetQMessage[ID:1b46fa55-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.01
      This is a test message0
      Received message: null, RequestId=0, duration 00:00:00.00
      1 messages read from queue.
      HornetQMessage[ID:1b496b56-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111
      HornetQMessage[ID:1b4a0797-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222
      HornetQMessage[ID:1b4af1f8-6fee-11df-b9f5-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222
      3 messages on queue.

       

      If I change the receiveNoWait to receive( 1 ) then it will usually pull all of the messages off of the queue.

       

      HornetQMessage[ID:5d06c39c-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:5d08bf6d-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:5d09349e-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:5d09d0df-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      4 messages on queue.

       

      Received message: HornetQMessage[ID:5d06c39c-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.00

      This is a test message0

      Received message: HornetQMessage[ID:5d08bf6d-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.00

      This is a test message1

      Received message: HornetQMessage[ID:5d09349e-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222, duration 00:00:00.00

      This is a test message2

      Received message: HornetQMessage[ID:5d09d0df-6ff1-11df-885e-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222, duration 00:00:00.00

      This is a test message3

      Received message: null, RequestId=0, duration 00:00:00.01

      4 messages read from queue.

       

      0 messages on queue.

       

       

      However, I have seen where using receive( 1 ) does not pul all of the messages off of the queue, but this is intermittent.

       

      HornetQMessage[ID:dd864a14-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:dd889405-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:dd890936-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:dd89a577-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e02ed4c8-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e030f7a9-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e031bafa-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e032a55b-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e26ed9f9-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e272355a-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e2731fbb-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e273bbfc-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:f3a39b52-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:f3a59723-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:f3a68184-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:f3a744d5-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      16 messages on queue.

       

      Received message: HornetQMessage[ID:dd864a14-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.00

      This is a test message0

      Received message: HornetQMessage[ID:dd889405-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.01

      This is a test message1

      Received message: HornetQMessage[ID:dd890936-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222, duration 00:00:00.01

      This is a test message2

      Received message: HornetQMessage[ID:dd89a577-6fea-11df-bb80-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222, duration 00:00:00.01

      This is a test message3

      Received message: HornetQMessage[ID:e02ed4c8-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111, duration 00:00:00.01

      This is a test message0

      Received message: null, RequestId=0, duration 00:00:00.01

      5 messages read from queue.

       

      HornetQMessage[ID:e030f7a9-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e031bafa-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e032a55b-6fea-11df-9346-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e26ed9f9-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e272355a-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:e2731fbb-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:e273bbfc-6fea-11df-b140-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:f3a39b52-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:f3a59723-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=1111111

      HornetQMessage[ID:f3a68184-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      HornetQMessage[ID:f3a744d5-6fea-11df-84dc-0023dfffb25d:0000000000000000]:PERSISTENT, RequestId=2222222

      11 messages on queue.

       

      Process finished with exit code 0

       

      I do not see this behavior when running with jboss mq.  If there is a configuration option that might cause this I would be interested to know what it is.  I am running jboss-5.1.0.GA with the default-with-hornetq configuration generated by HornetQ.  I have attached my test source in case it's just me.

        • 1. Re: receiveNoWait problem in 2.1.0CR1
          Tim Fox Master

          A couple of observations from looking at your code:

           

          1) Don't create new producer/consumer every time you send/consume a message. This is a common anti-pattern, and has been discussed many times on this forum, and in the performance chapter of the user manual.

           

          2) When you send a message. It might not arrive in the in memory queue until a little time later. Only messages in the queue will be received by receiveNoWait. So I'd expect it not to immediately see all the messages.

          • 2. Re: receiveNoWait problem in 2.1.0CR1
            Chris Stillwell Newbie

            1) Thanks for the info.  My understanding is that producers and consumers are not thread safe.  Can you point me to any good articles that talk about the pros and cons of just synchronizing the producer/consumer vs. creating pools? 

             

            2) Is it possible for the QueueBrowser to see the message on the queue and the receiveNoWait to not see it on the queue?  My test put 4 messages on the queue, the QueueBrowser showed all 4 on the queue, but the receiveNoWait loop only pulled one message off.  Running the test again it will put 4 more messages on the queue, the QueueBrowser will show a total of 7 messages on the queue, but the receiveNoWait loop again only pulls 1 message off.  With jboss mq the receiveNoWait loop always pulled all the messages off of the queue.

            • 3. Re: receiveNoWait problem in 2.1.0CR1
              Tim Fox Master

              Chris Stillwell wrote:

               

              1) Thanks for the info.  My understanding is that producers and consumers are not thread safe.  Can you point me to any good articles that talk about the pros and cons of just synchronizing the producer/consumer vs. creating pools? 

               

               

              This really depends on your application semantics. Also, it's not just a black and white choice between pooling and synchronization. You might have some other natural cardinality in your application that could apply. E.g. you might decide to maintain one session per football team, each football team maintains the reference to a session. The possibilities are endless.

               

              Chris Stillwell wrote:


               

              2) Is it possible for the QueueBrowser to see the message on the queue and the receiveNoWait to not see it on the queue? 

              Yes, that's quite possible, depending on exactly when they were create / executed.