Package org.springframework.amqp.rabbit.connection

Examples of org.springframework.amqp.rabbit.connection.CachingConnectionFactory


        if(this.amqpTemplate == null && getCamelContext() != null && getCamelContext().getRegistry() != null) {
            //Attempt to load an AMQP template from the registry
            this.amqpTemplate = new HashMap<String, AmqpTemplate>();
            Map<String, AmqpTemplate> templateMap = getCamelContext().getRegistry().findByTypeWithName(AmqpTemplate.class);
            for(AmqpTemplate template : templateMap.values()){
                CachingConnectionFactory adminConnection = (CachingConnectionFactory)((RabbitTemplate) template).getConnectionFactory();
                for(Map.Entry<String, ConnectionFactory> connection : this.connectionFactory.entrySet()){
                    if(identicalConnectionFactories(adminConnection, connection.getValue())){
                        this.amqpTemplate.put(connection.getKey(), template);
                        break;
                    }
View Full Code Here


  }

  private RabbitTemplate createTemplate(int concurrentConsumers) {
    RabbitTemplate template = new RabbitTemplate();
    // SingleConnectionFactory connectionFactory = new SingleConnectionFactory();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setChannelCacheSize(concurrentConsumers);
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
    return template;
  }
View Full Code Here

  @Configuration
  public static class FixedReplyQueueConfig {

    @Bean
    public ConnectionFactory rabbitConnectionFactory() {
      CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
      connectionFactory.setHost("localhost");
      return connectionFactory;
    }
View Full Code Here

  private SimpleMessageListenerContainer container;

  @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());
    admin.declareQueue(queue);
    admin.deleteQueue(queue1.getName());
View Full Code Here

  private MessageConverter messageConverter;

  private RabbitTemplate createTemplate(int concurrentConsumers) {
    RabbitTemplate template = new RabbitTemplate();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setChannelCacheSize(concurrentConsumers);
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
    if (messageConverter == null) {
      SimpleMessageConverter messageConverter = new SimpleMessageConverter();
      messageConverter.setCreateMessageIds(true);
      this.messageConverter = messageConverter;
View Full Code Here

  @Test
  public void testTransactionalLowLevel() throws Exception {

    RabbitTemplate template = new RabbitTemplate();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);

    BlockingQueueConsumer blockingQueueConsumer = new BlockingQueueConsumer(connectionFactory,
        new DefaultMessagePropertiesConverter(), new ActiveObjectCounter<BlockingQueueConsumer>(),
        AcknowledgeMode.AUTO, true, 1, queue.getName());
    blockingQueueConsumer.start();

    // TODO: make this into a proper assertion. An exception can be thrown here by the Rabbit client and printed to
    // stderr without being rethrown (so hard to make a test fail).
    blockingQueueConsumer.stop();
    assertNull(template.receiveAndConvert(queue.getName()));
    connectionFactory.destroy();

  }
View Full Code Here

    // Rabbit infrastructure setup

    @Bean
    public ConnectionFactory rabbitConnectionFactory() {
      CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
      connectionFactory.setHost("localhost");
      return connectionFactory;
    }
View Full Code Here

    ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
    Connection mockConnection = mock(Connection.class);
    final Channel onlyChannel = mock(Channel.class);
    when(onlyChannel.isOpen()).thenReturn(true);

    final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);

    final AtomicReference<Exception> tooManyChannels = new AtomicReference<Exception>();
View Full Code Here

    }
    else {
      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));
      }

    }
    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);

  }
View Full Code Here

  @Rule
  public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue);

  @Before
  public void createConnectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setChannelCacheSize(concurrentConsumers);
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.connection.CachingConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.