Browse Source

KAFKA-1723 (delta patch to fix javadoc); make the metrics name in new producer more standard; patched by Manikumar Reddy; reviewed by Jun Rao

pull/38/merge
Manikumar Reddy 10 years ago committed by Jun Rao
parent
commit
a611178408
  1. 22
      clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
  2. 24
      clients/src/main/java/org/apache/kafka/common/MetricName.java

22
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java

@ -265,32 +265,32 @@ public class KafkaProducer<K,V> implements Producer<K,V> { @@ -265,32 +265,32 @@ public class KafkaProducer<K,V> implements Producer<K,V> {
* <p>
* If you want to simulate a simple blocking call you can do the following:
*
* <pre>
* producer.send(new ProducerRecord<byte[],byte[]>("the-topic", "key".getBytes(), "value".getBytes())).get();
* </pre>
* <pre>{@code
* producer.send(new ProducerRecord<byte[],byte[]>("the-topic", "key".getBytes(), "value".getBytes())).get();
* }</pre>
* <p>
* Those desiring fully non-blocking usage can make use of the {@link Callback} parameter to provide a callback that
* will be invoked when the request is complete.
*
* <pre>
* ProducerRecord<byte[],byte[]> record = new ProducerRecord<byte[],byte[]>("the-topic", "key".getBytes(), "value".getBytes());
* <pre>{@code
* ProducerRecord<byte[],byte[]> record = new ProducerRecord<byte[],byte[]>("the-topic", "key".getBytes(), "value".getBytes());
* producer.send(myRecord,
* new Callback() {
* new Callback() {
* public void onCompletion(RecordMetadata metadata, Exception e) {
* if(e != null)
* e.printStackTrace();
* System.out.println("The offset of the record we just sent is: " + metadata.offset());
* }
* });
* </pre>
* });
* }</pre>
*
* Callbacks for records being sent to the same partition are guaranteed to execute in order. That is, in the
* following example <code>callback1</code> is guaranteed to execute before <code>callback2</code>:
*
* <pre>
* producer.send(new ProducerRecord<byte[],byte[]>(topic, partition, key, value), callback1);
* <pre>{@code
* producer.send(new ProducerRecord<byte[],byte[]>(topic, partition, key1, value1), callback1);
* producer.send(new ProducerRecord<byte[],byte[]>(topic, partition, key2, value2), callback2);
* </pre>
* }</pre>
* <p>
* Note that callbacks will generally execute in the I/O thread of the producer and so should be reasonably fast or
* they will delay the sending of messages from other threads. If you want to execute blocking or computationally

24
clients/src/main/java/org/apache/kafka/common/MetricName.java

@ -19,34 +19,40 @@ import org.apache.kafka.common.utils.Utils; @@ -19,34 +19,40 @@ import org.apache.kafka.common.utils.Utils;
/**
* The <code>MetricName</code> class encapsulates a metric's name, logical group and its related attributes
* <p/>
* <p>
* This class captures the following parameters
* <pre>
* <b>name</b> The name of the metric
* <b>group</b> logical group name of the metrics to which this metric belongs.
* <b>description</b> A human-readable description to include in the metric. This is optional.
* <b>tags</b> additional key/value attributes of the metric. This is optional.
* </pre>
* </pre>
* group, tags parameters can be used to create unique metric names while reporting in JMX or any custom reporting.
*
* <p>
* Ex: standard JMX MBean can be constructed like <b>domainName:type=group,key1=val1,key2=val2</b>
*
* <p>
* Usage looks something like this:
* <pre>
* <pre>{@code
* // set up metrics:
* Metrics metrics = new Metrics(); // this is the global repository of metrics and sensors
* Sensor sensor = metrics.sensor(&quot;message-sizes&quot;);
* Sensor sensor = metrics.sensor("message-sizes");
*
* Map<String, String> metricTags = new LinkedHashMap<String, String>();
* metricTags.put("client-id", "producer-1");
* metricTags.put("topic", "topic");
* MetricName metricName = new MetricName(&quot;message-size-avg&quot;, &quot;producer-metrics&quot;, "average message size", metricTags);
*
* MetricName metricName = new MetricName("message-size-avg", "producer-metrics", "average message size", metricTags);
* sensor.add(metricName, new Avg());
* metricName = new MetricName(&quot;message-size-max&quot;, &quot;producer-metrics&quot;,metricTags);
*
* metricName = new MetricName("message-size-max", "producer-metrics", metricTags);
* sensor.add(metricName, new Max());
*
* metricName = new MetricName("message-size-min", "producer-metrics", "message minimum size", "client-id", "my-client", "topic", "my-topic");
* sensor.add(metricName, new Min());
*
* // as messages are sent we record the sizes
* sensor.record(messageSize);
* </pre>
* }</pre>
*/
public final class MetricName {

Loading…
Cancel
Save