List of usage examples for com.rabbitmq.client Channel exchangeDeclare
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type, boolean durable, boolean autoDelete, Map<String, Object> arguments) throws IOException;
From source file:uk.org.openeyes.oink.proxy.test.support.RabbitServer.java
License:Open Source License
@Override public void run() { try {/*from w w w. jav a 2 s.c o m*/ log.info("RabbitServer started"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchange, "direct", true, true, null); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchange, routingKey); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (!stop) { // Wait for RabbitQueue delivery QueueingConsumer.Delivery delivery = consumer.nextDelivery(1000); if (delivery != null) { log.info("Message received"); receivedMessage = delivery.getBody(); stop = true; } } if (receivedMessage == null) { log.warn("RabbitServer stopping before any message was received"); } } catch (Exception e) { log.error("RabbitServer threw an exception:" + e); e.printStackTrace(); } }