[rabbitmq-discuss] Priority queue doesn't seem to work as expected
Nikita Zubrilov
nikita.zubrilov at gmail.com
Mon Jul 14 09:11:25 BST 2014
Hello,
I'm using Rabbitmq 3.3.3 on Windows 7.
I installed *rabbitmq-priority-queue plugin*, enable it, and finally restart
Rabbitmq server. When I list rabbitmq plugins I see => [E]
rabbitmq_priority_queue.
I tried the example from GitHub and it WORKS. Though, it is a very very
simple example.
But, when I tried some a little bit complex example, the queue seems to
behave in a very strange way.
So, my setup is like this:
First, the common configuration of the queue, just like in the example:
private static final String QUEUE = "my-priority-queue";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
Connection conn = factory.newConnection();
Channel ch = conn.createChannel();
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-priority", 10);
ch.queueDeclare(QUEUE, true, false, false, args);
...
I have a Producer thread that sends messages in intervals of couple of
seconds. For each message I define priority from 0 to 10 just like in the
example. For example sends 10 messages each 2 seconds:
the run() method looks like this:
while(true){
for(Message message : MESSAGES){
BasicProperties props =
MessageProperties.PERSISTENT_BASIC.builder().priority(message.priority)
.build();
System.out.println("Sent " + message.body);
ch.basicPublish("", QUEUE, props, message.body.getBytes());
}
Thread.sleep(2000);
}
Also, there is a Consumer thread which waits for incoming messages and
prints them on the screen:
inside run() method:
QueueingConsumer consumer = new
QueueingConsumer(channel);channel.basicConsume("hello", true,
consumer);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'"); }
nothing special...
And the behavior I get is the following:
All the messages that was posted BEFORE the Consumer starts to run are
received in prioritized order, BUT all the messages that sent AFTER the
Consumer starts, are received in the same order they were sent without
concerning a priority. Tried to put some Thread.sleep() in different places
in code to give the queue some time to reorganize itself, but it didn't
work.
So, it seems like priority works only on some static queues without
constantly working Consumer and Producer.
Am I right?
Maybe I am doing something wrong?
Can you please give some complex example for using the priority-queue
plugin?
In my project, we'll have a number of Producers and a number of Consumers
asynchronously putting and taking items from the queue. Does the plugin
support the following scenario?
Thank you,
Nik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140714/be35fba3/attachment.html>
More information about the rabbitmq-discuss
mailing list