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

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

Introduction

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

Prototype

public void setPassword(String password) 

Source Link

Usage

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

@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {/*from   www .j  a v a 2 s  .  com*/
        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  ava  2 s .c o m*/
    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: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:io.acme.solution.query.conf.EventBusConfigurer.java

@Bean
public ConnectionFactory eventBusConnectionFactory() {

    log.info("Creating query event bus connection on hostname: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}

From source file:io.acme.solution.application.conf.CommandBusConfigurer.java

@Bean
public ConnectionFactory commandBusConnectionFactory() {

    log.info("Creating command bus connection on hostname: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}

From source file:org.openbaton.nse.api.EventReceiver.java

@Bean
public ConnectionFactory getConnectionFactory(Environment env) {
    logger.debug("Created ConnectionFactory");
    CachingConnectionFactory factory = new CachingConnectionFactory(rabbitMQProperties.getHost());
    factory.setPassword(rabbitMQProperties.getPassword());
    factory.setUsername(rabbitMQProperties.getUsername());
    return factory;
}

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:org.opentestsystem.delivery.logging.RabbitConfiguration.java

@Bean
public ConnectionFactory connectionFactory() {
    final CachingConnectionFactory factory = new CachingConnectionFactory(determineHost());
    if (isNotBlank(addresses)) {
        factory.setAddresses(addresses);
    }/*  w w  w  .  ja  v  a2s .c om*/
    factory.setPort(port);
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setVirtualHost(vhost);
    return factory;
}

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

/**
 * Create a dedicated connection factory for the address.
 * @param address the address to which the factory should connect.
 * @param node  the node./*from   w  w  w  .  java  2 s.  co  m*/
 * @return the connection factory.
 * @throws Exception if errors occur during creation.
 */
protected ConnectionFactory createConnectionFactory(String address, String node) throws Exception {
    RabbitConnectionFactoryBean rcfb = new RabbitConnectionFactoryBean();
    rcfb.setUseSSL(this.useSSL);
    rcfb.setSslPropertiesLocation(this.sslPropertiesLocation);
    rcfb.setKeyStore(this.keyStore);
    rcfb.setTrustStore(this.trustStore);
    rcfb.setKeyStorePassphrase(this.keyStorePassPhrase);
    rcfb.setTrustStorePassphrase(this.trustStorePassPhrase);
    rcfb.afterPropertiesSet();
    CachingConnectionFactory ccf = new CachingConnectionFactory(rcfb.getObject());
    ccf.setAddresses(address);
    ccf.setUsername(this.username);
    ccf.setPassword(this.password);
    ccf.setVirtualHost(this.vhost);
    ccf.setBeanName("node:" + node);
    return ccf;
}

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);//  w w w  .  j  ava 2s .c o  m

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