Search in sources :

Example 1 with RabbitMQOptions

use of io.vertx.rabbitmq.RabbitMQOptions in project smallrye-reactive-messaging by smallrye.

the class RabbitMQProducers method getNamedOptions.

// <named>
@Produces
@Identifier("my-named-options")
public RabbitMQOptions getNamedOptions() {
    // You can use the produced options to configure the TLS connection
    PemKeyCertOptions keycert = new PemKeyCertOptions().addCertPath("./tls/tls.crt").addKeyPath("./tls/tls.key");
    PemTrustOptions trust = new PemTrustOptions().addCertPath("./tlc/ca.crt");
    return (RabbitMQOptions) new RabbitMQOptions().setUser("admin").setPassword("test").setSsl(true).setPemKeyCertOptions(keycert).setPemTrustOptions(trust).setHostnameVerificationAlgorithm("").setConnectTimeout(30000).setReconnectInterval(5000);
}
Also used : RabbitMQOptions(io.vertx.rabbitmq.RabbitMQOptions) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) Identifier(io.smallrye.common.annotation.Identifier) Produces(javax.enterprise.inject.Produces)

Example 2 with RabbitMQOptions

use of io.vertx.rabbitmq.RabbitMQOptions 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);
    }
}
Also used : RabbitMQOptions(io.vertx.rabbitmq.RabbitMQOptions) DefaultCredentialsRefreshService(com.rabbitmq.client.impl.DefaultCredentialsRefreshService) JksOptions(io.vertx.core.net.JksOptions) CredentialsProvider(com.rabbitmq.client.impl.CredentialsProvider)

Aggregations

RabbitMQOptions (io.vertx.rabbitmq.RabbitMQOptions)2 CredentialsProvider (com.rabbitmq.client.impl.CredentialsProvider)1 DefaultCredentialsRefreshService (com.rabbitmq.client.impl.DefaultCredentialsRefreshService)1 Identifier (io.smallrye.common.annotation.Identifier)1 JksOptions (io.vertx.core.net.JksOptions)1 PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)1 PemTrustOptions (io.vertx.core.net.PemTrustOptions)1 Produces (javax.enterprise.inject.Produces)1