List of usage examples for com.rabbitmq.client Channel exchangeDeclare
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type) throws IOException;
From source file:v2.APAdmin.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "topic"); String queueName = channel.queueDeclare().getQueue(); String bindingKey = "AP.*"; channel.queueBind(queueName, EXCHANGE_NAME, bindingKey); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override//from w w w. jav a 2 s . com 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 '" + envelope.getRoutingKey() + "':'" + message + "'"); //REPLY HERE String response = "You are in, breh"; BasicProperties replyProps = new BasicProperties.Builder() .correlationId(properties.getCorrelationId()).build(); channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes()); } }; channel.basicConsume(queueName, true, consumer); }
From source file:v2.PBAAdmin.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "topic"); String queueName = channel.queueDeclare().getQueue(); String bindingKey = "PBA.*"; channel.queueBind(queueName, EXCHANGE_NAME, bindingKey); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override/*w w w.j a v a2s .c o m*/ 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 '" + envelope.getRoutingKey() + "':'" + message + "'"); } }; channel.basicConsume(queueName, true, consumer); }
From source file:v2.Student.java
public static void main(String[] argv) { Connection connection = null; Channel channel = null; try {/*from w w w . ja v a 2 s . c o m*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); connection = factory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "topic"); String routingKey = "AP.DAT";//getRouting(argv); String message = "Plz enroll me, breh";//getMessage(argv); String corrId = java.util.UUID.randomUUID().toString(); String callbackQueueName = channel.queueDeclare().getQueue(); String response = null; QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(callbackQueueName, true, consumer); BasicProperties props = new BasicProperties.Builder().replyTo(callbackQueueName).build(); channel.basicPublish(EXCHANGE_NAME, routingKey, props, message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + routingKey + "':'" + message + "'"); while (true) { System.out.println("blocked?"); QueueingConsumer.Delivery delivery = consumer.nextDelivery(); System.out.println("unblocked"); System.out.println(delivery); response = new String(delivery.getBody()); System.out.println(response); // if (delivery.getProperties().getCorrelationId().equals(corrId)) { // response = new String(delivery.getBody()); // System.out.println(response); // break; // } } } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (Exception ignore) { } } } }
From source file:vn.com.uet.performance.rabbitmq.MulticastParams.java
License:Open Source License
public Producer createProducer(Connection connection, Stats stats, String id) throws IOException { Channel channel = connection.createChannel(); if (producerTxSize > 0) channel.txSelect();/*from w ww. j a v a 2 s. c o m*/ if (confirm >= 0) channel.confirmSelect(); if (!predeclared || !exchangeExists(connection, exchangeName)) { channel.exchangeDeclare(exchangeName, exchangeType); } final Producer producer = new Producer(channel, exchangeName, id, randomRoutingKey, flags, producerTxSize, producerRateLimit, producerMsgCount, minMsgSize, timeLimit, confirm, stats); channel.addReturnListener(producer); channel.addConfirmListener(producer); return producer; }
From source file:vn.com.uet.performance.rabbitmq.MulticastParams.java
License:Open Source License
public String configureQueue(Connection connection, String id) throws IOException { Channel channel = connection.createChannel(); if (!predeclared || !exchangeExists(connection, exchangeName)) { channel.exchangeDeclare(exchangeName, exchangeType); }/*from ww w . j ava2 s. c o m*/ String qName = queueName; if (!predeclared || !queueExists(connection, queueName)) { qName = channel.queueDeclare(queueName, flags.contains("persistent"), false, autoDelete, null) .getQueue(); } channel.queueBind(qName, exchangeName, id); channel.abort(); return qName; }