Search in sources :

Example 1 with Connection

use of org.akhq.configs.Connection in project akhq by tchiotludo.

the class KafkaModule method getRegistryClient.

public SchemaRegistryClient getRegistryClient(String clusterId) {
    if (!this.registryClient.containsKey(clusterId)) {
        Connection connection = this.getConnection(clusterId);
        List<SchemaProvider> providers = new ArrayList<>();
        providers.add(new AvroSchemaProvider());
        providers.add(new JsonSchemaProvider());
        providers.add(new ProtobufSchemaProvider());
        SchemaRegistryClient client = new CachedSchemaRegistryClient(this.getRegistryRestClient(clusterId), 1000, providers, connection.getSchemaRegistry() != null ? connection.getSchemaRegistry().getProperties() : null, null);
        this.registryClient.put(clusterId, client);
    }
    return this.registryClient.get(clusterId);
}
Also used : JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) Connection(org.akhq.configs.Connection) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)

Example 2 with Connection

use of org.akhq.configs.Connection in project akhq by tchiotludo.

the class KafkaModule method getConnectRestClient.

public Map<String, KafkaConnectClient> getConnectRestClient(String clusterId) {
    if (!this.connectRestClient.containsKey(clusterId)) {
        Connection connection = this.getConnection(clusterId);
        if (connection.getConnect() != null && !connection.getConnect().isEmpty()) {
            Map<String, KafkaConnectClient> mapConnects = new HashMap<>();
            connection.getConnect().forEach(connect -> {
                URIBuilder uri = URIBuilder.fromString(connect.getUrl().toString());
                Configuration configuration = new Configuration(uri.toNormalizedURI(false).toString());
                if (connect.getBasicAuthUsername() != null) {
                    configuration.useBasicAuth(connect.getBasicAuthUsername(), connect.getBasicAuthPassword());
                }
                if (connect.getSslTrustStore() != null) {
                    configuration.useTrustStore(new File(connect.getSslTrustStore()), connect.getSslTrustStorePassword());
                }
                if (connect.getSslKeyStore() != null) {
                    configuration.useKeyStore(new File(connect.getSslKeyStore()), connect.getSslKeyStorePassword());
                }
                mapConnects.put(connect.getName(), new KafkaConnectClient(configuration));
            });
            this.connectRestClient.put(clusterId, mapConnects);
        }
    }
    return this.connectRestClient.get(clusterId);
}
Also used : KafkaConnectClient(org.sourcelab.kafka.connect.apiclient.KafkaConnectClient) Configuration(org.sourcelab.kafka.connect.apiclient.Configuration) Connection(org.akhq.configs.Connection) File(java.io.File) URIBuilder(org.codehaus.httpcache4j.uri.URIBuilder)

Example 3 with Connection

use of org.akhq.configs.Connection in project akhq by tchiotludo.

the class KafkaModule method getRegistryRestClient.

public RestService getRegistryRestClient(String clusterId) {
    Connection connection = this.getConnection(clusterId);
    if (connection.getSchemaRegistry() != null) {
        RestService restService = new RestService(connection.getSchemaRegistry().getUrl());
        if (connection.getSchemaRegistry().getProperties() != null && !connection.getSchemaRegistry().getProperties().isEmpty()) {
            Map<String, Object> sslConfigs = connection.getSchemaRegistry().getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("schema.registry.")).collect(Collectors.toMap(e -> e.getKey().substring("schema.registry.".length()), Map.Entry::getValue));
            SslFactory sslFactory = new SslFactory(sslConfigs);
            if (sslFactory != null && sslFactory.sslContext() != null) {
                restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
            }
        }
        restService.setHttpHeaders(Collections.singletonMap("Accept", "application/json"));
        if (connection.getSchemaRegistry().getBasicAuthUsername() != null) {
            BasicAuthCredentialProvider basicAuthCredentialProvider = BasicAuthCredentialProviderFactory.getBasicAuthCredentialProvider(new UserInfoCredentialProvider().alias(), ImmutableMap.of("schema.registry.basic.auth.user.info", connection.getSchemaRegistry().getBasicAuthUsername() + ":" + connection.getSchemaRegistry().getBasicAuthPassword()));
            restService.setBasicAuthCredentialProvider(basicAuthCredentialProvider);
        }
        if (connection.getSchemaRegistry().getProperties() != null) {
            restService.configure(connection.getSchemaRegistry().getProperties());
        }
        return restService;
    }
    return null;
}
Also used : AbstractProperties(org.akhq.configs.AbstractProperties) java.util(java.util) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) Default(org.akhq.configs.Default) AdminClient(org.apache.kafka.clients.admin.AdminClient) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) URIBuilder(org.codehaus.httpcache4j.uri.URIBuilder) JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) Configuration(org.sourcelab.kafka.connect.apiclient.Configuration) ImmutableMap(com.google.common.collect.ImmutableMap) KafkaConnectClient(org.sourcelab.kafka.connect.apiclient.KafkaConnectClient) Singleton(jakarta.inject.Singleton) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) Collectors(java.util.stream.Collectors) File(java.io.File) BasicAuthCredentialProviderFactory(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory) Connection(org.akhq.configs.Connection) UserInfoCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) Inject(jakarta.inject.Inject) SslFactory(io.confluent.kafka.schemaregistry.client.security.SslFactory) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) BasicAuthCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider) UserInfoCredentialProvider(io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider) Connection(org.akhq.configs.Connection) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) ImmutableMap(com.google.common.collect.ImmutableMap) SslFactory(io.confluent.kafka.schemaregistry.client.security.SslFactory)

Aggregations

Connection (org.akhq.configs.Connection)3 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)2 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)2 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)2 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)2 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)2 File (java.io.File)2 URIBuilder (org.codehaus.httpcache4j.uri.URIBuilder)2 Configuration (org.sourcelab.kafka.connect.apiclient.Configuration)2 KafkaConnectClient (org.sourcelab.kafka.connect.apiclient.KafkaConnectClient)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)1 SslFactory (io.confluent.kafka.schemaregistry.client.security.SslFactory)1 BasicAuthCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProvider)1 BasicAuthCredentialProviderFactory (io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialProviderFactory)1 UserInfoCredentialProvider (io.confluent.kafka.schemaregistry.client.security.basicauth.UserInfoCredentialProvider)1 Inject (jakarta.inject.Inject)1 Singleton (jakarta.inject.Singleton)1 java.util (java.util)1