[rabbitmq-discuss] priority of the messages

Yurisleidy Hernández Moya ymoya at uci.cu
Thu Jan 26 16:26:57 GMT 2012


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. 





Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
http://www.antiterroristas.cu
http://justiciaparaloscinco.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120126/00d22603/attachment.htm>


More information about the rabbitmq-discuss mailing list