com.datasift.dropwizard.kafka.producer.InstrumentedProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-extra-kafka Show documentation
Show all versions of dropwizard-extra-kafka Show documentation
Dropwizard integration for working with Kafka.
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();
}
}