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

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

Introduction

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

Prototype

public void setPort(int port) 

Source Link

Usage

From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java

@Before
public void create() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template = new RabbitTemplate(connectionFactory);
}

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

private void doTest(int concurrentConsumers, ContainerConfigurer configurer) {
    int messageCount = 10;
    RabbitTemplate template = new RabbitTemplate();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setChannelCacheSize(concurrentConsumers);
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
    SimpleMessageConverter messageConverter = new SimpleMessageConverter();
    messageConverter.setCreateMessageIds(true);
    template.setMessageConverter(messageConverter);
    for (int i = 0; i < messageCount; i++) {
        template.convertAndSend(queue1.getName(), new Integer(i));
        template.convertAndSend(queue2.getName(), new Integer(i));
    }//w w w . ja v a2  s .  c  om
    final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    final CountDownLatch latch = new CountDownLatch(messageCount * 2);
    PojoListener listener = new PojoListener(latch);
    container.setMessageListener(new MessageListenerAdapter(listener));
    container.setAcknowledgeMode(AcknowledgeMode.AUTO);
    container.setChannelTransacted(true);
    container.setConcurrentConsumers(concurrentConsumers);
    configurer.configure(container);
    container.afterPropertiesSet();
    container.start();
    try {
        int timeout = Math.min(1 + messageCount / concurrentConsumers, 30);
        boolean waited = latch.await(timeout, TimeUnit.SECONDS);
        logger.info("All messages recovered: " + waited);
        assertEquals(concurrentConsumers, container.getActiveConsumerCount());
        assertTrue("Timed out waiting for messages", waited);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IllegalStateException("unexpected interruption");
    } finally {
        container.shutdown();
        assertEquals(0, container.getActiveConsumerCount());
    }
    assertNull(template.receiveAndConvert(queue1.getName()));
    assertNull(template.receiveAndConvert(queue2.getName()));
}

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   ww w  .j  a va 2 s . c om*/
    admin.declareQueue(queue);
    admin.deleteQueue(queue1.getName());
    admin.declareQueue(queue1);
}

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

@SuppressWarnings("deprecation")
@Override/*from   w w w  . j ava  2s .c o 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 w w. j a  va  2 s  .  c o 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);
}