/** * Creates a {@link ConnectionFactory} using the singleton service connector. * @param cloud {@link Cloud} instance to be used for accessing services. * @param connectorConfigObjectProvider the {@link ObjectProvider} for the * {@link RabbitConnectionFactoryConfig}. * @return the {@link ConnectionFactory} used by the binder. */ @Bean @Primary ConnectionFactory rabbitConnectionFactory(Cloud cloud, ObjectProvider<RabbitConnectionFactoryConfig> connectorConfigObjectProvider, ConfigurableApplicationContext applicationContext, RabbitProperties rabbitProperties) throws Exception { ConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(ConnectionFactory.class, connectorConfigObjectProvider.getIfUnique()); configureCachingConnectionFactory((CachingConnectionFactory) connectionFactory, applicationContext, rabbitProperties); return connectionFactory; }
static void configureCachingConnectionFactory(CachingConnectionFactory connectionFactory, ConfigurableApplicationContext applicationContext, RabbitProperties rabbitProperties) throws Exception { if (StringUtils.hasText(rabbitProperties.getAddresses())) { connectionFactory.setAddresses(rabbitProperties.determineAddresses()); } connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms()); 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()); } connectionFactory.setApplicationContext(applicationContext); applicationContext.addApplicationListener(connectionFactory); connectionFactory.afterPropertiesSet(); }
public RabbitMessageChannelBinder(ConnectionFactory connectionFactory, RabbitProperties rabbitProperties, RabbitExchangeQueueProvisioner provisioningProvider) { super(new String[0], provisioningProvider); Assert.notNull(connectionFactory, "connectionFactory must not be null"); Assert.notNull(rabbitProperties, "rabbitProperties must not be null"); this.connectionFactory = connectionFactory; this.rabbitProperties = rabbitProperties; }
@Override protected RabbitTestBinder getBinder() { if (this.testBinder == null) { RabbitProperties rabbitProperties = new RabbitProperties(); rabbitProperties.setPublisherConfirms(true); rabbitProperties.setPublisherReturns(true); this.testBinder = new RabbitTestBinder(rabbitAvailableRule.getResource(), rabbitProperties); } return this.testBinder; }
public RabbitMqSetupService(RabbitProperties properties) { hostname = properties.getHost(); username = properties.getUsername(); if (StringUtils.isEmpty(username)) { username = DEFAULT_USER; } password = properties.getPassword(); if (StringUtils.isEmpty(password)) { password = DEFAULT_PASSWORD; } }
@Bean Sender rabbitSender(CachingConnectionFactory connectionFactory, RabbitProperties config) { return RabbitMQSender.newBuilder() .connectionFactory(connectionFactory.getRabbitConnectionFactory()) .queue(this.queue) .addresses(config.determineAddresses()) .build(); }
/** * @see org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration.RabbitConnectionFactoryCreator */ private CachingConnectionFactory buildProducerConnectionFactory() throws Exception { com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory; if (this.rabbitConnectionFactory instanceof CachingConnectionFactory) { rabbitConnectionFactory = ((CachingConnectionFactory) this.rabbitConnectionFactory) .getRabbitConnectionFactory(); } else { RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean(); String host = this.rabbitProperties.determineHost(); if (host != null) { factory.setHost(host); } factory.setPort(this.rabbitProperties.determinePort()); String user = this.rabbitProperties.determineUsername(); if (user != null) { factory.setUsername(user); } String password = this.rabbitProperties.determinePassword(); if (password != null) { factory.setPassword(password); } String vHost = this.rabbitProperties.determineVirtualHost(); if (vHost != null) { factory.setVirtualHost(vHost); } Duration requestedHeartbeatDuration = this.rabbitProperties.getRequestedHeartbeat(); if (requestedHeartbeatDuration != null) { factory.setRequestedHeartbeat((int) requestedHeartbeatDuration.getSeconds()); } RabbitProperties.Ssl ssl = this.rabbitProperties.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()); } Duration connectionTimeoutDuration = this.rabbitProperties.getConnectionTimeout(); if (connectionTimeoutDuration != null) { factory.setConnectionTimeout((int) connectionTimeoutDuration.getSeconds()); } factory.afterPropertiesSet(); rabbitConnectionFactory = factory.getObject(); } CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitConnectionFactory); RabbitServiceAutoConfiguration.configureCachingConnectionFactory(connectionFactory, this.applicationContext, this.rabbitProperties); return connectionFactory; }
public RabbitTestBinder(ConnectionFactory connectionFactory, RabbitProperties rabbitProperties) { this(connectionFactory, new RabbitMessageChannelBinder(connectionFactory, rabbitProperties, new RabbitExchangeQueueProvisioner(connectionFactory))); }
public RabbitMQManagement(RabbitProperties rabbitProperties, RabbitMQResilienceHealthProperties rabbitMQResilienceHealthProperties) { this.rabbitProperties = rabbitProperties; this.rabbitMQResilienceHealthProperties = rabbitMQResilienceHealthProperties; }
@Bean RabbitMqSetupService rabbitmqSetupService(RabbitProperties properties) { return new RabbitMqSetupService(properties); }