List of usage examples for com.rabbitmq.client ConnectionFactory ConnectionFactory
ConnectionFactory
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 a v 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.headstrong.fusion.connector.amqp.AMQPProducer.java
License:Open Source License
public void start() throws Exception { if (this.connection == null || !this.connection.isOpen()) { this.connection = new ConnectionFactory().newConnection( this.amqpEndpoint.getAmqpBinding().getHostName(), this.amqpEndpoint.getAmqpBinding().getPortNumber()); }/* www .ja v a2s .c o m*/ if (this.channel == null || !this.channel.isOpen()) { this.channel = this.connection.createChannel(); String exchange = this.amqpEndpoint.getAmqpBinding().getExchange(); if (exchange != null && !"".equals(exchange)) { this.channel.exchangeDeclare(exchange, "direct"); } this.channel.queueDeclare(this.amqpEndpoint.getAmqpBinding().getRoutingKey()); } }
From source file:com.hopped.runner.rabbitmq.RPCClient.java
License:Open Source License
/** * @param requestQueueName/*w w w . j av a 2s .com*/ * @throws Exception */ public RPCClient(String requestQueueName) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); this.requestQueueName = requestQueueName; connection = factory.newConnection(); channel = connection.createChannel(); replyQueueName = channel.queueDeclare().getQueue(); consumer = new QueueingConsumer(channel); channel.basicConsume(replyQueueName, true, consumer); }
From source file:com.hopped.running.demo.Demo.java
License:Open Source License
public static void main(final String... strings) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); AuthRequest request = AuthRequest.newBuilder().setUsername("hopped").build(); RunnerClient client = new RunnerClient(factory, "runningRabbit").init(); IRunnerService service = (IRunnerService) client.createProxy(IRunnerService.class); AuthResponse res = service.login(request); System.out.println("Returned sessionId: " + res.getSessionId()); Ack ack = service.setProfile(User.newBuilder().setAlias("hopped").build()); System.out.println(ack.getSuccess()); }
From source file:com.hopped.running.demo.RunServer.java
License:Open Source License
/** * /*from www.ja va 2 s. c om*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); final String queueName = "runningRabbit"; Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.basicQos(1); channel.queueDeclare(queueName, false, false, false, null); ProtobufRPCServer server = new ProtobufRPCServer(channel, queueName).init() .setInstance(new RunnerServiceImpl()).setProtocol(IRunnerService.class); server.consume(); }
From source file:com.hp.ov.sdk.messaging.core.RabbitMqClientConnectionFactory.java
License:Apache License
public static ConnectionFactory getConnectionFactory(final SSLContext sslContext, final RestParams params) { final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(params.getHostname()); factory.setPort(params.getAmqpPort()); // Set Auth mechanism to "EXTERNAL" so that commonName of the client // certificate is mapped to AMQP user name. Hence, No need to set // userId/Password here. factory.setSaslConfig(DefaultSaslConfig.EXTERNAL); factory.useSslProtocol(sslContext);//from ww w .ja v a 2 s . co m factory.setAutomaticRecoveryEnabled(true); return factory; }
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.// ww w . j ava 2 s .c om */ 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);//from w w w. j a v a 2 s .c o 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.interop.webapp.WebApp.java
License:Apache License
@PostConstruct public void setUpQueue() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(config.getQueueHostName()); connection = factory.newConnection(); channel = connection.createChannel(); replyQueueName = channel.queueDeclare().getQueue(); consumer = new QueueingConsumer(channel); channel.basicConsume(replyQueueName, true, consumer); // Create the folder that will hold the processed files String foldername = config.getImageFilesRoot() + '/' + processedFilesWebPath; File folder = new File(URI.create(foldername)); if (folder.exists()) { return;/*from w w w . j a va2 s . co m*/ } log.info("creating directory: " + foldername); try { folder.mkdir(); } catch (SecurityException se) { log.error(String.format("creating directory: %s (%s)", foldername, se.getMessage())); } catch (Exception e) { log.error(String.format("creating directory: %s (%s)", foldername, e.getMessage())); } }
From source file:com.jarova.mqtt.RabbitMQ.java
public void fixConnection() { try {// w w w . j a v a 2 s. co m ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(USER_NAME); factory.setPassword(PASSWORD); factory.setHost(HOST_NAME); //adicionado para que a conexao seja recuperada em caso de falha de rede; factory.setAutomaticRecoveryEnabled(true); Connection connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(QUEUE, true, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); } catch (IOException ex) { Logger.getLogger(RabbitMQ.class.getName()).log(Level.SEVERE, null, ex); } catch (TimeoutException ex) { Logger.getLogger(RabbitMQ.class.getName()).log(Level.SEVERE, null, ex); } }