Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// Establish the REQ/REP wiring.
String queueName = channel.queueDeclare().getQueue();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, true, consumer);
// Send the request
AMQP.BasicProperties properties = new AMQP.BasicProperties();
properties.setReplyTo(queueName);
channel.basicPublish("", "REQREP", properties,
"Hello!".getBytes());
// Get and print the reply
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String reply = new String(delivery.getBody());
System.out.println(reply);
connection.close();