Example usage for org.springframework.amqp.rabbit.connection CachingConnectionFactory setHost

List of usage examples for org.springframework.amqp.rabbit.connection CachingConnectionFactory setHost

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.connection CachingConnectionFactory setHost.

Prototype

public void setHost(String host) 

Source Link

Usage

From source file:com.nkapps.billing.configs.RabbitMQConfig.java

@Bean
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost(environment.getProperty("rabbitmq.host"));
    connectionFactory.setPort(Integer.parseInt(environment.getProperty("rabbitmq.port")));
    connectionFactory.setUsername(environment.getProperty("rabbitmq.username"));
    connectionFactory.setPassword(environment.getProperty("rabbitmq.password"));
    connectionFactory.setVirtualHost(environment.getProperty("rabbitmq.virtual_host"));

    return connectionFactory;
}

From source file:vn.topmedia.monitor.rabbit.client.RabbitClientConfiguration.java

@Bean
@Override//from   w ww.  j a v a 2  s .com
public ConnectionFactory connectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setUsername(Constants.RABBIT_USER);
    connectionFactory.setPassword(Constants.RABBIT_PASSWORD);
    connectionFactory.setHost(Constants.RABBIT_SERVER);
    connectionFactory.setVirtualHost(Constants.RABBIT_VITUALHOST);
    connectionFactory.setPort(Constants.RABBIT_PORT);
    return connectionFactory;
}

From source file:com.noriental.solr.config.test.BrokerRunning.java

public void removeTestQueues() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    for (Queue queue : this.queues) {
        admin.deleteQueue(queue.getName());
    }/*w  w w .j  av  a 2  s.  c om*/
    connectionFactory.destroy();
}

From source file:com.sample.amqp.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {/*from w  w  w  .j  a  v  a 2  s  . c  o  m*/
        ampqUrl = new URI(getEnvOrThrow("CLOUDAMQP_URL"));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    final CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(ampqUrl.getUserInfo().split(":")[0]);
    factory.setPassword(ampqUrl.getUserInfo().split(":")[1]);
    factory.setHost(ampqUrl.getHost());
    factory.setPort(ampqUrl.getPort());
    factory.setVirtualHost(ampqUrl.getPath().substring(1));
    factory.setPublisherReturns(true);

    return factory;
}

From source file:com.noriental.solr.config.test.BrokerRunning.java

@Override
public Statement apply(Statement base, Description description) {

    // Check at the beginning, so this can be used as a static field
    if (assumeOnline) {
        Assume.assumeTrue(brokerOnline.get(port));
    } else {/*ww w  . j  av  a2 s .c  om*/
        Assume.assumeTrue(brokerOffline.get(port));
    }

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");

    try {

        connectionFactory.setPort(port);
        if (StringUtils.hasText(hostName)) {
            connectionFactory.setHost(hostName);
        }
        RabbitAdmin admin = new RabbitAdmin(connectionFactory);

        for (Queue queue : queues) {
            String queueName = queue.getName();

            if (purge) {
                logger.debug("Deleting queue: " + queueName);
                // Delete completely - gets rid of consumers and bindings as well
                admin.deleteQueue(queueName);
            }

            if (isDefaultQueue(queueName)) {
                // Just for test probe.
                admin.deleteQueue(queueName);
            } else {
                admin.declareQueue(queue);
            }
        }
        brokerOffline.put(port, false);
        if (!assumeOnline) {
            Assume.assumeTrue(brokerOffline.get(port));
        }

        if (this.management) {
            Client client = new Client("http://localhost:15672/api/", "guest", "guest");
            if (!client.alivenessTest("/")) {
                throw new RuntimeException(
                        "Aliveness test failed for localhost:15672 guest/quest; " + "management not available");
            }
        }
    } catch (AmqpTimeoutException e) {
        fail("Timed out getting connection");
    } catch (Exception e) {
        logger.warn("Not executing tests because basic connectivity test failed", e);
        brokerOnline.put(port, false);
        if (assumeOnline) {
            Assume.assumeNoException(e);
        }
    } finally {
        connectionFactory.destroy();
    }

    return super.apply(base, description);

}

From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java

