kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-6053; Fix NoSuchMethodError when creating ProducerRecords with older client versions
Date Thu, 12 Oct 2017 09:05:25 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk f6e724b12 -> bdf8e211e


KAFKA-6053; Fix NoSuchMethodError when creating ProducerRecords with older client versions

Author: Apurva Mehta <apurva@confluent.io>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes #4057 from apurvam/KAFKA-6053-fix-no-such-method-error-in-producer-record


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/bdf8e211
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/bdf8e211
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/bdf8e211

Branch: refs/heads/trunk
Commit: bdf8e211ecb50a24071390d493cf1c1732f7346d
Parents: f6e724b
Author: Apurva Mehta <apurva@confluent.io>
Authored: Thu Oct 12 10:05:14 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Thu Oct 12 10:05:14 2017 +0100

----------------------------------------------------------------------
 .../org/apache/kafka/tools/VerifiableProducer.java     | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/bdf8e211/tools/src/main/java/org/apache/kafka/tools/VerifiableProducer.java
----------------------------------------------------------------------
diff --git a/tools/src/main/java/org/apache/kafka/tools/VerifiableProducer.java b/tools/src/main/java/org/apache/kafka/tools/VerifiableProducer.java
index 8de115f..975cba7 100644
--- a/tools/src/main/java/org/apache/kafka/tools/VerifiableProducer.java
+++ b/tools/src/main/java/org/apache/kafka/tools/VerifiableProducer.java
@@ -229,9 +229,18 @@ public class VerifiableProducer {
 
     /** Produce a message with given key and value. */
     public void send(String key, String value) {
-        ProducerRecord<String, String> record = new ProducerRecord<>(topic, null,
createTime, key, value);
-        if (createTime != null)
+        ProducerRecord<String, String> record;
+
+        // Older versions of ProducerRecord don't include the message create time in the
constructor. So including
+        // even a 'null' argument results in a NoSuchMethodException. Thus we only include
the create time if it is
+        // explicitly specified to remain fully backward compatible with older clients.
+        if (createTime != null) {
+            record = new ProducerRecord<>(topic, null, createTime, key, value);
             createTime += System.currentTimeMillis() - startTime;
+        } else {
+            record = new ProducerRecord<>(topic, key, value);
+        }
+
         numSent++;
         try {
             producer.send(record, new PrintInfoCallback(key, value));


Mime
View raw message