List of usage examples for com.rabbitmq.client Channel queueBind
Queue.BindOk queueBind(String queue, String exchange, String routingKey) throws IOException;
From source file:com.github.dann.wspusher.pubsub.subscriber.impl.RabbitMQSubscriberImpl.java
License:Apache License
@Override public void subscribe(String exchange, DataPusherWebSocket webSocket) { Connection connection = null; Channel channel = null; try {//from w w w. jav a 2s .c o m // FIXME Cache connection! ConnectionFactory factory = new ConnectionFactory(); connection = factory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare(exchange, DEFAULT_EXCHANGE_TYPE); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, exchange, ""); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); doWork(consumer, webSocket); } catch (Exception e) { logger.error("Error occured", e); throw new WsRuntimeException(e); } finally { RabbitMQResourceUtils.closeQuietly(channel); RabbitMQResourceUtils.closeQuietly(connection); } }
From source file:com.github.kislayverma.dredd.action.async.amqp.AmqpActionQueue.java
License:Apache License
public AmqpActionQueue(ConnectionFactory factory, String queue, String exchange, String routingKey) throws IOException, TimeoutException { this.factory = factory; this.queue = queue; this.exchange = exchange; this.routingKey = routingKey; Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(exchange, "direct", true); channel.queueDeclare(queue, true, false, false, null); channel.queueBind(queue, exchange, routingKey); }
From source file:com.groupx.recipientlist.test.TranslatorMock.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 X+ENTER"); Consumer consumer = new DefaultConsumer(channel) { @Override//from w ww . j av a2 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); try { Scanner in = new Scanner(System.in); String input = in.next(); if ("x".equals(input)) { System.exit(0); } } catch (Exception e) { } }
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);//from ww w .j a va 2 s . c om 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.jbrisbin.vcloud.cache.RabbitMQAsyncCacheProvider.java
License:Apache License
@Override public void start() { active.set(true);// ww w . jav a 2 s.c om try { Channel channel = getConnection().createChannel(); channel.exchangeDeclare(objectRequestExchange, "topic", true, false, null); channel.queueDeclare(cacheNodeQueueName, true, false, true, null); channel.queueBind(cacheNodeQueueName, objectRequestExchange, "#"); channel.exchangeDeclare(heartbeatExchange, "fanout", true, false, null); } catch (IOException e) { log.error(e.getMessage(), e); } activeTasks.add(workerPool.submit(new HeartbeatMonitor())); delayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { commandMessages.add(new CommandMessage("ping", heartbeatExchange, "")); } }, 0, heartbeatInterval); delayTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { numOfPeers.set(peers.size()); if (debug) { log.debug("Expecting responses from " + numOfPeers.get() + " peers."); } } }, heartbeatInterval, heartbeatInterval); for (int i = 0; i < maxWorkers; i++) { activeTasks.add(workerPool.submit(new ObjectSender())); activeTasks.add(workerPool.submit(new CommandSender())); workerPool.submit(new Runnable() { @Override public void run() { try { Channel channel = getConnection().createChannel(); ObjectMonitor monitor = new ObjectMonitor(channel); channel.basicConsume(cacheNodeQueueName, monitor); } catch (IOException e) { log.error(e.getMessage(), e); } } }); } }
From source file:com.jbrisbin.vcloud.classloader.RabbitMQResourceProvider.java
License:Apache License
protected void declareResources() throws IOException { Channel mq = getChannel(); synchronized (mq) { mq.exchangeDeclare(exchange, "topic", true, false, null); if (null == this.queue) { queue = mq.queueDeclare().getQueue(); } else {//from w ww . j av a 2s .c om mq.queueDeclare(this.queue, true, false, true, null); } mq.queueBind(queue, exchange, routingKey); } }
From source file:com.jbrisbin.vcloud.session.CloudStore.java
License:Apache License
/** * @param session//from ww w. j a v a 2s . co m * @throws IOException */ public void save(Session session) throws IOException { String id = session.getId(); if (sessions.add(id)) { // This is a new session. String qname = String.format(sessionEventsQueuePattern, id); Channel channel = getMqChannel(); synchronized (channel) { channel.queueBind(sourceEventsQueue, sessionEventsExchange, qname); } sendEvent("touch", id.getBytes()); replicateSession(session); } localSessions.put(id, (CloudSession) session); }
From source file:com.jbrisbin.vcloud.session.CloudStore.java
License:Apache License
protected void restartListeners() throws IOException { Channel channel = getMqChannel(); synchronized (channel) { for (String id : localSessions.keySet()) { String qname = String.format(sessionEventsQueuePattern, id); channel.queueBind(sourceEventsQueue, sessionEventsExchange, qname); }/*from ww w. j a v a2 s. c om*/ } }
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 + "'"); }// w ww . j a va2 s . co 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 a v a 2 s .c om channel.basicPublish(EXCHANGE_NAME, "", bp, messageOut.getBytes()); System.out.println(" [x] Sent by JSONtester: '" + messageOut + "'"); channel.close(); connection.close(); }