List of usage examples for com.rabbitmq.client Channel queueDeclare
Queue.DeclareOk queueDeclare() throws IOException;
From source file:Release1.Controllers.AlarmController.java
/** * mtodo para recibir mensajes de los sensores de alarmas de ventana * dependiendo del mensaje recibido se envia la respuesta a los sensores * @throws IOException//w ww . j a va 2s . c om * @throws TimeoutException */ private synchronized void receiveAlamrWindowSensorMessage() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(HOST); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(ID_CHANNEL_AWINDOW_SENSOR, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ID_CHANNEL_AWINDOW_SENSOR, ""); Consumer consumer; consumer = new DefaultConsumer(channel) { @Override public synchronized void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { setMessage(new String(body, "UTF-8")); logger.info("Class ALARM WINDOW Controller --- RECEIVED from Sensor --- Value: " + new String(body, "UTF-8")); if (Integer.parseInt(getMessage()) > MAX_VALUE_ALARMS) {//si el valor obtenido es mayor al permitido para simular las alarmas se activa la alarma try { sendMessage(ID_CHANNEL_AWINDOW_CONTROLLER, ID_AWINDOW_ON);//envio de mensaje para encender alarma la alarma de ventnaa logger.info("Class: ALARM CONTROLLER --- SEND --- ACTIVE ALARM WINDOW"); } catch (TimeoutException ex) { logger.error(ex); } } else { try { sendMessage(ID_CHANNEL_AWINDOW_CONTROLLER, ID_AWINDOW_OFF);//envio de mensaje apra apagar la alarma de ventana } catch (TimeoutException ex) { logger.error(ex); } } } }; channel.basicConsume(queueName, true, consumer); }
From source file:Release1.Controllers.AlarmController.java
/** * mtodo para recibir mensajes de los sensores de alarmas de puerta * dependiendo del mensaje recibido se envia la respuesta a los sensores * @throws IOException/* w w w . j a va 2s . c o m*/ * @throws TimeoutException */ private void receiveAlarmDoorMessage() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(HOST); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(ID_CHANNEL_ADOOR_SENSOR, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ID_CHANNEL_ADOOR_SENSOR, ""); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { setMessage(new String(body, "UTF-8")); logger.info("Class Alarm DOOR Controller --- RECEIVED from Sensor --- Value: " + new String(body, "UTF-8")); if (Integer.parseInt(getMessage()) > MAX_VALUE_ALARMS) { try { sendMessage(ID_CHANNEL_ADOOR_CONTROLLER, ID_ADOOR_ON);//envio de mensaje para encender la alarma } catch (TimeoutException ex) { logger.error(ex); } } else { try { sendMessage(ID_CHANNEL_ADOOR_CONTROLLER, ID_ADOOR_OFF);//envio de mensajes para apagar la alarma } catch (TimeoutException ex) { logger.error(ex); } } } }; channel.basicConsume(queueName, true, consumer); }
From source file:Release1.Controllers.AlarmController.java
/** * * mtodo para recibir mensajes de los sensores de alarmas de movimiento * dependiendo del mensaje recibido se envia la respuesta a los sensores * @throws IOException/*from ww w .j a v a 2 s. co m*/ * @throws TimeoutException */ private void receiveMoveMessage() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(HOST); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(ID_CHANNEL_AMOVE_SENSOR, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ID_CHANNEL_AMOVE_SENSOR, ""); Consumer consumer; consumer = new DefaultConsumer(channel) { @Override public synchronized void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { setMessage(new String(body, "UTF-8")); logger.info("Class ALARM MOVE Controller --- RECEIVED from Sensor --- Value: " + new String(body, "UTF-8")); if (Integer.parseInt(getMessage()) > MAX_VALUE_ALARMS) { try { sendMessage(ID_CHANNEL_AMOVE_CONTROLLER, ID_AMOVE_ON);//envio de mensajes para encender la alarma de movimiento logger.info("Class: ALARM CONTROLLER --- SEND --- ACTIVE ALARM WINDOW"); } catch (TimeoutException ex) { logger.error(ex); } } else { try { sendMessage(ID_CHANNEL_AMOVE_CONTROLLER, ID_AMOVE_OFF);//envio de mensajes para apagar la alarma de movimientos } catch (TimeoutException ex) { logger.error(ex); } } } }; channel.basicConsume(queueName, true, consumer); }
From source file:Release2.Controllers.AlarmFireController.java
private synchronized void receivedAlarmFireSensorMessage() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(HOST);/*from ww w . jav a 2s . c o m*/ Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(ID_CHANNEL_AFIRE_SENSOR, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ID_CHANNEL_AFIRE_SENSOR, ""); Consumer consumer; consumer = new DefaultConsumer(channel) { @Override public synchronized void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { setMessage(new String(body, "UTF-8")); logger.info("Class ALARM FIRE Controller --- RECEIVED from Sensor --- Value: " + new String(body, "UTF-8")); if (Integer.parseInt(getMessage()) > MAX_VALUE_ALARMS) {//si el valor obtenido es mayor al permitido para simular las alarmas se activa la alarma try { sendMessage(ID_CHANNEL_AFIRE_CONTROLLER, ID_AFIRE_ON);//envio de mensaje para encender alarma la alarma de ventnaa logger.info("Class: ALARM CONTROLLER --- SEND --- ACTIVE ALARM WINDOW"); } catch (TimeoutException ex) { logger.error(ex); } } else { try { sendMessage(ID_CHANNEL_AFIRE_CONTROLLER, ID_AFIRE_OFF);//envio de mensaje apra apagar la alarma de ventana } catch (TimeoutException ex) { logger.error(ex); } } } }; channel.basicConsume(queueName, true, consumer); }
From source file:scratchpad.SimpleConsumer.java
License:Mozilla Public License
public static void main(String[] args) { try {//from w w w.jav a 2 s . c o m String hostName = (args.length > 0) ? args[0] : "localhost"; int portNumber = (args.length > 1) ? Integer.parseInt(args[1]) : AMQP.PROTOCOL.PORT; String queueName = (args.length > 2) ? args[2] : "eventName"; ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setHost(hostName); connFactory.setPort(portNumber); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); ch.queueDeclare(); QueueingConsumer consumer = new QueueingConsumer(ch); ch.basicConsume(queueName, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); Envelope envelope = delivery.getEnvelope(); System.out .println("Routing Key: " + envelope.getRoutingKey() + ":" + new String(delivery.getBody())); ch.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }
From source file:se.kodiak.logging.appenders.util.MQListener.java
License:Open Source License
public MQListener() { try {/*from w w w . j ava2 s . co m*/ ConnectionFactory factory = new ConnectionFactory(); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.basicQos(1); channel.exchangeDeclare("test", "topic"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, "test", "log.*"); consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:translators.ToJsonSchool.java
public static void main(String[] args) throws Exception { final String replyQueueName = "teachersJsonReply"; final String EXCHANGE_NAME_SCHOOL = "cphbusiness.bankJSON"; final String exchangeName = ExchangeName.GLOBAL; RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "keyBankJSON"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override/*from ww w . j a v a 2s .co 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("Received msg: " + message); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToOurJsonBank.java
public static void main(String[] args) throws Exception { RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(ExchangeName.GLOBAL, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ExchangeName.GLOBAL, RoutingKeys.OUR_JSON_BANK); QueueingConsumer consumer = new QueueingConsumer(channel) { @Override/*from w w w. jav a 2 s . c om*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println("Received msg: " + message); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), ExchangeName.OUTPUT_TRANSLATOR_TO_OUR_JSON_BANK, REPLY_QUEUE_NAME); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToOurXmlBank.java
public static void main(String[] args) throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "ourBankSoapXML"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override// w w w .ja va 2 s. co m public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); Message messageFromJson = getFromJson(message); connectToWebService(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }
From source file:translators.ToXmlSchool.java
public static void main(String[] args) throws IOException { //final String replyQueueName = "replyFromBanks"; final String replyQueueName = "teachersXmlReply"; final String EXCHANGE_NAME_SCHOOL = "cphbusiness.bankXML"; final String exchangeName = ExchangeName.GLOBAL; RabbitConnection rabbitConnection = new RabbitConnection(); Channel channel = rabbitConnection.makeConnection(); channel.exchangeDeclare(exchangeName, "direct"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchangeName, "keyBankXML"); //get banks from queue. "Get banks" component QueueingConsumer consumer = new QueueingConsumer(channel) { @Override/* w ww.ja va2s.c o m*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); Message messageFromJson = getFromJson(message); sendMsgToBank(messageFromJson, properties.getCorrelationId(), EXCHANGE_NAME_SCHOOL, replyQueueName); } }; channel.basicConsume(queueName, true, consumer); }