datahub.client.kafka.KafkaEmitterConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datahub-client Show documentation
Show all versions of datahub-client Show documentation
DataHub Java client for metadata integration
package datahub.client.kafka;
import datahub.event.EventFormatter;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.function.Consumer;
import lombok.Builder;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
@Value
@Builder
@Slf4j
public class KafkaEmitterConfig {
public static final String CLIENT_VERSION_PROPERTY = "clientVersion";
@Builder.Default private final String bootstrap = "localhost:9092";
@Builder.Default private final String schemaRegistryUrl = "http://localhost:8081";
@Builder.Default private final Map schemaRegistryConfig = Collections.emptyMap();
@Builder.Default private final Map producerConfig = Collections.emptyMap();
@Builder.Default
private final EventFormatter eventFormatter =
new EventFormatter(EventFormatter.Format.PEGASUS_JSON);
public static class KafkaEmitterConfigBuilder {
@SuppressWarnings("unused")
private String getVersion() {
try (InputStream foo =
this.getClass().getClassLoader().getResourceAsStream("client.properties")) {
Properties properties = new Properties();
properties.load(foo);
return properties.getProperty(CLIENT_VERSION_PROPERTY, "unknown");
} catch (Exception e) {
log.warn("Unable to find a version for datahub-client. Will set to unknown", e);
return "unknown";
}
}
public KafkaEmitterConfigBuilder with(Consumer builderFunction) {
builderFunction.accept(this);
return this;
}
}
}