You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Jecsiac <je...@163.com> on 2008/08/26 09:38:17 UTC

Problem with Selector

Hi, I have a problem when using selector in ActiveMQ 5.1.0. 

I set a property named 'SomeId' on every Message sent to the queue, and
every Message has a different value of that property (the value is just the
order of the message sent to the queue, for example, for the first message
sent to the queue, it's SomeId is 1, and for the second, is 2, and so on.
And here, I use this mechanism is just for describing the problem easily.
It's not the thing that I want to realize). When I use selector to receive
message from the queue, I get a strange result: I send 2000 messages to the
queue, and when I write:

QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 5');
receiver.receiveNoWait();

I can get the message. But when I write:

QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 200');
receiver.receiveNoWait();

I just get null. What's the problem? I do the just same thing on JBossMQ,
everything is right, no problem. So I just do not known what's going wrong.

Thanks
Best regards
-- 
View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p19157015.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by Jecsiac <je...@163.com>.
Thanks a lot at first. No, I'm not trying to do request/response over JMS. I
use receiveNoWait() because I need to return immediately when there's no
message in the queue. I'll try receive(some time) later. However, it is so
regret that different JMS providers behave so differently... My codes go
well on some other providers, but, if I want to use ActiveMQ, it seems I
have to make some modification...


-- 
View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p19158325.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by James Strachan <ja...@gmail.com>.
BTW are you trying to do request/response over JMS - is that why
you're numbering your messages and trying to receive a specific one
back?

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

2008/8/26 James Strachan <ja...@gmail.com>:
> 2008/8/26 Jecsiac <je...@163.com>:
>>
>> Hi, I have a problem when using selector in ActiveMQ 5.1.0.
>>
>> I set a property named 'SomeId' on every Message sent to the queue, and
>> every Message has a different value of that property (the value is just the
>> order of the message sent to the queue, for example, for the first message
>> sent to the queue, it's SomeId is 1, and for the second, is 2, and so on.
>> And here, I use this mechanism is just for describing the problem easily.
>> It's not the thing that I want to realize). When I use selector to receive
>> message from the queue, I get a strange result: I send 2000 messages to the
>> queue, and when I write:
>>
>> QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 5');
>> receiver.receiveNoWait();
>>
>> I can get the message. But when I write:
>>
>> QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 200');
>> receiver.receiveNoWait();
>>
>> I just get null. What's the problem? I do the just same thing on JBossMQ,
>> everything is right, no problem. So I just do not known what's going wrong.
>
> receiveNoWait() is not meant to wait for a message to arrive. In
> ActiveMQ creating a receiver does not block until messages are
> received.
>
> i.e. its not really JMS compliant to use receiveNoWait() and not
> expect nulls to come back if you've not really left much time for the
> JMS provider to actually find the messages and return them over the
> network.
>
> Just replace receiveNoWait() with receive(2000L) and it should work fine
>
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Problem with Selector

Posted by Gary Tully <ga...@gmail.com>.
I wonder if your issue is related to the pageSize, default 200, the amount
of messages that the broker will keep in memory for a destination. If your
selection criteria matches a message further down the queue than the
pageSize it will not be dispatched till those ahead of it in the queue are
consumed.

On trunk, or 5.3.0, with a prefetch=0 and a selectable message in the page
window, a receive(timeout)  will work reliable assuming no network glitches.
To make it more deterministic, use of asyncDispatch==false for your consumer
will also help.



2010/1/18 akos <ak...@p92.hu>

>
> Hi, are there any news on this issue? Any low level method maybe?
> receiveNoWait and receive(timeout)  both can return null even if the queue
> contains selectable messages. It makes no sense to rely on these methods.
> --
> View this message in context:
> http://old.nabble.com/Problem-with-Selector-tp19157015p27212570.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
http://blog.garytully.com

Open Source Integration
http://fusesource.com

Re: Problem with Selector

Posted by akos <ak...@p92.hu>.
Hi, are there any news on this issue? Any low level method maybe?
receiveNoWait and receive(timeout)  both can return null even if the queue
contains selectable messages. It makes no sense to rely on these methods.
-- 
View this message in context: http://old.nabble.com/Problem-with-Selector-tp19157015p27212570.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by IBeaumont <IB...@categoric.com>.
Sorry about opening up an old thread, by I've got all the same fustrations as
Jecsiac with this issue.

How can I write a deterministic system to return a message if it exists on a
queue, or null if it doesn't exist.  How long should I wait, a second, a
minute, an hour?  What if I have a million messages - how long is long
enough.   And if then I have no messages on my queue I've wasted lots of
time waiting for a message that didn't exist.

Surely receiveNoWait is the correct way to go - and the ActiveMQ
implementation is wrong.  As well as WebSphereMQ we also use SwiftMQ as a
queue provider, and things behave like this.

James - which other providers work the way ActiveMQ does?

TIA
Ian
-- 
View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p21496474.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by Jecsiac <je...@163.com>.
>It seems to be provider specific. Many JMS providers will treat
>"Receives the next message if one is immediately available" literally
>- i.e. not to wait for a request/response with the broker to check if
>there is a message available for processing. This is what ActiveMQ
>does and a number of other JMS providers do the same - but its
>provider specific.

>At the very least you should wait some period of time (say 1 second)
>after creating your consumer before issuing a receiveNoWait() if you
>want your code to work with most JMS providers - or use receive(1000)
>on the first call - then use receiveNoWait() afterwards etc.

Thanks, I'll try it. But I still doubt that would it be more complex if the
provider do so? Why not an easier way (maybe)? And, as I tested, JBossMQ and
WebSphereMQ behave as my expectation. I do not have more test environment, 
so don't known how other providers act. Oh, provider specific, I have to say
it is nightmare for programmer, ^_^, joking, but it's really pain.
-- 
View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p19162534.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by James Strachan <ja...@gmail.com>.
It seems to be provider specific. Many JMS providers will treat
"Receives the next message if one is immediately available" literally
- i.e. not to wait for a request/response with the broker to check if
there is a message available for processing. This is what ActiveMQ
does and a number of other JMS providers do the same - but its
provider specific.

At the very least you should wait some period of time (say 1 second)
after creating your consumer before issuing a receiveNoWait() if you
want your code to work with most JMS providers - or use receive(1000)
on the first call - then use receiveNoWait() afterwards etc.

2008/8/26 Jecsiac <je...@163.com>:
>
>>receiveNoWait() is not meant to wait for a message to arrive. In
>>ActiveMQ creating a receiver does not block until messages are
>>received.
>
>>i.e. its not really JMS compliant to use receiveNoWait() and not
>>expect nulls to come back if you've not really left much time for the
>>JMS provider to actually find the messages and return them over the
>
> JMS 1.1 Specification has no words on receiveNoWait() (at least in it's PDF
> document). And in JMS 1.1 API document, it just said:
>
> receiveNoWait
> public Message receiveNoWait()
>                      throws JMSException
> Receives the next message if one is immediately available.
> Returns:
> the next message produced for this message consumer, or null if one is not
> available
> Throws:
> JMSException - if the JMS provider fails to receive the next message due to
> some internal error.
>
> Maybe it is some amphibolous. So I think my expectation could also be
> proper: There're 2000 messages in the queue, and the message I want to find
> is just in them, so why receiveNoWait() gives me a null? Of course, the
> provider needs time to find out the message. But in contrast with receive():
>
> receive
> public Message receive()
>                throws JMSException
> Receives the next message produced for this message consumer.
> This call blocks indefinitely until a message is produced or until this
> message consumer is closed.
>
> If this receive is done within a transaction, the consumer retains the
> message until the transaction commits.
>
> Returns:
> the next message produced for this message consumer, or null if this message
> consumer is concurrently closed
> Throws:
> JMSException - if the JMS provider fails to receive the next message due to
> some internal error.
>
> It seems NoWait could means no 'blocks indefinitely until a message is
> produced' —— but should it include the time the provider needs to find out
> the message? No more words. So maybe it is some amphibolous.
>
> --
> View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p19161717.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Problem with Selector

Posted by Jecsiac <je...@163.com>.
>receiveNoWait() is not meant to wait for a message to arrive. In
>ActiveMQ creating a receiver does not block until messages are
>received.

>i.e. its not really JMS compliant to use receiveNoWait() and not
>expect nulls to come back if you've not really left much time for the
>JMS provider to actually find the messages and return them over the

JMS 1.1 Specification has no words on receiveNoWait() (at least in it's PDF
document). And in JMS 1.1 API document, it just said:

receiveNoWait
public Message receiveNoWait()
                      throws JMSException
Receives the next message if one is immediately available.
Returns:
the next message produced for this message consumer, or null if one is not
available
Throws:
JMSException - if the JMS provider fails to receive the next message due to
some internal error.

Maybe it is some amphibolous. So I think my expectation could also be
proper: There're 2000 messages in the queue, and the message I want to find
is just in them, so why receiveNoWait() gives me a null? Of course, the
provider needs time to find out the message. But in contrast with receive():

receive
public Message receive()
                throws JMSException
Receives the next message produced for this message consumer. 
This call blocks indefinitely until a message is produced or until this
message consumer is closed. 

If this receive is done within a transaction, the consumer retains the
message until the transaction commits.

Returns:
the next message produced for this message consumer, or null if this message
consumer is concurrently closed
Throws:
JMSException - if the JMS provider fails to receive the next message due to
some internal error.

It seems NoWait could means no 'blocks indefinitely until a message is
produced' —— but should it include the time the provider needs to find out
the message? No more words. So maybe it is some amphibolous.

-- 
View this message in context: http://www.nabble.com/Problem-with-Selector-tp19157015p19161717.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Problem with Selector

Posted by James Strachan <ja...@gmail.com>.
2008/8/26 Jecsiac <je...@163.com>:
>
> Hi, I have a problem when using selector in ActiveMQ 5.1.0.
>
> I set a property named 'SomeId' on every Message sent to the queue, and
> every Message has a different value of that property (the value is just the
> order of the message sent to the queue, for example, for the first message
> sent to the queue, it's SomeId is 1, and for the second, is 2, and so on.
> And here, I use this mechanism is just for describing the problem easily.
> It's not the thing that I want to realize). When I use selector to receive
> message from the queue, I get a strange result: I send 2000 messages to the
> queue, and when I write:
>
> QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 5');
> receiver.receiveNoWait();
>
> I can get the message. But when I write:
>
> QueueReceiver receiver = session.createReceiver(queue, 'SomeId = 200');
> receiver.receiveNoWait();
>
> I just get null. What's the problem? I do the just same thing on JBossMQ,
> everything is right, no problem. So I just do not known what's going wrong.

receiveNoWait() is not meant to wait for a message to arrive. In
ActiveMQ creating a receiver does not block until messages are
received.

i.e. its not really JMS compliant to use receiveNoWait() and not
expect nulls to come back if you've not really left much time for the
JMS provider to actually find the messages and return them over the
network.

Just replace receiveNoWait() with receive(2000L) and it should work fine


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com