io.quarkiverse.reactive.messaging.nats.jetstream.client.configuration.DefaultConnectionConfiguration Maven / Gradle / Ivy
package io.quarkiverse.reactive.messaging.nats.jetstream.client.configuration;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.util.Optional;
import io.nats.client.ErrorListener;
import io.quarkiverse.reactive.messaging.nats.NatsConfiguration;
import io.quarkiverse.reactive.messaging.nats.jetstream.mapper.DefaultPayloadMapper;
class DefaultConnectionConfiguration implements ConnectionConfiguration {
private final NatsConfiguration configuration;
DefaultConnectionConfiguration(NatsConfiguration configuration) {
this.configuration = configuration;
}
@Override
public String servers() {
return configuration.servers();
}
@Override
public Optional password() {
return configuration.password();
}
@Override
public Optional username() {
return configuration.username();
}
@Override
public Optional token() {
return configuration.token();
}
@Override
public Optional credentialPath() {
return configuration.credentialPath();
}
@Override
public boolean sslEnabled() {
return configuration.sslEnabled();
}
@Override
public Optional bufferSize() {
return configuration.bufferSize();
}
@Override
public Optional errorListener() {
return configuration.errorListener().map(this::getInstanceOfErrorListener);
}
@Override
public Optional connectionTimeout() {
return configuration.connectionTimeout();
}
@Override
public Optional keystorePath() {
return configuration.keystorePath();
}
@Override
public Optional keystorePassword() {
return configuration.keystorePassword();
}
@Override
public Optional truststorePath() {
return configuration.truststorePath();
}
@Override
public Optional truststorePassword() {
return configuration.truststorePassword();
}
@Override
public Optional tlsAlgorithm() {
return configuration.tlsAlgorithm();
}
@Override
public Optional connectionBackoff() {
return configuration.connectionBackoff();
}
@Override
public Optional connectionAttempts() {
return configuration.connectionAttempts();
}
private ErrorListener getInstanceOfErrorListener(String className) {
try {
var clazz = DefaultPayloadMapper.loadClass(className);
var constructor = clazz.getConstructor();
return (ErrorListener) constructor.newInstance();
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException
| InvocationTargetException e) {
throw new RuntimeException("Not able to create instance of error listener", e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy