List of usage examples for com.rabbitmq.client ConnectionFactory setPassword
public void setPassword(String password)
From source file:org.trianacode.TrianaCloud.Broker.Receiver.java
License:Open Source License
public String init() { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host);/*from w w w. j a v a 2 s.c o m*/ factory.setPort(port); factory.setUsername(user); factory.setPassword(password); factory.setVirtualHost(vHost); factory.setConnectionTimeout(60); try { connection = factory.newConnection(); channel = connection.createChannel(); consumer = new QueueingConsumer(channel); receiveQueueName = channel.queueDeclare("", false, false, true, null).getQueue(); channel.basicConsume(receiveQueueName, true, consumer); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. return null; } return receiveQueueName; }
From source file:org.trianacode.TrianaCloud.Broker.RPCServer.java
License:Open Source License
public void init() throws ServletException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host);//ww w. j a va 2s .c o m factory.setPort(port); factory.setUsername(user); factory.setPassword(password); factory.setVirtualHost(vHost); factory.setConnectionTimeout(60); try { keepRunning = true; td = new TaskDAO(); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(rpc_queue_name, false, false, false, null); channel.basicQos(1); consumer = new QueueingConsumer(channel); channel.basicConsume(rpc_queue_name, false, consumer); logger.info("[x] Awaiting RPC requests"); } catch (Exception e) { ServletException se = new ServletException(e); logger.fatal("Something Happened!", se); throw se; } }
From source file:org.trianacode.TrianaCloud.Utils.RPCClient.java
License:Open Source License
public RPCClient() { try {// www . ja v a 2 s . c om ConnectionFactory factory = new ConnectionFactory(); factory.setHost("zotac.toaster.dbyz.co.uk"); factory.setVirtualHost("trianacloud"); factory.setUsername("trianacloud"); factory.setPassword("trianacloud"); factory.setRequestedHeartbeat(60); connection = factory.newConnection(); channel = connection.createChannel(); replyQueueName = channel.queueDeclare().getQueue(); consumer = new QueueingConsumer(channel); channel.basicConsume(replyQueueName, true, consumer); } catch (Exception e) { logger.fatal("Error connecting to Rabbit while initialising RPCClient", e); } }
From source file:org.trpr.mule.transport.rabbitmq.RabbitConnector.java
License:Apache License
/** * Abstract method implementation. Creates the AMQP connection * @see org.mule.transport.AbstractConnector#doConnect() *//*w ww . j av a 2 s . c om*/ protected void doConnect() throws Exception { if (connection == null) { int totalNumberOfNodes = rabbitMQConfigurations.size(); int tries = 0; while (tries <= totalNumberOfNodes) { int index = (lastUsedConnectionIndex + 1) % totalNumberOfNodes; RabbitMQConfiguration rabbitMQConfiguration = null; try { ConnectionFactory factory = new ConnectionFactory(); rabbitMQConfiguration = rabbitMQConfigurations.get(index); factory.setUsername(rabbitMQConfiguration.getUserName()); factory.setPassword(rabbitMQConfiguration.getPassword()); factory.setVirtualHost(rabbitMQConfiguration.getVirtualHost()); factory.setRequestedHeartbeat(rabbitMQConfiguration.getRequestHeartBeat()); factory.setHost(rabbitMQConfiguration.getHostName()); factory.setPort(rabbitMQConfiguration.getPortNumber()); connection = factory.newConnection(); lastUsedConnectionIndex = index; logger.info("Connection successfully created to configuration = " + rabbitMQConfiguration); return; } catch (Exception e) { logger.info("Failed to connect to Rabbit MQ Node. Configuration is " + rabbitMQConfiguration + ". Will try other configurations"); } tries++; } logger.error("Failed to connect to all configured Rabbit MQ nodes"); throw new Exception("Failed to connect to all configured Rabbit MQ nodes"); } }
From source file:org.trpr.platform.integration.impl.messaging.RabbitConnectionHolder.java
License:Apache License
/** * Helper method to create RabbitMQ {@link Connection} and {@link Channel} for the specified {@link RabbitMQRpcConfiguration} * @param configuration the RabbitMQRpcConfiguration or one of its sub-types to create connection objects for * @throws MessagingException in case of errors during connection & channel creation *///from w w w . j a v a 2 s . c om private void createConnection(RabbitMQRpcConfiguration configuration) throws MessagingException { synchronized (this) { // all code blocks that mutate the connection and channel objects held by this class are synchronized ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(configuration.getUserName()); factory.setPassword(configuration.getPassword()); factory.setVirtualHost(configuration.getVirtualHost()); factory.setRequestedHeartbeat(configuration.getRequestHeartBeat()); factory.setHost(configuration.getHostName()); factory.setPort(configuration.getPortNumber()); try { // create the connection this.conn = factory.newConnection(); // add a shutdown listener to the newly created connection this.conn.addShutdownListener(this); // create the channel this.channel = this.conn.createChannel(); this.channel.exchangeDeclare(configuration.getExchangeName(), configuration.getExchangeType(), configuration.isDurable()); } catch (Exception e) { LOGGER.error("Error initializing RabbitMQ connection for : " + configuration.toString(), e); throw new MessagingException( "Error initializing RabbitMQ connection for : " + configuration.toString()); //not passing the root cause as it is logged here } } }
From source file:org.wso2.carbon.caching.invalidator.amqp.CacheInvalidationSubscriber.java
License:Open Source License
private void subscribe() { log.debug("Global cache invalidation: initializing the subscription"); try {//from w w w . j a v a 2 s. c o m ConnectionFactory factory = new ConnectionFactory(); factory.setHost(ConfigurationManager.getProviderUrl()); int port = Integer.parseInt(ConfigurationManager.getProviderPort()); factory.setPort(port); factory.setUsername(ConfigurationManager.getProviderUsername()); factory.setPassword(ConfigurationManager.getProviderPassword()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(ConfigurationManager.getTopicName(), "topic"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ConfigurationManager.getTopicName(), "#"); consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); Thread reciever = new Thread(messageReciever); reciever.start(); log.info("Global cache invalidation is online"); } catch (Exception e) { log.error("Global cache invalidation: Error message broker initialization", e); } }
From source file:org.wso2.carbon.event.adapter.rabbitmq.internal.util.RabbitMQOutputEventAdapterPublisher.java
License:Open Source License
/** * <pre>/* www. j a va2 s . c o m*/ * Create a rabbitmq ConnectionFactory instance * </pre> * @param hostName * @param port * @param userName * @param password * @param virtualHost * @return */ private synchronized static ConnectionFactory getConnectionFactory(String hostName, int port, String userName, String password, String virtualHost) { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(hostName); factory.setPort(port); factory.setUsername(userName); factory.setPassword(password); factory.setVirtualHost(virtualHost); /** * Add connection recovery logic * @author Sang-Cheon Park * @date 2015.07.16 */ /** * connection that will recover automatically */ factory.setAutomaticRecoveryEnabled(true); /** * attempt recovery every 5 seconds */ factory.setNetworkRecoveryInterval(5 * 1000); /** * wait maximum 10 seconds to connect(if connection failed, will be retry to connect after 5 seconds) */ factory.setConnectionTimeout(10 * 1000); return factory; }
From source file:org.wso2.carbon.event.adaptor.rabbitmq.internal.EventAdapterHelper.java
License:Apache License
/** * <pre>// www. jav a2s . c o m * Create a rabbitmq ConnectionFactory instance * </pre> * @param hostName * @param port * @param userName * @param password * @param virtualHost * @return */ public synchronized static ConnectionFactory getConnectionFactory(String hostName, int port, String userName, String password, String virtualHost) { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(hostName); factory.setPort(port); factory.setUsername(userName); factory.setPassword(password); factory.setVirtualHost(virtualHost); /** * Add connection recovery logic * @author Sang-Cheon Park * @date 2015.07.16 */ /** * connection that will recover automatically */ factory.setAutomaticRecoveryEnabled(true); /** * attempt recovery every 5 seconds */ factory.setNetworkRecoveryInterval(5 * 1000); /** * wait maximum 10 seconds to connect(if connection failed, will be retry to connect after 5 seconds) */ factory.setConnectionTimeout(10 * 1000); return factory; }
From source file:other.common.messaging.JsonConnection.java
License:Apache License
public JsonConnection() { // Create a ConnectionFactory ConnectionFactory connectionFactory = new ConnectionFactory(); // Create a Connection try {// ww w . j a v a 2s . c om // Create a ConnectionFactory connectionFactory.setHost(Play.configuration.getProperty("AMQPhost")); connectionFactory.setPort(Integer.valueOf(Play.configuration.getProperty("AMQPport"))); connectionFactory.setUsername(Play.configuration.getProperty("AMQPuser")); connectionFactory.setPassword(Play.configuration.getProperty("AMQPpasswd")); /* The AMQ connection. */ Connection connection = connectionFactory.newConnection(); channel = connection.createChannel(); // Create exchange channel.exchangeDeclare("iris", "topic", true); } catch (IOException e) { LOGGER.error("Error while connection to AMQP broker: " + e.getMessage()); System.exit(1); } }
From source file:ox.softeng.burst.service.message.RabbitMessageService.java
public RabbitMessageService(EntityManagerFactory emf, Properties properties) throws IOException, TimeoutException { exchange = properties.getProperty("rabbitmq.exchange"); queue = properties.getProperty("rabbitmq.queue"); entityManagerFactory = emf;/*from www.java2 s.co m*/ consumerCount = Utils.convertToInteger("message.service.thread.size", properties.getProperty("message.service.consumer.size"), 1); String host = properties.getProperty("rabbitmq.host"); String username = properties.getProperty("rabbitmq.user", ConnectionFactory.DEFAULT_USER); String password = properties.getProperty("rabbitmq.password", ConnectionFactory.DEFAULT_PASS); Integer port = Utils.convertToInteger("rabbitmq.port", properties.getProperty("rabbitmq.port"), ConnectionFactory.DEFAULT_AMQP_PORT); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(username); factory.setPassword(password); factory.setPort(port); factory.setHost(host); factory.setAutomaticRecoveryEnabled(true); factory.setThreadFactory(new NamedThreadFactory("consumer")); connection = factory.newConnection(); logger.info("Creating new RabbitMQ Service using: \n" + " host: {}:{}\n" + " user: {}\n" + " exchange: {}\n" + " queue: {}", host, port, username, exchange, queue); }