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

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

Introduction

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

Prototype

public CachingConnectionFactory() 

Source Link

Document

Create a new CachingConnectionFactory initializing the hostname to be the value returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws an exception.

Usage

From source file:com.anton.dev.tqrbs2.basic.BasicJava.java

public static void main(String[] args) throws Exception {
    ConnectionFactory cf = new CachingConnectionFactory();

    // set up the queue, exchange, binding on the broker
    RabbitAdmin admin = new RabbitAdmin(cf);
    Queue queue = new Queue("myQueue");
    admin.declareQueue(queue);/*  ww  w .  j a  v a  2  s  .  c o  m*/
    TopicExchange exchange = new TopicExchange("myExchange2");
    admin.declareExchange(exchange);
    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*"));

    // set up the listener and container
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
    Object listener = new Object() {
        public void handleMessage(String foo) {
            LOGGER.info("Recibiendo Java: " + foo);
        }
    };
    MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
    container.setMessageListener(adapter);
    container.setQueueNames("myQueue");
    container.start();

    // send something
    RabbitTemplate template = new RabbitTemplate(cf);
    String msg = "Hello, world Rabbit!";
    LOGGER.info("Enviando Java: " + msg);
    template.convertAndSend("myExchange2", "foo.bar", msg);
    Thread.sleep(1000);
    container.stop();
}

From source file:amqp.spring.camel.component.SpringAMQPComponent.java

public SpringAMQPComponent() {
    this.connectionFactory = new CachingConnectionFactory();
}

From source file:io.manasobi.commons.config.AmqpConfig.java

@Bean
public ConnectionFactory rabbitConnectionFactory() {

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();

    connectionFactory.setAddresses("192.168.0.9");
    connectionFactory.setVirtualHost("manasobi-host");
    connectionFactory.setUsername("manasobi");
    connectionFactory.setPassword("manasobi");

    return connectionFactory;
}

From source file:amqp.spring.camel.component.SpringAMQPComponentTest.java

@Override
protected CamelContext createCamelContext() throws Exception {
    ConnectionFactory factory = new CachingConnectionFactory();

    CamelContext camelContext = super.createCamelContext();
    camelContext.addComponent("spring-amqp", new SpringAMQPComponent(factory));
    return camelContext;
}

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

@Bean
@Override//w w  w .  j ava 2 s.co  m
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.sample.amqp.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {//w  w  w .  j av a  2s  .  c  om
        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:vn.com.vndirect.api.service.SpringAMQP.java

protected CamelContext addAmqpCamelContext() throws Exception {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setAddresses(addressesAmqp);
    factory.setUsername(usernameAmqp);/*from   w w  w  .  j a v  a 2  s . c om*/
    factory.setPassword(passwordAmqp);
    factory.setPort(5672);
    RabbitTemplate amqpTemplate = new RabbitTemplate(factory);
    amqpTemplate.setMessageConverter(new JsonMessageConverter());
    SpringAMQPComponent amqpComponent = new SpringAMQPComponent(factory);
    amqpComponent.setAmqpTemplate(amqpTemplate);
    context.addComponent("spring-amqp", amqpComponent);
    return context;
}

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:acromusashi.stream.component.rabbitmq.AmqpTemplateFactoryTest.java

/**
 * ???// w ww.j ava2s .  c  o  m
 * 
 * @target {@link AmqpTemplateFactory#getAmqpTemplate(String)}
 * @test ???(??null:)
 *    condition:: ??:null
 *    result:: ????
 * 
 * @test ???(??null:)
 *    condition:: ??:null
 *    result:: ??????
 * 
 * @test ???(??:)
 *    condition:: ??:
 *    result:: ????
 * 
 * @test ???(??:)
 *    condition:: ??:
 *    result:: ??????
 * 
 * @test ???(????:??)
 *    condition:: ??:????
 *    result:: ??????
 * 
 * @test ???(????:ConnectionFactory?)
 *    condition:: ??:????
 *    result:: ??ConnectionFactory??????
 * 
 * @test ???(????:?)
 *    condition:: ??:????
 *    result:: 2???1?????????
 * 
 * @test ???(???????:)
 *    condition:: ??:???????
 *    result:: ????
 * 
 * @test ???(???????:)
 *    condition:: ??:???????
 *    result:: ??????
 */
@DataPoints
public static Fixture[] createFixture_QueueName() {
    List<Fixture> patterns = new ArrayList<Fixture>();

    // null
    patterns.add(new Fixture(null, new RabbitmqCommunicateException("QueueName is not defined.")));

    // 
    patterns.add(new Fixture("",
            new RabbitmqCommunicateException("QueueNames ProcessList is not defined. QueueName={0}")));

    // ????
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setChannelCacheSize(10);
    patterns.add(new Fixture(DEFINED_QUEUE_NAME, new RabbitTemplate(connectionFactory)));

    // ???????
    patterns.add(new Fixture(NON_DEFINED_QUEUE_NAME,
            new RabbitmqCommunicateException("QueueNames ProcessList is not defined. QueueName={0}")));

    return patterns.toArray(new Fixture[patterns.size()]);
}

From source file:amqp.spring.camel.component.SpringAMQPProducerTest.java

@Override
protected CamelContext createCamelContext() throws Exception {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    RabbitTemplate amqpTemplate = new RabbitTemplate(factory);
    SpringAMQPComponent amqpComponent = new SpringAMQPComponent(factory);
    amqpComponent.setAmqpTemplate(amqpTemplate);

    CamelContext camelContext = super.createCamelContext();
    camelContext.addComponent("spring-amqp", amqpComponent);
    return camelContext;
}