<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'>Hello<br>i'm new in rabbitmq. can i to send messages with a specific priority of the producer for the consumer? <br><br>that is, if the queue has more than one message, the consumer must first receive the message that has the highest priority<br><br>we tested the property of the message "priority" but i not obtained a good result. i send my code. <br><br>Producer.java<br>public class Producer {<br><br> private static final String TASK_QUEUE_NAME = "task_queue";<br><br> public static void main(String[] argv)<br> throws java.io.IOException {<br><br> ConnectionFactory factory = new ConnectionFactory();<br> factory.setHost("localhost");<br> Connection connection = factory.newConnection();<br> Channel channel = connection.createChannel();<br> boolean durable = true;<br> channel.queueDeclare(TASK_QUEUE_NAME, durable, false, false, null);<br> BasicProperties props = new BasicProperties.Builder().priority(0).build();<br><br> String message;<br><br> for (int i = 0; i < 3; i++) {<br> message = "cerooo";<br><br> channel.basicPublish("", TASK_QUEUE_NAME, props, message.getBytes());<br><br> System.out.println(" [x] Sent '" + message + "'");<br> }<br> channel.close();<br> connection.close();<br> }<br>}<br><br>Consumer.java<br>public class Consumer {<br><br> private static final String TASK_QUEUE_NAME = "task_queue";<br><br> public static void main(String[] argv)<br> throws java.io.IOException,<br> java.lang.InterruptedException {<br><br> ConnectionFactory factory = new ConnectionFactory();<br> factory.setHost("localhost");<br> Connection connection = factory.newConnection();<br> Channel channel = connection.createChannel();<br><br> channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);<br> System.out.println(" [*] Waiting for messages. To exit press CTRL+C");<br><br> channel.basicQos(1);<br><br> QueueingConsumer consumer = new QueueingConsumer(channel);<br> channel.basicConsume(TASK_QUEUE_NAME, false, consumer);<br><br> while (true) {<br> QueueingConsumer.Delivery delivery = consumer.nextDelivery();<br> String message = new String(delivery.getBody());<br><br> System.out.println(" [x] Received '" + message + "'");<br> Thread.sleep(2000);<br> System.out.println(" [x] Done");<br><br> channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);<br> }<br> }<br>}<br><br><br>Any ideas how I can do this?<br><br>thanks in advance.<br><br><div><span name="x"></span><div>Saludos,<br>Yuri.<br><br><img src="/home/yuri/Escritorio/aa0qm2.gif"></div><span name="x"></span><br></div></div>
<br><html>
<body>
<a href="http://www.antiterroristas.cu/">
<img src="http://cincoheroes.uci.cu/cinco.gif" alft="Para mas informacion consultar \n
http://wwww.antiterroristas.cu y http://justiciaparaloscinco.wordpress.com" width="792" height="52" />
</body>
</html>
<br></body></html>