List of usage examples for com.rabbitmq.client ConnectionFactory setVirtualHost
public void setVirtualHost(String virtualHost)
From source file:org.kairosdb.plugin.rabbitmq.core.RabbitmqService.java
License:MIT License
@Override public void start() throws KairosDBException { try {/*from w ww . j av a 2s .co m*/ LOGGER.info("[KRMQ] Starting to RabbitMQ consumer thread."); // Socket abstract connection with broker ConnectionFactory rabbitmqConnectionFactory = new ConnectionFactory(); rabbitmqConnectionFactory.setHost(rabbmitmqHost); rabbitmqConnectionFactory.setVirtualHost(rabbitmqVirtualHost); rabbitmqConnectionFactory.setUsername(rabbitmqUser); rabbitmqConnectionFactory.setPassword(rabbitmqPassword); rabbitmqConnectionFactory.setPort(rabbitmqPort); rabbitmqConnectionFactory.setConnectionTimeout(rabbitmqTimeout); rabbitmqConnectionFactory.setRequestedChannelMax(rabbitmqChannelMax); rabbitmqConnectionFactory.setRequestedFrameMax(rabbitmqFrameMax); rabbitmqConnectionFactory.setRequestedHeartbeat(rabbitmqHearbeat); rabbitmqConnectionFactory.setAutomaticRecoveryEnabled(true); // Get KairosDatastore implementation KairosDatastore kairosDatabase = googleInjector.getInstance(KairosDatastore.class); // Create consumer thread RabbitmqConsumer consumer = new RabbitmqConsumer(kairosDatabase, rabbitmqConnectionFactory, bindingsFile, configurationJSONFieldValue, configurationJSONTimeStamp, configurationJSONTags, configurationCSVSeperator, configurationDefaultContentType); // Start consumer thread consumerThread = new Thread(consumer); consumerThread.start(); } catch (Exception e) { LOGGER.error("[KRMQ] An error occurred: ", e); } }
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; }/*from w ww .j a v a 2s . 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 www .j a v a2 s . c om*/ 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.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); }/*ww w. j av a 2 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.plugin.PluginListener.java
License:Apache License
private void initRabbitMQ() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(brokerIp);//from ww w . j a va 2 s . c o m factory.setPort(brokerPort); 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.s23m.cell.repository.client.connector.RepositoryClientConnector.java
License:Mozilla Public License
private void initClient() { final ConnectionFactory cfconn = new ConnectionFactory(); cfconn.setHost(ConfigValues.getString("RepositoryClientServer.HOST_NAME")); cfconn.setPort(Integer.parseInt(ConfigValues.getString("RepositoryClientServer.PORT"))); cfconn.setVirtualHost(ConfigValues.getString("RepositoryClientServer.VHOST_NAME")); cfconn.setUsername(ConfigValues.getString("RepositoryClientServer.USER_NAME")); cfconn.setPassword(ConfigValues.getString("RepositoryClientServer.PW")); Connection conn;/*www .ja va 2s . c o m*/ try { conn = cfconn.newConnection(); final Channel ch = conn.createChannel(); clientService = new RpcClient(ch, "", ConfigValues.getString("RepositoryClientServer.QUEUE")); } catch (final IOException ex) { throw new IllegalStateException("Client set up failed", ex); } }
From source file:org.s23m.cell.repository.client.server.RepositoryClientServer.java
License:Mozilla Public License
private void setupConnection() throws IOException { final ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setHost(LOCALHOST);/* www . j a v a 2s . com*/ connFactory.setPort(PORT); connFactory.setVirtualHost(ConfigValues.getString("RepositoryClientServer.VHOST_NAME")); connFactory.setUsername(ConfigValues.getString("RepositoryClientServer.USER_NAME")); connFactory.setPassword(ConfigValues.getString("RepositoryClientServer.PW")); final Connection conn = connFactory.newConnection(); ch = conn.createChannel(); ch.queueDeclare(QUEUE_NAME, false, false, false, null); }
From source file:org.smartdeveloperhub.curator.connector.BrokerController.java
License:Apache License
void connect() throws ControllerException { this.write.lock(); try {// w w w . jav a 2 s.c o m if (this.connected) { return; } final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.broker.host()); factory.setPort(this.broker.port()); factory.setVirtualHost(this.broker.virtualHost()); factory.setThreadFactory(brokerThreadFactory()); factory.setExceptionHandler(new BrokerControllerExceptionHandler(this)); this.connection = factory.newConnection(); createChannel(); } catch (IOException | TimeoutException e) { this.connected = false; final String message = String.format("Could not connect to broker at %s:%s using virtual host %s", this.broker.host(), this.broker.port(), this.broker.virtualHost()); throw new ControllerException(message, e); } finally { this.write.unlock(); } }
From source file:org.smartdeveloperhub.harvesters.it.notification.ConnectionManager.java
License:Apache License
void connect() throws ControllerException { this.lock.lock(); try {//from w w w. j a v a2 s . c om if (connected()) { return; } final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.brokerHost); factory.setPort(this.brokerPort); factory.setVirtualHost(this.virtualHost); factory.setThreadFactory(brokerThreadFactory()); factory.setExceptionHandler(new ConnectionManagerExceptionHandler(this)); this.connection = factory.newConnection(); createChannel(); } catch (IOException | TimeoutException e) { final String message = String.format("Could not connect to broker at %s:%s using virtual host %s", this.brokerHost, this.brokerPort, this.virtualHost); throw new ControllerException(this.brokerHost, this.brokerPort, this.virtualHost, message, e); } finally { this.lock.unlock(); } }
From source file:org.teksme.server.common.messaging.AMQPBrokerManager.java
License:Apache License
protected Connection connect(MessageMiddleware msgMiddlewareConfig) throws IOException { logger.info("Connecting to AMQP broker..."); ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUsername(msgMiddlewareConfig.getUsername()); connFactory.setPassword(msgMiddlewareConfig.getPasswd()); connFactory.setVirtualHost(msgMiddlewareConfig.getVirtualHost()); connFactory.setHost(msgMiddlewareConfig.getHost()); connFactory.setRequestedHeartbeat(0); connFactory.setPort(//from w w w. j a v a 2 s . c o m msgMiddlewareConfig.getPort() == null ? AMQP.PROTOCOL.PORT : msgMiddlewareConfig.getPort()); toString(connFactory); try { conn = connFactory.newConnection(); } catch (Exception e) { e.printStackTrace(); } conn.addShutdownListener(this); logger.info("RabbitMQ AMQP broker connected!"); return conn; }