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);
}
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);
}
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;
}
Aggregations