RabbitMQ Message Priority Queue Not working -


i run priority queue java program in eclipse, got issue, first time got correct answer. time added 1 more message in queue, time got different result.

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_update, true, false, false, args);           publish(ch, 141);             publish(ch, 250);             final countdownlatch latch = new countdownlatch(2);         ch.basicconsume(queue_update, true, new defaultconsumer(ch) {             public void handledelivery(string consumertag, envelope envelope, basicproperties properties, byte[] body) throws ioexception {                 system.out.println("received " + new string(body));                 latch.countdown();             }         });          latch.await();         conn.close();                    system.out.println("finished"); }  private static void publish(channel ch, int priority) throws exception {      basicproperties props = messageproperties.persistent_basic.builder().priority(priority).build();      string body = queue_update + " message priority " + priority ;      ch.basicpublish("", queue_update, props, body.getbytes());          } 

correct output:

received update-queue message priority 250 received update-queue message priority 141 finished 

added 1 more queue message

         publish(ch, 141);              publish(ch, 250);             publish(ch, 110); // newly added 

expected output

received update-queue message priority 250 received update-queue message priority 141 received update-queue message priority 110 finished 

actual output

received update-queue message priority 141 received update-queue message priority 250 received update-queue message priority 110 finished 

how came this? did wrong?

i ran same problem. worked me defining limit defined consumer prefetch, example channel.basicqos(1);. if don't set limit messages delivered consumers arrive @ broker, never sorted using priority.

when set low limit broker won't send more messages limit @ time, sorting messages before delivery.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -