Skip to content

Instantly share code, notes, and snippets.

@debraj-manna
Created November 22, 2015 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debraj-manna/212ddc1657a290ac516b to your computer and use it in GitHub Desktop.
Save debraj-manna/212ddc1657a290ac516b to your computer and use it in GitHub Desktop.
Reading Priotised Messages from RabbitMq priority queue
//Refer https://gist.github.com/debraj-manna/c470073496ddff1f26e4 for the Sending message to RabbitMq code.
package helloWorld;
import com.rabbitmq.client.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class Recv {
private final static String QUEUE_NAME = "hello_priority";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-priority", 10);
channel.queueDeclare(QUEUE_NAME, true, false, false, args);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "' with type " + properties.getType());
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment