Created
November 22, 2015 12:05
-
-
Save debraj-manna/212ddc1657a290ac516b to your computer and use it in GitHub Desktop.
Reading Priotised Messages from RabbitMq priority queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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