Last active
December 13, 2015 16:49
-
-
Save rinrinne/4943092 to your computer and use it in GitHub Desktop.
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
package com.sonymobile.swe.app.amqpget; | |
import java.io.IOException; | |
import com.rabbitmq.client.*; | |
import com.rabbitmq.client.AMQP.BasicProperties; | |
public class App | |
{ | |
public static void main( String[] args ) | |
{ | |
ConnectionFactory factory = null; | |
Connection conn = null; | |
try { | |
factory = new ConnectionFactory(); | |
factory.setUri("amqp://localhost"); | |
conn = factory.newConnection(); | |
final Channel channel = conn.createChannel(); | |
String queueName = "gerouter-rcv"; | |
String exchangeName = "gerrit.event"; | |
String routingKey = "gerrit.event.*"; | |
String consumerTag = "rabbitmq-client"; | |
channel.queueDeclare(queueName, true, false, false, null); | |
channel.queueBind(queueName, exchangeName, routingKey); | |
channel.basicConsume(queueName, false, consumerTag, | |
new DefaultConsumer(channel) { | |
@Override | |
public void handleDelivery(String consumerTag, | |
Envelope envelope, BasicProperties properties, | |
byte[] body) throws IOException { | |
// TODO Auto-generated method stub | |
super.handleDelivery(consumerTag, envelope, properties, body); | |
String routingKey = envelope.getRoutingKey(); | |
long deliveryTag = envelope.getDeliveryTag(); | |
String eventBody = new String(body, "UTF-8"); | |
System.out.println("Received: [" + routingKey + "] " + eventBody); | |
channel.basicAck(deliveryTag, false); | |
} | |
}); | |
System.out.println("Consume mode"); | |
} catch(Exception e) { | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment