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

com.datasift.dropwizard.kafka.producer.InstrumentedProducer Maven / Gradle / Ivy

The newest version!
package com.datasift.dropwizard.kafka.producer;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;

import java.util.List;

/**
 * A {@link Producer} that is instrumented with metrics.
 */
public class InstrumentedProducer implements KafkaProducer {

    private final Producer underlying;
    private final Meter sentMessages;

    public InstrumentedProducer(final Producer underlying,
                                final MetricRegistry registry,
                                final String name) {
        this.underlying = underlying;
        this.sentMessages = registry.meter(MetricRegistry.name(name, "sent"));
    }

    public void send(final KeyedMessage message) {
        underlying.send(message);
        sentMessages.mark();
    }

    public void send(final List> messages) {
        underlying.send(messages);
        sentMessages.mark(messages.size());
    }

    public void close() {
        underlying.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy