use of com.rabbitmq.client.impl.DefaultCredentialsRefreshService in project smallrye-reactive-messaging by smallrye.
the class RabbitMQClientHelper method getClient.
static RabbitMQClient getClient(Vertx vertx, RabbitMQConnectorCommonConfiguration config, Instance<CredentialsProvider> credentialsProviders) {
try {
String host = config.getHost();
int port = config.getPort();
log.brokerConfigured(host, port, config.getChannel());
RabbitMQOptions options = new RabbitMQOptions().setHost(host).setPort(port).setSsl(config.getSsl()).setTrustAll(config.getTrustAll()).setAutomaticRecoveryEnabled(config.getAutomaticRecoveryEnabled()).setAutomaticRecoveryOnInitialConnection(config.getAutomaticRecoveryOnInitialConnection()).setReconnectAttempts(config.getReconnectAttempts()).setReconnectInterval(ofSeconds(config.getReconnectInterval()).toMillis()).setConnectionTimeout(config.getConnectionTimeout()).setHandshakeTimeout(config.getHandshakeTimeout()).setIncludeProperties(config.getIncludeProperties()).setNetworkRecoveryInterval(config.getNetworkRecoveryInterval()).setRequestedChannelMax(config.getRequestedChannelMax()).setRequestedHeartbeat(config.getRequestedHeartbeat()).setUseNio(config.getUseNio()).setVirtualHost(config.getVirtualHost());
// JKS TrustStore
Optional<String> trustStorePath = config.getTrustStorePath();
if (trustStorePath.isPresent()) {
JksOptions jks = new JksOptions();
jks.setPath(trustStorePath.get());
config.getTrustStorePassword().ifPresent(jks::setPassword);
options.setTrustStoreOptions(jks);
}
if (config.getCredentialsProviderName().isPresent()) {
String credentialsProviderName = config.getCredentialsProviderName().get();
credentialsProviders = credentialsProviders.select(Identifier.Literal.of(credentialsProviderName));
if (credentialsProviders.isUnsatisfied()) {
// this `if` block should be removed when support for the `@Named` annotation is removed
credentialsProviders = credentialsProviders.select(NamedLiteral.of(credentialsProviderName));
if (!credentialsProviders.isUnsatisfied()) {
ProviderLogging.log.deprecatedNamed();
}
}
if (!credentialsProviders.isResolvable()) {
throw ex.illegalStateFindingBean(CredentialsProvider.class.getName(), credentialsProviderName);
}
CredentialsProvider credentialsProvider = credentialsProviders.get();
options.setCredentialsProvider(credentialsProvider);
// To ease configuration, set up a "standard" refresh service
options.setCredentialsRefreshService(new DefaultCredentialsRefreshService(vertx.nettyEventLoopGroup(), ratioRefreshDelayStrategy(CREDENTIALS_PROVIDER_REFRESH_DELAY_RATIO), fixedTimeApproachingExpirationStrategy(CREDENTIALS_PROVIDER_APPROACH_EXPIRE_TIME)));
} else {
String username = config.getUsername().orElse(RabbitMQOptions.DEFAULT_USER);
String password = config.getPassword().orElse(RabbitMQOptions.DEFAULT_PASSWORD);
options.setUser(username);
options.setPassword(password);
}
return RabbitMQClient.create(vertx, options);
} catch (Exception e) {
log.unableToCreateClient(e);
throw ex.illegalStateUnableToCreateClient(e);
}
}
Aggregations