List of usage examples for com.rabbitmq.client ConnectionFactory setVirtualHost
public void setVirtualHost(String virtualHost)
From source file:it.txt.ens.core.util.AMQPFactory.java
License:Apache License
public static Connection createConnection(ENSAuthzServiceConnectionParameters params) throws IOException { //create and configure the RabbitMQ Connection Factory ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(params.getSubjectID()); factory.setPassword(params.getAccessToken()); factory.setPort(params.getBrokerPort()); factory.setHost(params.getBrokerHost()); factory.setVirtualHost(params.getVirtualHost()); return factory.newConnection(); }
From source file:li.barter.chat.AbstractRabbitMQConnector.java
License:Open Source License
/** * Connect to the broker and create the exchange * //from w w w. ja v a 2s.c o m * @return success */ protected boolean connectToRabbitMQ(final String userName, final String password) { if ((mChannel != null) && mChannel.isOpen()) { return true; } try { final ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(mServer); connectionFactory.setUsername(userName); connectionFactory.setPassword(password); connectionFactory.setVirtualHost(mVirtualHost); connectionFactory.setPort(mPort); connectionFactory.setRequestedHeartbeat(AppConstants.HEART_BEAT_INTERVAL); mConnection = connectionFactory.newConnection(); mChannel = mConnection.createChannel(); mChannel.exchangeDeclare(mExchange, mExchangeType.key); return true; } catch (final Exception e) { e.printStackTrace(); return false; } }
From source file:mx.bigdata.utils.amqp.AMQPClientHelperImpl.java
License:Apache License
public ConnectionFactory createConnectionFactory(String key) throws Exception { ConnectionFactory factory = new ConnectionFactory(); String username = getValueOrDefault("amqp_username", key); if (username != null) { factory.setUsername(username);/* w ww . j av a 2 s . c o m*/ } String password = getValueOrDefault("amqp_password", key); if (password != null) { factory.setPassword(password); } String virtualHost = getValueOrDefault("amqp_virtual_host", key); if (virtualHost != null) { factory.setVirtualHost(virtualHost); } String host = getValueOrDefault("amqp_host", key); if (host != null) { factory.setHost(host); } Integer port = getIntegerOrDefault("amqp_port", key); if (port != null) { factory.setPort(port); } return factory; }
From source file:net.echinopsii.ariane.community.messaging.rabbitmq.Client.java
License:Open Source License
/** * Initialize RabbitMQ connection with provided properties and this client ServiceFactory. * <br/>//w w w . j a v a 2s . co m * Following properties fields MUST be defined : * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_HOST} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PORT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VHOST} * <br/> * Following properties fields MAY be defined: * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_USER} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PSWD} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_MSG_DEBUG_ON_TIMEOUT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_ROUTEES_NB_PER_SERVICE} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_TIMEOUT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_RETRY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_INFORMATION_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PRODUCT_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PLATFORM_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_COPYRIGHT_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VERSION_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_APP_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_CMP_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OSI_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OTM_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PGURL_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PID_KEY} * @param properties configuration properties * @throws IOException if problems to join NATS server */ @Override public void init(Dictionary properties) throws IOException { if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null) super.setClientID((String) properties.get(MomClient.RBQ_INFORMATION_KEY)); if (properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT) != null && (((String) properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT)).toLowerCase().equals("true"))) super.setMsgDebugOnTimeout(true); if (properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE) != null) super.setRouteesCountPerService(new Integer((String) properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE))); try { if (Class.forName("akka.osgi.ActorSystemActivator") != null && MessagingAkkaSystemActivator.getSystem() != null) super.setActorSystem(MessagingAkkaSystemActivator.getSystem()); else super.setActorSystem(ActorSystem.create("MySystem")); } catch (ClassNotFoundException e) { super.setActorSystem(ActorSystem.create("MySystem")); } ConnectionFactory factory = new ConnectionFactory(); factory.setHost((String) properties.get(MOM_HOST)); factory.setPort(new Integer((String) properties.get(MOM_PORT))); if (properties.get(RBQ_VHOST) != null) factory.setVirtualHost((String) properties.get(RBQ_VHOST)); if (properties.get(MOM_USER) != null) factory.setUsername((String) properties.get(MOM_USER)); if (properties.get(MOM_PSWD) != null) factory.setPassword((String) properties.get(MOM_PSWD)); Map<String, Object> factoryProperties = factory.getClientProperties(); if (properties.get(MomClient.RBQ_PRODUCT_KEY) != null) factoryProperties.put(RBQ_PRODUCT_KEY, properties.get(MomClient.RBQ_PRODUCT_KEY)); if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null) factoryProperties.put(RBQ_INFORMATION_KEY, super.getClientID()); if (properties.get(MomClient.RBQ_PLATFORM_KEY) != null) factoryProperties.put(RBQ_PLATFORM_KEY, properties.get(MomClient.RBQ_PLATFORM_KEY)); else factoryProperties.put(RBQ_PLATFORM_KEY, "Java " + System.getProperty("java.version")); if (properties.get(MomClient.RBQ_COPYRIGHT_KEY) != null) factoryProperties.put(RBQ_COPYRIGHT_KEY, properties.get(MomClient.RBQ_COPYRIGHT_KEY)); if (properties.get(MomClient.RBQ_VERSION_KEY) != null) factoryProperties.put(RBQ_VERSION_KEY, properties.get(MomClient.RBQ_VERSION_KEY)); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key instanceof String && ((String) key).startsWith(MomClient.ARIANE_KEYS)) factoryProperties.put((String) key, properties.get((String) key)); } connection = factory.newConnection(); super.setServiceFactory(new ServiceFactory(this)); }
From source file:net.orzo.queue.AmqpConnection.java
License:Apache License
@Override public void start() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.conf.host); factory.setPort(this.conf.port); factory.setVirtualHost(this.conf.virtualHost); factory.setUsername(this.conf.user); factory.setPassword(this.conf.password); this.connection = factory.newConnection(); }
From source file:org.apache.airavata.gfac.monitor.util.AMQPConnectionUtil.java
License:Apache License
public static Connection connect(String host, String vhost, String proxyFile) { Connection connection;//from w w w. jav a2s . c om try { String keyPassPhrase = "test123"; KeyStore ks = X509Helper.keyStoreFromPEM(proxyFile, keyPassPhrase); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, keyPassPhrase.toCharArray()); KeyStore tks = X509Helper.trustKeyStoreFromCertDir(); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(tks); SSLContext c = SSLContext.getInstance("SSLv3"); c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setPort(5671); factory.useSslProtocol(c); factory.setVirtualHost(vhost); factory.setSaslConfig(DefaultSaslConfig.EXTERNAL); connection = factory.newConnection(); } catch (Exception e) { e.printStackTrace(); return null; } return connection; }
From source file:org.apache.axis2.transport.rabbitmq.ConnectionFactoryManager.java
License:Open Source License
/** * Get the connection factory that matches the given name, i.e. referring to * the same underlying connection factory. Used by the RabbitMQSender to determine if already * available resources should be used for outgoing messages. If no factory instance is * found then a new one will be created and added to the connection factory map * * @param props a Map of connection factory properties and name * @return the connection factory or null if no connection factory compatible * with the given properties exists */// w w w . j a v a2 s. co m public ConnectionFactory getAMQPConnectionFactory(Hashtable<String, String> props) { ConnectionFactory connectionFactory = null; String hostName = props.get(RabbitMQConstants.SERVER_HOST_NAME); String portValue = props.get(RabbitMQConstants.SERVER_PORT); String hostAndPort = hostName + ":" + portValue; connectionFactory = connectionFactories.get(hostAndPort); if (connectionFactory == null) { com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); if (hostName != null && !hostName.equals("")) { factory.setHost(hostName); } else { throw new AxisRabbitMQException("Host name is not correctly defined"); } int port = Integer.parseInt(portValue); if (port > 0) { factory.setPort(port); } String userName = props.get(RabbitMQConstants.SERVER_USER_NAME); if (userName != null && !userName.equals("")) { factory.setUsername(userName); } String password = props.get(RabbitMQConstants.SERVER_PASSWORD); if (password != null && !password.equals("")) { factory.setPassword(password); } String virtualHost = props.get(RabbitMQConstants.SERVER_VIRTUAL_HOST); if (virtualHost != null && !virtualHost.equals("")) { factory.setVirtualHost(virtualHost); } factory.setAutomaticRecoveryEnabled(true); factory.setTopologyRecoveryEnabled(false); connectionFactory = new ConnectionFactory(hostAndPort, factory); connectionFactories.put(connectionFactory.getName(), connectionFactory); } return connectionFactory; }
From source file:org.apache.camel.component.rabbitmq.RabbitMQConsumerIntTest.java
License:Apache License
@Test public void sentMessageIsReceived() throws InterruptedException, IOException { to.expectedMessageCount(1);//from w ww .ja va2s . co m to.expectedHeaderReceived(RabbitMQConstants.REPLY_TO, "myReply"); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPort(5672); factory.setUsername("cameltest"); factory.setPassword("cameltest"); factory.setVirtualHost("/"); Connection conn = factory.newConnection(); AMQP.BasicProperties.Builder properties = new AMQP.BasicProperties.Builder(); properties.replyTo("myReply"); Channel channel = conn.createChannel(); channel.basicPublish(EXCHANGE, "", properties.build(), "hello world".getBytes()); to.assertIsSatisfied(); }
From source file:org.apache.camel.component.rabbitmq.RabbitMQProducerIntTest.java
License:Apache License
@Test public void producedMessageIsReceived() throws InterruptedException, IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPort(5672);//from w w w.ja v a2s.c om factory.setUsername("cameltest"); factory.setPassword("cameltest"); factory.setVirtualHost("/"); Connection conn = factory.newConnection(); final List<Envelope> received = new ArrayList<Envelope>(); Channel channel = conn.createChannel(); channel.queueDeclare("sammyq", false, false, true, null); channel.queueBind("sammyq", EXCHANGE, "route1"); channel.basicConsume("sammyq", true, new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { received.add(envelope); } }); template.sendBodyAndHeader("new message", RabbitMQConstants.EXCHANGE_NAME, "ex1"); Thread.sleep(500); assertEquals(1, received.size()); }
From source file:org.apache.cloudstack.mom.rabbitmq.RabbitMQEventBus.java
License:Apache License
private synchronized Connection createConnection() throws Exception { try {//from w ww . j a v a2 s. c o m ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(username); factory.setPassword(password); factory.setVirtualHost("/"); factory.setHost(amqpHost); factory.setPort(port); Connection connection = factory.newConnection(); connection.addShutdownListener(disconnectHandler); _connection = connection; return _connection; } catch (Exception e) { throw e; } }