List of usage examples for com.rabbitmq.client ConnectionFactory setUsername
public void setUsername(String username)
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);/*from w ww . j a v a 2s . com*/ 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 {/*w w w . j a v a 2 s . com*/ 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 w w. jav a 2 s . co m*/ 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 ww . j a va 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 {//w w w. j a v a 2s . c om 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>/*w w w.j av a2 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>/*from ww w.ja v a2s . c om*/ * 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 {/*from w w w. j av a 2s . co m*/ // 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. ja v a 2s .com*/ 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); }
From source file:ox.softeng.burst.services.RabbitService.java
License:Open Source License
public RabbitService(String rabbitMQHost, Integer port, String username, String password, String rabbitMQExchange, String rabbitMQQueue, EntityManagerFactory emf) throws IOException, TimeoutException, JAXBException { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(username); factory.setPassword(password);//from w w w .j a v a 2 s . co m factory.setPort(port); factory.setHost(rabbitMQHost); factory.setAutomaticRecoveryEnabled(true); entityManagerFactory = emf; this.rabbitMQQueue = rabbitMQQueue; this.rabbitMQExchange = rabbitMQExchange; connection = factory.newConnection(); unmarshaller = JAXBContext.newInstance(MessageDTO.class).createUnmarshaller(); }