All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.kafka.health.KafkaProducerHealthCheck Maven / Gradle / Ivy

package io.dropwizard.kafka.health;

import com.codahale.metrics.health.HealthCheck;
import org.apache.kafka.clients.producer.Producer;

import java.util.Collection;

import static java.util.Objects.requireNonNull;

public class KafkaProducerHealthCheck extends HealthCheck {

    private final Producer producer;
    private final Collection topics;

    public KafkaProducerHealthCheck(final Producer producer,
                                    final Collection topics) {
        this.producer = requireNonNull(producer);
        this.topics = requireNonNull(topics);
    }

    @Override
    protected Result check() {
        try {
            topics.forEach(producer::partitionsFor);
            return Result.healthy();
        } catch (final Exception e) {
            return Result.unhealthy(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy