List of usage examples for com.rabbitmq.client ConnectionFactory setPort
public void setPort(int port)
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 ww w .j ava2 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.esb.rabbitmq.message.store.jira.ESBJAVA4569RabbiMQSSLStoreWithClientCertValidationTest.java
License:Open Source License
/** * Helper method to retrieve queue message from rabbitMQ * * @return result//ww w.j av a 2 s.co m * @throws Exception */ private static String consumeWithoutCertificate() throws Exception { String result = ""; String basePath = TestConfigurationProvider.getResourceLocation() + "/artifacts/ESB/messageStore/rabbitMQ/SSL/"; String truststoreLocation = basePath + "rabbitMQ/certs/client/rabbitstore"; String keystoreLocation = basePath + "rabbitMQ/certs/client/keycert.p12"; char[] keyPassphrase = "MySecretPassword".toCharArray(); KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(new FileInputStream(keystoreLocation), keyPassphrase); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(ks, keyPassphrase); char[] trustPassphrase = "rabbitstore".toCharArray(); KeyStore tks = KeyStore.getInstance("JKS"); tks.load(new FileInputStream(truststoreLocation), trustPassphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); tmf.init(tks); SSLContext c = SSLContext.getInstance("SSL"); c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPort(5671); factory.useSslProtocol(c); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); GetResponse chResponse = channel.basicGet("WithClientCertQueue", true); if (chResponse != null) { byte[] body = chResponse.getBody(); result = new String(body); } channel.close(); conn.close(); return result; }
From source file:org.wso2.carbon.esb.rabbitmq.message.store.jira.ESBJAVA4569RabbiMQSSLStoreWithoutClientCertValidationTest.java
License:Open Source License
/** * Helper method to retrieve queue message from rabbitMQ * * @return result//from w w w.jav a 2 s .c o m * @throws Exception */ private static String consumeWithoutCertificate() throws Exception { String result = ""; ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPort(5671); factory.useSslProtocol(); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); GetResponse chResponse = channel.basicGet("WithoutClientCertQueue", true); if (chResponse != null) { byte[] body = chResponse.getBody(); result = new String(body); } channel.close(); conn.close(); return result; }
From source file:org.wso2.carbon.event.adapter.rabbitmq.internal.util.RabbitMQOutputEventAdapterPublisher.java
License:Open Source License
/** * <pre>/*from w w w. j av a2s .c om*/ * 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>// w w w. j a v a 2 s . co 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 {/*from w w w . ja v a 2 s . 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 ww w . ja va2 s .c o 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); }
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);/* w ww. ja v a 2s.c o m*/ factory.setPassword(password); 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(); }
From source file:pl.nask.hsn2.unicorn.connector.ConnectorImpl.java
License:Open Source License
private void createConnection() throws ConnectionException { ConnectionFactory factory = new ConnectionFactory(); String[] addressParts = address.split(":"); factory.setHost(addressParts[0]);/* w w w .ja v a 2s . c om*/ if (addressParts.length > 1) { factory.setPort(Integer.parseInt(addressParts[1])); } try { connection = factory.newConnection(); channel = connection.createChannel(); } catch (IOException e) { throw new ConnectionException("Creating connection error!", e); } }
From source file:rabbitmq_clienttest.Simple_receiver.java
public static void main(String[] argv) throws Exception { db = new Database_connector_sqlite(); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setUsername("es"); factory.setPassword("a"); //factory.setVirtualHost("/"); factory.setPort(5672); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override//from www .ja v a 2 s . c o m public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); doWork(message); } }; channel.basicConsume(QUEUE_NAME, true, consumer); }