List of usage examples for com.rabbitmq.client Channel exchangeDeclare
Exchange.DeclareOk exchangeDeclare(String exchange, BuiltinExchangeType type) throws IOException;
From source file:com.insa.tp3g1.esbsimulator.view.MessageHandler.java
public static String sendConfig1(String who, String config) throws Exception { /* calling connectionFactory to create a custome connexion with * rabbitMQ server information./* w w w. j a v a 2 s . co m*/ */ ConnectionFactory factory = new ConnectionFactory(); factory.setHost("146.148.27.98"); factory.setUsername("admin"); factory.setPassword("adminadmin"); factory.setPort(5672); System.out.println("connection ok"); // establish the connection with RabbitMQ server using our factory. Connection connection = factory.newConnection(); // System.out.println("connection ok1"); // We're connected now, to the broker on the cloud machine. // If we wanted to connect to a broker on a the local machine we'd simply specify "localhost" as IP adresse. // creating a "configuration" direct channel/queue Channel channel = connection.createChannel(); // System.out.println("connection ok2"); channel.exchangeDeclare(EXCHANGE_NAME, "direct"); // System.out.println("exchangeDeclare"); // the message and the distination String forWho = who; String message = config; // publish the message channel.basicPublish(EXCHANGE_NAME, forWho, null, message.getBytes()); // System.out.println("basicPublish"); // close the queue and the connexion channel.close(); connection.close(); return " [x] Sent '" + forWho + "':'" + message + "'"; }
From source file:com.insa.tp3g1.esbsimulator.view.MessageHandler.java
public static void logGetter() throws java.io.IOException { ConnectionFactory factory = new ConnectionFactory(); LogHandler logHandler = new LogHandler(); factory.setHost("146.148.27.98"); factory.setUsername("admin"); factory.setPassword("adminadmin"); factory.setPort(5672);/* w ww . ja v a2 s. co m*/ Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(LOG_NAME, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, LOG_NAME, ""); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); count = 0; boolean over = false; while (!over) { QueueingConsumer.Delivery delivery = null; try { delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); //System.out.println(" [x] Received '" + message + "'"); synchronized (count) { count++; } logHandler.add(message); System.out.print(Thread.currentThread().getId() + " "); } catch (InterruptedException interruptedException) { System.out.println("finished"); System.out.println(logHandler); System.out.println(logHandler); Thread.currentThread().interrupt(); System.out.println(Thread.currentThread().getId() + " "); break; // Thread.currentThread().stop(); // over = true; } catch (ShutdownSignalException shutdownSignalException) { System.out.println("finished"); // Thread.currentThread().stop(); over = true; } catch (ConsumerCancelledException consumerCancelledException) { System.out.println("finished"); // Thread.currentThread().stop(); over = true; } catch (IllegalMonitorStateException e) { System.out.println("finished"); // Thread.currentThread().stop(); over = true; } } System.out.println("before close"); channel.close(); connection.close(); System.out.println("finished handling"); Result res = logHandler.fillInResultForm(logHandler.getTheLog()); ResultHandler resH = new ResultHandler(res); resH.createResultFile("/home/alpha/alphaalpha.xml"); final OverlaidBarChart demo = new OverlaidBarChart("Response Time Chart", res); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); int lost = Integer.parseInt(res.getTotalResult().getLostRequests()) / logHandler.getNbRequests(); PieChart demo1 = new PieChart("Messages", lost * 100); demo1.pack(); demo1.setVisible(true); //System.out.println(logHandler); }
From source file:com.loanbroker.old.JSONReceiveTest.java
public static void main(String[] argv) throws IOException, InterruptedException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = "Kender du hende der Arne"; channel.queueDeclare(queueName, false, false, false, null); channel.queueBind(queueName, EXCHANGE_NAME, ""); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String messageIn = new String(delivery.getBody()); System.out.println(" [x] Received by tester: '" + messageIn + "'"); }//from ww w. j a v a 2 s . c o m }
From source file:com.loanbroker.old.JSONSendTest.java
public static void main(String[] argv) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); factory.setUsername("student"); factory.setPassword("cph"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = "Kender du hende der Arne"; channel.queueDeclare(queueName, false, false, false, null); channel.queueBind(queueName, EXCHANGE_NAME, ""); String messageOut = "{\"ssn\":1605789787,\"creditScore\":699,\"loanAmount\":10.0,\"loanDuration\":360}"; BasicProperties.Builder props = new BasicProperties().builder(); props.replyTo(""); BasicProperties bp = props.build();//from ww w . j ava 2s.c o m channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes()); System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'"); channel.close(); connection.close(); }
From source file:com.mycompany.bankjsontranslator.Translator.java
public static void main(String[] args) throws IOException { ConnectionFactory listeningFactory = new ConnectionFactory(); listeningFactory.setHost("datdb.cphbusiness.dk"); listeningFactory.setUsername("Dreamteam"); listeningFactory.setPassword("bastian"); ConnectionFactory sendingFactory = new ConnectionFactory(); sendingFactory.setHost("datdb.cphbusiness.dk"); sendingFactory.setUsername("Dreamteam"); sendingFactory.setPassword("bastian"); Connection listeningConnection = listeningFactory.newConnection(); Connection sendingConnection = sendingFactory.newConnection(); final Channel listeningChannel = listeningConnection.createChannel(); final Channel sendingChannel = sendingConnection.createChannel(); final BasicProperties props = new BasicProperties.Builder().replyTo(REPLY_TO_HEADER).build(); listeningChannel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null); listeningChannel.queueBind(LISTENING_QUEUE_NAME, EXCHANGE_NAME, "CphBusinessJSON"); listeningChannel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(listeningChannel) { @Override/*from w w w .j a v a2 s. c o m*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); String[] arr = message.split(","); int dashRemoved = Integer.parseInt(arr[0].replace("-", "")); Result res = new Result(dashRemoved, Integer.parseInt(arr[1]), Double.parseDouble(arr[2]), Integer.parseInt(arr[3])); String result = gson.toJson(res); System.out.println(result); sendingChannel.exchangeDeclare(SENDING_QUEUE_NAME, "fanout"); String test = sendingChannel.queueDeclare().getQueue(); sendingChannel.queueBind(test, SENDING_QUEUE_NAME, ""); sendingChannel.basicPublish(SENDING_QUEUE_NAME, "", props, result.getBytes()); } }; listeningChannel.basicConsume(LISTENING_QUEUE_NAME, true, consumer); }
From source file:com.mycompany.bankxmltranslator.Translator.java
public static void main(String[] args) throws IOException { ConnectionFactory listeningFactory = new ConnectionFactory(); listeningFactory.setHost("datdb.cphbusiness.dk"); listeningFactory.setUsername("Dreamteam"); listeningFactory.setPassword("bastian"); ConnectionFactory sendingFactory = new ConnectionFactory(); sendingFactory.setHost("datdb.cphbusiness.dk"); sendingFactory.setUsername("Dreamteam"); sendingFactory.setPassword("bastian"); Connection listeningConnection = listeningFactory.newConnection(); Connection sendingConnection = sendingFactory.newConnection(); final Channel listeningChannel = listeningConnection.createChannel(); final Channel sendingChannel = sendingConnection.createChannel(); listeningChannel.queueDeclare(LISTENING_QUEUE_NAME, false, false, false, null); listeningChannel.queueBind(LISTENING_QUEUE_NAME, EXCHANGE_NAME, "CphBusinessXML"); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(listeningChannel) { @Override//w w w .j ava 2 s .c o m public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { try { message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); String[] arr = message.split(","); // String ssnFix = arr[0].substring(2); String dashRemoved = arr[0].replace("-", ""); Result res = new Result(dashRemoved, Integer.parseInt(arr[1]), Double.parseDouble(arr[2]), theDateAdder(Integer.parseInt(arr[3]))); JAXBContext jaxbContext = JAXBContext.newInstance(Result.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); StringWriter sw = new StringWriter(); jaxbMarshaller.marshal(res, sw); String xmlString = sw.toString(); xmlString = xmlString.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", ""); System.out.println(xmlString); // HANDLE MESSAGE HERE sendingChannel.exchangeDeclare(SENDING_QUEUE_NAME, "fanout"); String test = sendingChannel.queueDeclare().getQueue(); sendingChannel.queueBind(test, SENDING_QUEUE_NAME, ""); sendingChannel.basicPublish("", SENDING_QUEUE_NAME, props, xmlString.getBytes()); } catch (JAXBException ex) { Logger.getLogger(Translator.class.getName()).log(Level.SEVERE, null, ex); } } }; listeningChannel.basicConsume(LISTENING_QUEUE_NAME, true, consumer); }
From source file:com.mycompany.javateste.queues.pubsub.EmitLog.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String message = getMessage(argv); channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + message + "'"); channel.close();/* w ww .jav a2 s .co m*/ connection.close(); }
From source file:com.mycompany.javateste.queues.pubsub.ReceiveLogs.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, EXCHANGE_NAME, ""); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override//from w w w .ja v a 2 s.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 '" + message + "'"); } }; channel.basicConsume(queueName, true, consumer); }
From source file:com.mycompany.javateste.queues.routing.EmitLogDirect.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "direct"); String severity = getSeverity(argv); String message = getMessage(argv); channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes("UTF-8")); System.out.println(" [x] Sent '" + severity + "':'" + message + "'"); channel.close();/*www . j ava 2 s . c o m*/ connection.close(); }
From source file:com.mycompany.javateste.queues.routing.ReceiveLogsDirect.java
public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "direct"); String queueName = channel.queueDeclare().getQueue(); if (argv.length < 1) { System.err.println("Usage: ReceiveLogsDirect [info] [warning] [error]"); System.exit(1);/*from ww w . j ava 2 s .com*/ } for (String severity : argv) { channel.queueBind(queueName, EXCHANGE_NAME, severity); } System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override 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); }