Java Code Examples for org.springframework.amqp.rabbit.connection.CachingConnectionFactory#setCacheMode()

The following examples show how to use org.springframework.amqp.rabbit.connection.CachingConnectionFactory#setCacheMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitServiceAutoConfiguration.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
static void configureCachingConnectionFactory(
		CachingConnectionFactory connectionFactory,
		ConfigurableApplicationContext applicationContext,
		RabbitProperties rabbitProperties) throws Exception {

	if (StringUtils.hasText(rabbitProperties.getAddresses())) {
		connectionFactory.setAddresses(rabbitProperties.determineAddresses());
	}

	connectionFactory.setPublisherConfirmType(rabbitProperties.getPublisherConfirmType() == null ? ConfirmType.NONE : rabbitProperties.getPublisherConfirmType());
	connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns());
	if (rabbitProperties.getCache().getChannel().getSize() != null) {
		connectionFactory.setChannelCacheSize(
				rabbitProperties.getCache().getChannel().getSize());
	}
	if (rabbitProperties.getCache().getConnection().getMode() != null) {
		connectionFactory
				.setCacheMode(rabbitProperties.getCache().getConnection().getMode());
	}
	if (rabbitProperties.getCache().getConnection().getSize() != null) {
		connectionFactory.setConnectionCacheSize(
				rabbitProperties.getCache().getConnection().getSize());
	}
	if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) {
		connectionFactory.setChannelCheckoutTimeout(rabbitProperties.getCache()
				.getChannel().getCheckoutTimeout().toMillis());
	}
	connectionFactory.setApplicationContext(applicationContext);
	applicationContext.addApplicationListener(connectionFactory);
	connectionFactory.afterPropertiesSet();
}
 
Example 2
Source File: RabbitAutoConfiguration.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config) throws Exception {
    RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
    if (config.determineHost() != null) {
        factory.setHost(config.determineHost());
    }
    factory.setPort(config.determinePort());
    if (config.determineUsername() != null) {
        factory.setUsername(config.determineUsername());
    }
    if (config.determinePassword() != null) {
        factory.setPassword(config.determinePassword());
    }
    if (config.determineVirtualHost() != null) {
        factory.setVirtualHost(config.determineVirtualHost());
    }
    if (config.getRequestedHeartbeat() != null) {
        factory.setRequestedHeartbeat(config.getRequestedHeartbeat());
    }
    RabbitProperties.Ssl ssl = config.getSsl();
    if (ssl.isEnabled()) {
        factory.setUseSSL(true);
        if (ssl.getAlgorithm() != null) {
            factory.setSslAlgorithm(ssl.getAlgorithm());
        }
        factory.setKeyStore(ssl.getKeyStore());
        factory.setKeyStorePassphrase(ssl.getKeyStorePassword());
        factory.setTrustStore(ssl.getTrustStore());
        factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
    }
    if (config.getConnectionTimeout() != null) {
        factory.setConnectionTimeout(config.getConnectionTimeout());
    }
    factory.afterPropertiesSet();
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(factory.getObject());
    connectionFactory.setAddresses(config.determineAddresses());
    connectionFactory.setPublisherConfirms(config.isPublisherConfirms());
    connectionFactory.setPublisherReturns(config.isPublisherReturns());
    if (config.getCache().getChannel().getSize() != null) {
        connectionFactory.setChannelCacheSize(config.getCache().getChannel().getSize());
    }
    if (config.getCache().getConnection().getMode() != null) {
        connectionFactory.setCacheMode(config.getCache().getConnection().getMode());
    }
    if (config.getCache().getConnection().getSize() != null) {
        connectionFactory.setConnectionCacheSize(config.getCache().getConnection().getSize());
    }
    if (config.getCache().getChannel().getCheckoutTimeout() != null) {
        connectionFactory.setChannelCheckoutTimeout(config.getCache().getChannel().getCheckoutTimeout());
    }
    return connectionFactory;
}