@Test
public void setAddressesEmpty() throws Exception {
    ConnectionFactory mock = mock(com.rabbitmq.client.ConnectionFactory.class);
    CachingConnectionFactory ccf = new CachingConnectionFactory(mock);
    ccf.setExecutor(mock(ExecutorService.class));
    ccf.setHost("abc");
    ccf.setAddresses("");
    ccf.createConnection();/*from   w ww  .j a va2  s  .  c o  m*/
    verify(mock).isAutomaticRecoveryEnabled();
    verify(mock).setHost("abc");
    Log logger = TestUtils.getPropertyValue(ccf, "logger", Log.class);
    if (logger.isInfoEnabled()) {
        verify(mock).getHost();
        verify(mock).getPort();
    }
    verify(mock).newConnection(any(ExecutorService.class), anyString());
    verifyNoMoreInteractions(mock);
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerIntegration2Tests.java

@Before
public void declareQueues() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
    admin = new RabbitAdmin(connectionFactory);
    admin.deleteQueue(queue.getName());/*from   w w  w.  j ava 2s  . co  m*/
    admin.declareQueue(queue);
    admin.deleteQueue(queue1.getName());
    admin.declareQueue(queue1);
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerWithRabbitMQ.java

public static void main(String[] args) throws InterruptedException {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
    connectionFactory.setHost("localhost");
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    assertNotNull(connectionFactory);/*from   ww w.  j a v  a2s  .  c om*/

    MessageConverter messageConverter = new SimpleMessageConverter();
    MessageProperties messageProperties = new MessageProperties();
    messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames("foo");
    container.setPrefetchCount(1000);
    container.setTxSize(500);
    container.setAcknowledgeMode(AcknowledgeMode.AUTO);
    container.setConcurrentConsumers(20);
    container.setMessageListener(new MessageListenerAdapter(new SimpleAdapter(), messageConverter));
    container.start();

    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setMessageConverter(messageConverter);
    List<BlockingQueue<?>> queues = getQueues(container);

    Thread.sleep(10000);
    int n = 0;
    while (true) {
        for (int i = 1; i <= 200; i++) {

            template.send("foo", "",
                    new Message(
                            "foo # ID: id".replace("#", String.valueOf(i))
                                    .replace("id", java.util.UUID.randomUUID().toString()).getBytes(),
                            messageProperties));

        }
        Thread.sleep(1000);
        if (++n % 10 == 0) {
            logger.warn(count(queues));
        }
    }
}

From source file:org.springframework.amqp.rabbit.test.BrokerFederated.java

@SuppressWarnings("deprecation")
@Override//www.  j  av  a2 s.  co  m
public Statement apply(Statement base, FrameworkMethod method, Object target) {

    // Check at the beginning, so this can be used as a static field
    if (assumeOnline) {
        Assume.assumeTrue(brokerOnline.get(port));
    } else {
        Assume.assumeTrue(brokerOffline.get(port));
    }

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();

    try {

        connectionFactory.setPort(port);
        if (StringUtils.hasText(hostName)) {
            connectionFactory.setHost(hostName);
        }
        RabbitAdmin admin = new RabbitAdmin(connectionFactory);
        org.springframework.amqp.core.FederatedExchange exchange = new org.springframework.amqp.core.FederatedExchange(
                "fedDirectRuleTest");
        exchange.setBackingType("direct");
        exchange.setUpstreamSet("upstream-set");
        admin.declareExchange(exchange);
        admin.deleteExchange("fedDirectRuleTest");

        brokerOffline.put(port, false);

        if (!assumeOnline) {
            Assume.assumeTrue(brokerOffline.get(port));
        }

    } catch (Exception e) {
        logger.warn("Not executing tests because federated connectivity test failed", e);
        brokerOnline.put(port, false);
        if (assumeOnline) {
            Assume.assumeNoException(e);
        }
    } finally {
        connectionFactory.destroy();
    }

    return super.apply(base, method, target);

}

From source file:org.springframework.integration.amqp.rule.BrokerRunning.java

@Override
public Statement apply(Statement base, Description description) {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");

    try {//from   w ww  .  ja  v  a2 s.  co m

        connectionFactory.setPort(PORT);

        RabbitAdmin admin = new RabbitAdmin(connectionFactory);

        for (Queue queue : queues) {
            String queueName = queue.getName();
            logger.info("Deleting queue: " + queueName);
            // Delete completely - gets rid of consumers and bindings as well
            admin.deleteQueue(queueName);

            if (!DEFAULT_QUEUE_NAME.getName().equals(queueName)) {
                admin.declareQueue(queue);
            }
        }

    } catch (final Exception e) {
        logger.warn("Not executing tests because basic connectivity test failed", e);
        Assume.assumeNoException(e);
    } finally {
        connectionFactory.destroy();
    }

    return super.apply(base, description);
}