getPublisher();
}
@Override
protected void publish(MetricsScope scope, Iterator<MetricsRecord> metrics) throws Exception {
KafkaPublisher publisher = getPublisher();
if (publisher == null) {
LOG.warn("Unable to get kafka publisher, will not be able to publish metrics.");
return;
}
encoderOutputStream.reset();
KafkaPublisher.Preparer preparer = publisher.prepare(topicPrefix + "." + scope.name().toLowerCase());
while (metrics.hasNext()) {
// Encode each MetricRecord into bytes and make it an individual kafka message in a message set.
MetricsRecord record = metrics.next();
recordWriter.encode(record, encoder);
preparer.add(ByteBuffer.wrap(encoderOutputStream.toByteArray()), record.getContext());