List of usage examples for com.rabbitmq.client ConnectionFactory setPort
public void setPort(int port)
From source file:lpp.rabbitmq.original.EndPoint.java
License:Open Source License
public EndPoint(String endpointName, RabbitMqConfig config) throws IOException, TimeoutException { this.endPointName = endpointName; // ?//from w ww . java 2 s.c om ConnectionFactory factory = new ConnectionFactory(); factory.setHost(config.getHost()); factory.setPort(config.getPort()); factory.setUsername(config.getUserName()); factory.setPassword(config.getPassword()); // getting a connection connection = factory.newConnection(); // creating a channel channel = connection.createChannel(); // declaring a queue for this channel. If queue does not exist, // it will be created on the server. channel.queueDeclare(endpointName, false, false, false, null); }
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);// www .jav a 2s .c om } 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/>//from w w w . j av a 2 s . c o 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.es.netshell.rabbitmq.SSLConnection.java
License:Open Source License
public ConnectionFactory createConnection() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host);//w ww . jav a 2s.c o m factory.setUsername(user); factory.setPassword(password); factory.setPort(port); if (ssl) { char[] keyPassphrase = KEYPASS.toCharArray(); KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(new FileInputStream(KEYCERT), keyPassphrase); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, keyPassphrase); char[] trustPassphrase = TRUSTPASS.toCharArray(); KeyStore tks = KeyStore.getInstance("JKS"); tks.load(new FileInputStream(KEYSTORE), trustPassphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(tks); SSLContext c = SSLContext.getInstance("SSLv3"); c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); factory.useSslProtocol(c); } return factory; }
From source file:net.lshift.accent.ConnectionSmokeTest.java
License:Apache License
private static ConnectionFactory controlledFactory(int port) { ConnectionFactory controlledFactory = new ConnectionFactory(); controlledFactory.setPort(port); return controlledFactory; }
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:net.roboconf.messaging.internal.utils.RabbitMqUtils.java
License:Apache License
/** * Configures the connection factory with the right settings. * @param factory the connection factory * @param messageServerIp the message server IP (can contain a port) * @param messageServerUsername the user name for the message server * @param messageServerPassword the password for the message server * @throws IOException if something went wrong *//*from w w w. ja va 2 s . com*/ public static void configureFactory(ConnectionFactory factory, String messageServerIp, String messageServerUsername, String messageServerPassword) throws IOException { Map.Entry<String, Integer> entry = findUrlAndPort(messageServerIp); factory.setHost(entry.getKey()); if (entry.getValue() > 0) factory.setPort(entry.getValue()); factory.setUsername(messageServerUsername); factory.setPassword(messageServerPassword); }
From source file:net.roboconf.messaging.rabbitmq.internal.utils.RabbitMqUtils.java
License:Apache License
/** * Configures the connection factory with the right settings. * @param factory the connection factory * @param configuration the messaging configuration * @throws IOException if something went wrong * @see RabbitMqConstants//from w w w . j a v a 2 s . c om */ public static void configureFactory(ConnectionFactory factory, Map<String, String> configuration) throws IOException { final Logger logger = Logger.getLogger(RabbitMqUtils.class.getName()); logger.fine("Configuring a connection factory for RabbitMQ."); String messageServerIp = configuration.get(RABBITMQ_SERVER_IP); if (messageServerIp != null) { Map.Entry<String, Integer> entry = Utils.findUrlAndPort(messageServerIp); factory.setHost(entry.getKey()); if (entry.getValue() > 0) factory.setPort(entry.getValue()); } factory.setUsername(configuration.get(RABBITMQ_SERVER_USERNAME)); factory.setPassword(configuration.get(RABBITMQ_SERVER_PASSWORD)); // Timeout for connection establishment: 5s factory.setConnectionTimeout(5000); // Configure automatic reconnection factory.setAutomaticRecoveryEnabled(true); // Recovery interval: 10s factory.setNetworkRecoveryInterval(10000); // Exchanges and so on should be redeclared if necessary factory.setTopologyRecoveryEnabled(true); // SSL if (Boolean.parseBoolean(configuration.get(RABBITMQ_USE_SSL))) { logger.fine("Connection factory for RabbitMQ: SSL is used."); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream(configuration.get(RABBITMQ_SSL_KEY_STORE_PATH)); storeIS = new FileInputStream(configuration.get(RABBITMQ_SSL_TRUST_STORE_PATH)); char[] keyStorePassphrase = configuration.get(RABBITMQ_SSL_KEY_STORE_PASSPHRASE).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue(configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE)); ks.load(clientIS, keyStorePassphrase); String value = getValue(configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY); KeyManagerFactory kmf = KeyManagerFactory.getInstance(value); kmf.init(ks, keyStorePassphrase); char[] trustStorePassphrase = configuration.get(RABBITMQ_SSL_TRUST_STORE_PASSPHRASE).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue(configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE)); tks.load(storeIS, trustStorePassphrase); value = getValue(configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY); TrustManagerFactory tmf = TrustManagerFactory.getInstance(value); tmf.init(tks); SSLContext c = SSLContext .getInstance(getValue(configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL)); c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); factory.useSslProtocol(c); } catch (GeneralSecurityException e) { throw new IOException("SSL configuration for the RabbitMQ factory failed.", e); } finally { Utils.closeQuietly(storeIS); Utils.closeQuietly(clientIS); } } }
From source file:net.yacy.grid.io.messages.RabbitQueueFactory.java
License:Open Source License
private void init() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.server); if (this.port > 0) factory.setPort(this.port); if (this.username != null && this.username.length() > 0) factory.setUsername(this.username); if (this.password != null && this.password.length() > 0) factory.setPassword(this.password); try {/* w w w.j a va2s . c o m*/ this.connection = factory.newConnection(); this.channel = connection.createChannel(); this.queues = new ConcurrentHashMap<>(); } catch (TimeoutException e) { throw new IOException(e.getMessage()); } }
From source file:nl.uva.sne.drip.api.rpc.DRIPCaller.java
License:Apache License
public DRIPCaller(String messageBrokerHost, String requestQeueName) throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(messageBrokerHost);/*from w w w. j ava 2 s.c om*/ factory.setPort(AMQP.PROTOCOL.PORT); //factory.setUsername("guest"); //factory.setPassword("pass"); connection = factory.newConnection(); channel = connection.createChannel(); // create a single callback queue per client not per requests. replyQueueName = channel.queueDeclare().getQueue(); this.requestQeueName = requestQeueName; this.mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); }