[rabbitmq-discuss] priority of the messages

Jerry Kuch jerryk at vmware.com
Thu Jan 26 16:53:34 GMT 2012


Hi, Yuri:

Rabbit doesn't currently implement priorities, but you might consider an
approach like the following, which some people have found helpful:

http://dougbarth.github.com/2011/07/01/approximating-priority-with-rabbitmq.html

Best regards,
Jerry

----- Original Message -----
From: "Yurisleidy Hernández Moya" <ymoya at uci.cu>
To: rabbitmq-discuss at lists.rabbitmq.com
Sent: Thursday, January 26, 2012 8:26:57 AM
Subject: [rabbitmq-discuss] priority of the messages



Hello
i'm new in rabbitmq. can i to send messages with a specific priority of the producer for the consumer?

that is, if the queue has more than one message, the consumer must first receive the message that has the highest priority

we tested the property of the message "priority" but i not obtained a good result. i send my code.

Producer.java
public class Producer {

private static final String TASK_QUEUE_NAME = "task_queue";

public static void main(String[] argv)
throws java.io.IOException {

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
boolean durable = true;
channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false, null);
BasicProperties props = new BasicProperties.Builder().priority(0).build();

String message;

for (int i = 0; i < 3; i++) {
message = "cerooo";

channel.basicPublish("", TASK_QUEUE_NAME, props, message.getBytes());

System.out.println(" [x] Sent '" + message + "'");
}
channel.close();
connection.close();
}
}

Consumer.java
public class Consumer {

private static final String TASK_QUEUE_NAME = "task_queue";

public static void main(String[] argv)
throws java.io.IOException,
java.lang.InterruptedException {

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

channel.basicQos(1);

QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(TASK_QUEUE_NAME, false, consumer);

while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());

System.out.println(" [x] Received '" + message + "'");
Thread.sleep(2000);
System.out.println(" [x] Done");

channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
}
}


Any ideas how I can do this?

thanks in advance.



Saludos,
Yuri.





_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list