Discussion:
[openjms-developer] Priority Queing & Extending Queue to include Attributes
Curtis Paris
2003-12-22 21:32:16 UTC
Permalink
I currently have implemented priority based Queuing into the OpenJMS
system. But, I'm struggling with the best way to have a client define
it's priority. There is no obvious way in JMS, that I can see, to pass
an attribute for each Queue. I would rather not do it on a ClientID
basis, since it may be applicable that some clients need to have a
higher priority in one queue, and a lower priority in another (including
in my environment). As soon as I can get a best practice for
specifying the client priority, I'll be happy to send in my code to the
OpenJMS project

To give you an idea of what the priority queuing does, here we go:

A client creates a queue connection, and specifies its priority (agian,
any ideas on best practices?). Priorities are defined as a byte.

QueueDestinationCache will look for people to handle the message by:
- Top to Bottom Priorioty
- Round Robin Servers for each priority (keeping track of the
last server # for each priority level).

Example, if I had five clients:
#1 - Priority of 200
#2 - Priority of 200
#3 - Priority of 100
#4 - Priority of 100
#5 - Priority of 50

* It will round robin and check to see if client #1 or #2 can
select the message and are ready for it (checking all highest priority
servers first)
* If not, it will round robin and check to see if Client #3 or #4
can select the message and are ready for it.
* If not, it will round robin #5 and check to see if client #5 can
select the message and is ready for it.
* If not, queue the message for later delivery.


Clients can not change their priority unless the unregister and
reregister. (Although it would be simple enough to have
registerConsumer() handle this appropriately.


My only thought on how to do this would be to extend the selection
critereon. For example:

Currently: MyHeader > 5
Attributed: {Priority=5} MyHeader > 5

When the client is connected, it will parse out attributes in {}'s.
It'll then release the rest of it for the normal parser.


_____

Curtis Paris
Software Engineer IV
Metro One Telecommunications, Inc.
11200 Murray Scholls Place
Beaverton, OR 97007 Phone: +1 (503) 643-9500
Fax: +1 (503) 643-9600
E-Mail: ***@metro1.com
Web: http://www.metro1.com/
Tim Anderson
2003-12-23 13:33:27 UTC
Permalink
MessageTo clarify, you're trying to ensure that clients with a higher
priority receive messages
before those with a lower priority?
I suspect you could simulate this behaviour in your clients, by using
blocking receive() calls,
in conjunction with Thread.sleep().
High priority clients would specify a long receive timeout, and a short
sleep time,
while low priority clients would specify a short receive timeout and a long
sleep time -
this would ensure that high priority clients are more likely to receive
messages.

E.g:
public Message receive(QueueReceiver receiver, int clientPriority)
throws JMSException {

if (clientPriority > 10) {
clientPriority = 10;
}
long sleepTimeout = 1000 - (clientPriority * 100);
long recvTimeout = 1000 - sleepTimeout;

Message message = null;
while (message == null) {
message = receiver.receive(recvTimeout);
if (message == null) {
try {
Thread.currentThread().sleep(sleepTimeout);
} catch (InterruptedException ignore) {
}
}
return message;
}

For a high priority client (10), invoking the above with
Message message = receive(receiver, 10);
would wait at most 1 second for a message, and not sleep if no message
is received.

For a low priority client (1), invoking the above with
Message message = receive(receiver, 10);
would wait at most 100 milliseconds for a message, and sleep for 900ms if no
message
is received.

-----Original Message-----
From: openjms-developer-***@lists.sourceforge.net
[mailto:openjms-developer-***@lists.sourceforge.net]On Behalf Of Curtis
Paris
Sent: Tuesday, 23 December 2003 8:32 AM
To: openjms-***@lists.sourceforge.net
Subject: [openjms-developer] Priority Queing & Extending Queue to include
Attributes


I currently have implemented priority based Queuing into the OpenJMS
system. But, I'm struggling with the best way to have a client define it's
priority. There is no obvious way in JMS, that I can see, to pass an
attribute for each Queue. I would rather not do it on a ClientID basis,
since it may be applicable that some clients need to have a higher priority
in one queue, and a lower priority in another (including in my environment).
As soon as I can get a best practice for specifying the client priority,
I'll be happy to send in my code to the OpenJMS project

To give you an idea of what the priority queuing does, here we go:

A client creates a queue connection, and specifies its priority (agian,
any ideas on best practices?). Priorities are defined as a byte.

QueueDestinationCache will look for people to handle the message by:
- Top to Bottom Priorioty
- Round Robin Servers for each priority (keeping track of the last
server # for each priority level).

Example, if I had five clients:
#1 - Priority of 200
#2 - Priority of 200
#3 - Priority of 100
#4 - Priority of 100
#5 - Priority of 50
a.. It will round robin and check to see if client #1 or #2 can select
the message and are ready for it (checking all highest priority servers
first)
b.. If not, it will round robin and check to see if Client #3 or #4 can
select the message and are ready for it.
c.. If not, it will round robin #5 and check to see if client #5 can
select the message and is ready for it.
d.. If not, queue the message for later delivery.

Clients can not change their priority unless the unregister and
reregister. (Although it would be simple enough to have registerConsumer()
handle this appropriately.


My only thought on how to do this would be to extend the selection
critereon. For example:

Currently: MyHeader > 5
Attributed: {Priority=5} MyHeader > 5

When the client is connected, it will parse out attributes in {}'s. It'll
then release the rest of it for the normal parser.




----------------------------------------------------------------------------
--
Curtis Paris
Software Engineer IV
Metro One Telecommunications, Inc.
11200 Murray Scholls Place
Beaverton, OR 97007 Phone: +1 (503) 643-9500
Fax: +1 (503) 643-9600
E-Mail: ***@metro1.com
Web: http://www.metro1.com/

Loading...