List of usage examples for com.rabbitmq.client ConnectionFactory setHost
public void setHost(String host)
From source file:org.mazerunner.core.messaging.Worker.java
License:Apache License
public void doMain(String[] args) throws Exception { CmdLineParser parser = new CmdLineParser(this); // if you have a wider console, you could increase the value; // here 80 is also the default parser.setUsageWidth(80);// ww w . j a v a 2 s.c o m try { // parse the arguments. parser.parseArgument(args); if (sparkMaster == "" || hadoopHdfs == "") throw new CmdLineException(parser, "Options required: --hadoop.hdfs <url>, --spark.master <url>"); ConfigurationLoader.getInstance().setHadoopHdfsUri(hadoopHdfs); ConfigurationLoader.getInstance().setSparkHost(sparkMaster); ConfigurationLoader.getInstance().setAppName(sparkAppName); ConfigurationLoader.getInstance().setExecutorMemory(sparkExecutorMemory); ConfigurationLoader.getInstance().setDriverHost(driverHost); ConfigurationLoader.getInstance().setRabbitmqNodename(rabbitMqHost); } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); System.err.println("java -cp $CLASSPATH [<spark-config-options>] <main-class> [<mazerunner-args>]"); // print the list of available options parser.printUsage(System.err); System.err.println(); // print option sample. This is useful some time System.err.println(" Example: java -cp $CLASSPATH org.mazerunner.core.messaging.Worker" + parser.printExample(ALL)); return; } ConnectionFactory factory = new ConnectionFactory(); factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); channel.basicQos(20); // Initialize spark context GraphProcessor.initializeSparkContext(); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(TASK_QUEUE_NAME, false, consumer); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); System.out.println(" [x] Received '" + message + "'"); // Deserialize message Gson gson = new Gson(); ProcessorMessage processorMessage = gson.fromJson(message, ProcessorMessage.class); // Run PageRank GraphProcessor.processEdgeList(processorMessage); System.out.println(" [x] Done '" + message + "'"); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } }
From source file:org.mule.transport.amqp.harness.TestConnectionManager.java
License:Open Source License
public Connection getConnection() throws IOException { if (connection != null && connection.isOpen()) { return connection; }// w ww . j a v a 2 s. c om ConnectionFactory factory = new ConnectionFactory(); factory.setHost(System.getProperty("amqpHost")); factory.setPort(Integer.valueOf(System.getProperty("amqpPort"))); factory.setUsername(System.getProperty("amqpUserName")); factory.setPassword(System.getProperty("amqpPassword")); factory.setVirtualHost(System.getProperty("amqpVirtualHost")); connection = factory.newConnection(); return connection; }
From source file:org.mule.transport.rmq.RmqConnector.java
License:Open Source License
private ConnectionFactory createConnectionFactory() { ConnectionFactory factory = new ConnectionFactory(); //Construct the factory from the connector URI if available //else from the variables. if (connectorURI != null) { RmqConnectorParser rcp = new RmqConnectorParser(connectorURI); host = rcp.getHost();/*from ww w .j ava2s .co m*/ port = rcp.getPort(); vhost = rcp.getVhost(); username = rcp.getUsername(); password = rcp.getPassword(); } factory.setHost(host); factory.setPort(port); if (vhost != null) factory.setVirtualHost(vhost); if (password != null) factory.setPassword(password); if (username != null) factory.setUsername(username); return factory; }
From source file:org.ninjav.rabbitmq.SendTest.java
@Test public void canSendMessageToQueue() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); for (int i = 0; i < 1000000; i++) { String message = "Hello world " + i; channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); }//from w w w. j ava 2s.c o m channel.close(); connection.close(); }
From source file:org.ninjav.rabbitmq.TestReceive.java
@Test public void canReceiveMessageFromQueue() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); Consumer consumer;//from w w w.j ava2 s. c om consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { try { String message = new String(body, "UTF-8"); System.out.println("Message Received: " + message); } finally { channel.basicAck(envelope.getDeliveryTag(), false); } } }; boolean autoAck = false; channel.basicConsume(QUEUE_NAME, autoAck, consumer); try { Thread.sleep(100000); } catch (InterruptedException ex) { Logger.getLogger(TestReceive.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.nuxeo.rabbit.RabbitMQEventForwarder.java
License:Apache License
protected void produceRabbitMQMessage(Event event) throws RabbitMQException, IOException, TimeoutException { DocumentEventContext context = (DocumentEventContext) event.getContext(); DocumentModel doc = context.getSourceDocument(); if (!doc.hasSchema("file")) { return;/*from w ww.j a va 2 s . c o m*/ } if (connection == null) { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(Framework.getProperty(RABBITMQ_URL, "localhost")); connection = factory.newConnection(); } if (channel == null) { channel = connection.createChannel(); } channel.queueDeclare(QUEUE_NAME, false, false, false, null); channel.basicPublish("", QUEUE_NAME, null, message(event, doc).getBytes("UTF-8")); channel.close(); connection.close(); }
From source file:org.objectweb.proactive.extensions.amqp.remoteobject.ConnectionAndChannelFactory.java
License:Open Source License
private synchronized CachedConnection getConnection(AMQPConnectionParameters connectionParameters) throws IOException { String key = connectionParameters.getKey(); CachedConnection connection = cachedConnections.get(key); if (connection == null) { logger.debug(String.format("creating a new connection %s", key)); ConnectionFactory factory = new ConnectionFactory(); if (socketFactory != null) { factory.setSocketFactory(socketFactory); }/* w w w .jav a2 s .c om*/ factory.setHost(connectionParameters.getHost()); factory.setPort(connectionParameters.getPort()); factory.setUsername(connectionParameters.getUsername()); factory.setPassword(connectionParameters.getPassword()); factory.setVirtualHost(connectionParameters.getVhost()); Connection c = factory.newConnection(); c.addShutdownListener(new AMQPShutDownListener(c.toString())); connection = new CachedConnection(this, c); cachedConnections.put(key, connection); } return connection; }
From source file:org.openbaton.common.vnfm_sdk.amqp.AbstractVnfmSpringAmqp.java
License:Apache License
@Override protected void unregister() { try {/* ww w . ja va2 s . c om*/ ((VnfmSpringHelperRabbit) vnfmHelper).sendMessageToQueue(RabbitConfiguration.queueName_vnfmUnregister, vnfmManagerEndpoint); } catch (IllegalStateException e) { log.warn("Got exception while unregistering trying to do it manually"); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(rabbitHost); Connection connection = null; try { connection = factory.newConnection(); Channel channel = connection.createChannel(); String message = gson.toJson(vnfmManagerEndpoint); channel.basicPublish("openbaton-exchange", RabbitConfiguration.queueName_vnfmUnregister, MessageProperties.TEXT_PLAIN, message.getBytes("UTF-8")); log.debug("Sent '" + message + "'"); channel.close(); connection.close(); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:org.openbaton.plugin.PluginListener.java
License:Apache License
private void initRabbitMQ() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(brokerIp); factory.setPort(brokerPort);//w w w. j a v a2s . c o m factory.setPassword(password); factory.setUsername(username); factory.setVirtualHost(virtualHost); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(pluginId, this.durable, false, true, null); channel.queueBind(pluginId, exchange, pluginId); channel.basicQos(1); }
From source file:org.openbaton.plugin.utils.PluginCaller.java
License:Apache License
public PluginCaller(String pluginId, String brokerIp, String username, String password, int port, int managementPort) throws IOException, TimeoutException, NotFoundException { this.pluginId = getFullPluginId(pluginId, brokerIp, username, password, managementPort); this.managementPort = managementPort; this.brokerIp = brokerIp; this.username = username; this.password = password; ConnectionFactory factory = new ConnectionFactory(); factory.setHost(brokerIp); if (username != null) factory.setUsername(username);// ww w .j a va 2 s . com else factory.setUsername("admin"); if (password != null) factory.setPassword(password); else factory.setPassword("openbaton"); if (port > 1024) factory.setPort(port); else factory.setPort(5672); connection = factory.newConnection(); // replyQueueName = channel.queueDeclare().getQueue(); // channel.queueBind(replyQueueName,exchange,replyQueueName); // consumer = new QueueingConsumer(channel); // channel.basicConsume(replyQueueName, true, consumer); }