Created
December 9, 2014 16:57
-
-
Save raj-rajaratnam/55f48fd27e77232db6be 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 org.wso2.esb.rabbitmq; | |
import java.io.IOException; | |
import com.rabbitmq.client.*; | |
public class RPCReceiver { | |
static String queue = "callback-queue"; | |
static String exchange = "callback-exchange"; | |
static String host = "localhost"; | |
static String username = "guest"; | |
static String password = "guest"; | |
static int port = 5672; | |
public static void main(String[] args) throws IOException, | |
ShutdownSignalException, ConsumerCancelledException, | |
InterruptedException { | |
ConnectionFactory factory = new ConnectionFactory(); | |
factory.setHost(host); | |
factory.setUsername(username); | |
factory.setPassword(password); | |
factory.setPort(port); | |
Connection connection = factory.newConnection(); | |
Channel channel = connection.createChannel(); | |
channel.queueDeclare(queue, false, false, false, null); | |
channel.exchangeDeclare(exchange, "direct", true); | |
channel.queueBind(queue, exchange, ""); | |
// Create the consumer | |
QueueingConsumer consumer = new QueueingConsumer(channel); | |
channel.basicConsume(queue, true, consumer); | |
// Start consuming messages | |
while (true) { | |
QueueingConsumer.Delivery delivery = consumer.nextDelivery(); | |
BasicProperties props = delivery.getProperties(); | |
String message = new String(delivery.getBody()); | |
System.out.println("Message received"); | |
System.out.println(message); | |
System.out.println("Correlation id : " + props.getCorrelationId()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment