<div dir="ltr">Hello,<div><br></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">I'm using Rabbitmq 3.3.3 on Windows 7.</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">I installed <b>rabbitmq-priority-queue plugin</b>, enable it, and finally restart</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">Rabbitmq server. </span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">When I list rabbitmq plugins I see => [E] rabbitmq_priority_queue.</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">
</div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">I tried the example from GitHub and it WORKS. Though, it is a very very simple example.</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">But,    when I tried some a little bit complex example, the queue seems to behave in a very strange way.</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">So, my setup is like this:</span></div><div>
<span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><font color="#000000" face="arial, sans-serif">First, the common configuration of the queue, just like in the example:</font></div>
<div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div class="" id="LC17" style="padding-left:10px;height:18px">
<span class="" style="font-weight:bold">private</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">QUEUE</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">"my-priority-queue"</span><span class="" style="font-weight:bold">;</span></div>
<div class="" id="LC18" style="padding-left:10px;height:18px"><br></div><div class="" id="LC19" style="padding-left:10px;height:18px">    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">void</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">main</span><span class="" style="font-weight:bold">(</span><span class="">String</span><span class="" style="font-weight:bold">[]</span> <span class="">argv</span><span class="" style="font-weight:bold">)</span> <span class="" style="font-weight:bold">throws</span> <span class="">Exception</span> <span class="" style="font-weight:bold">{</span></div>
<div class="" id="LC20" style="padding-left:10px;height:18px">        <span class="">ConnectionFactory</span> <span class="">factory</span> <span class="" style="font-weight:bold">=</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">ConnectionFactory</span><span class="" style="font-weight:bold">();</span></div>
<div class="" id="LC21" style="padding-left:10px;height:18px">        <span class="">Connection</span> <span class="">conn</span> <span class="" style="font-weight:bold">=</span> <span class="">factory</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">newConnection</span><span class="" style="font-weight:bold">();</span></div>
<div class="" id="LC22" style="padding-left:10px;height:18px">        <span class="">Channel</span> <span class="">ch</span> <span class="" style="font-weight:bold">=</span> <span class="">conn</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">createChannel</span><span class="" style="font-weight:bold">();</span></div>
<div class="" id="LC23" style="padding-left:10px;height:18px"><br></div><div class="" id="LC24" style="padding-left:10px;height:18px">        <span class="">Map</span><span class="" style="font-weight:bold"><</span><span class="">String</span><span class="" style="font-weight:bold">,</span> <span class="">Object</span><span class="" style="font-weight:bold">></span> <span class="">args</span> <span class="" style="font-weight:bold">=</span> <span class="" style="font-weight:bold">new</span> <span class="">HashMap</span><span class="" style="font-weight:bold"><</span><span class="">String</span><span class="" style="font-weight:bold">,</span> <span class="">Object</span><span class="" style="font-weight:bold">>();</span></div>
<div class="" id="LC25" style="padding-left:10px;height:18px">        <span class="">args</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">put</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">"x-max-priority"</span><span class="" style="font-weight:bold">,</span> <span class="" style="color:rgb(0,153,153)">10</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC26" style="padding-left:10px;height:18px">        <span class="">ch</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">queueDeclare</span><span class="" style="font-weight:bold">(</span><span class="">QUEUE</span><span class="" style="font-weight:bold">,</span> <span class="" style="font-weight:bold">true</span><span class="" style="font-weight:bold">,</span> <span class="" style="font-weight:bold">false</span><span class="" style="font-weight:bold">,</span> <span class="" style="font-weight:bold">false</span><span class="" style="font-weight:bold">,</span> <span class="">args</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC26" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">...</span></div></pre></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">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:</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">the run() method looks like this:</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">while(true){</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">   for(Message message : MESSAGES){</span></div>
<div><pre style="overflow:auto;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div class="" id="LC46" style="padding-left:10px;height:18px">
<span class="">BasicProperties</span> <span class="">props</span> <span class="" style="font-weight:bold">=</span> </div><div class="" id="LC46" style="padding-left:10px;height:18px"><span class="">MessageProperties</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">PERSISTENT_BASIC</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">builder</span><span class="" style="font-weight:bold">().</span><span class="" style="color:teal">priority</span><span class="" style="font-weight:bold">(message.</span><span class="">priority</span><span class="" style="font-weight:bold">)</span></div>
<div class="" id="LC46" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">build</span><span class="" style="font-weight:bold">();</span></div><div class="" id="LC48" style="padding-left:10px;height:18px">
        <span class="">System</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">out</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">println</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">"Sent "</span> <span class="" style="font-weight:bold">+</span> message.b<span class="">ody</span><span class="" style="font-weight:bold">);</span></div>
<div class="" id="LC49" style="padding-left:10px;height:18px">        <span class="">ch</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">basicPublish</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">""</span><span class="" style="font-weight:bold">,</span> <span class="">QUEUE</span><span class="" style="font-weight:bold">,</span> <span class="">props</span><span class="" style="font-weight:bold">,</span> message.<span class="">body</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">getBytes</span><span class="" style="font-weight:bold">());</span></div>
<div class="" id="LC49" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">}</span></div><div class="" id="LC49" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">Thread.sleep(2000);</span></div>
</pre></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">}</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><font color="#000000" face="arial, sans-serif">Also, there is a Consumer thread which waits for incoming messages and prints them on the screen:</font></div>
<div><font color="#000000" face="arial, sans-serif"><br></font></div><div><font color="#000000" face="arial, sans-serif">inside run() method:</font></div><div><pre style="padding:5px 15px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;font-size:13px;line-height:18px;background-color:rgb(238,238,238)">
<span class="" style="font-weight:bold"><pre style="padding:5px 15px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;font-size:13px;font-weight:normal"><span class="" style="color:rgb(0,128,128)">QueueingConsumer</span><font color="#555555"> </font><span class="" style="color:rgb(0,128,128)">consumer</span><font color="#555555"> </font><span class="" style="color:rgb(85,85,85);font-weight:bold">=</span><font color="#555555"> </font><span class="" style="color:rgb(85,85,85);font-weight:bold">new</span><font color="#555555"> </font><span class="" style="color:rgb(0,128,128)">QueueingConsumer</span><span class="" style="color:rgb(85,85,85);font-weight:bold">(</span><span class="" style="color:rgb(0,128,128)">channel</span><span class="" style="color:rgb(85,85,85);font-weight:bold">);</span><font color="#555555">
</font><span class="" style="color:rgb(0,128,128)">channel</span><span class="" style="color:rgb(85,85,85);font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">basicConsume</span><span class="" style="color:rgb(85,85,85);font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">"hello"</span><span class="" style="color:rgb(85,85,85);font-weight:bold">,</span><font color="#555555"> </font><font color="#008080">true</font><span class="" style="color:rgb(85,85,85);font-weight:bold">,</span><font color="#555555"> </font><span class="" style="color:rgb(0,128,128)">consumer</span><span class="" style="color:rgb(85,85,85);font-weight:bold">);</span></pre>
</span></pre><pre style="padding:5px 15px;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;color:rgb(85,85,85);font-size:13px;line-height:18px;background-color:rgb(238,238,238)">
<span class="" style="font-weight:bold">while</span> <span class="" style="font-weight:bold">(</span><span class="" style="font-weight:bold">true</span><span class="" style="font-weight:bold">)</span> <span class="" style="font-weight:bold">{</span>
    <span class="" style="color:rgb(0,128,128)">QueueingConsumer</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">Delivery</span> <span class="" style="color:rgb(0,128,128)">delivery</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(0,128,128)">consumer</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">nextDelivery</span><span class="" style="font-weight:bold">();</span>
    <span class="" style="color:rgb(0,128,128)">String</span> <span class="" style="color:rgb(0,128,128)">message</span> <span class="" style="font-weight:bold">=</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(0,128,128)">String</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(0,128,128)">delivery</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">getBody</span><span class="" style="font-weight:bold">());</span>
    <span class="" style="color:rgb(0,128,128)">System</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">out</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">println</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">" [x] Received '"</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(0,128,128)">message</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(221,17,68)">"'"</span><span class="" style="font-weight:bold">);</span>       
<span class="" style="font-weight:bold">}</span></pre></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">nothing special...</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br>
</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">And the behavior I get is the following: </span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">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.</span></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">So, it seems like priority works only on some static queues without constantly working Consumer and Producer.</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:14px">Am I right?</span></div>
<div><font color="#000000" face="arial, sans-serif">Maybe I am doing something wrong?</font></div><div><font color="#000000" face="arial, sans-serif">Can you please give some complex example for using the priority-queue plugin?</font></div>
<div><font color="#000000" face="arial, sans-serif">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?</font></div>
<div><span style="color:rgb(0,0,0);font-family:arial,sans-serif"> </span><br></div><div><font color="#000000" face="arial, sans-serif">Thank you,</font></div><div><font color="#000000" face="arial, sans-serif">Nik</font></div>
</div>