0

I am trying to publish an Avro message to a Kafka topic using JMeter.

I get the below error message:

Caused by: javax.script.ScriptException: org.apache.kafka.common.errors.SerializationException: Error retrieving Avro schema"string"

I used the following code using JSR223 sampler.

KAFKA_BROKERS, KAFKA_TOPIC & MESSAGE are passed in User Defined variables.

import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

String brokers = vars.get("KAFKA_BROKERS");
String topic = vars.get("KAFKA_TOPIC");
String user = String.valueOf(ctx.getThreadNum() + 1);
Object msg = vars.get("MESSAGE");

Properties kafkaProps = new Properties();

kafkaProps.put("bootstrap.servers", brokers);
kafkaProps.put("schema.registry.url","https://\<\>");
kafkaProps.put("auto.register.schemas","false");
kafkaProps.put("basic.auth.credentials.source","USER_INFO");
kafkaProps.put("basic.auth.user.info","\<\>");
kafkaProps.put("security.protocol","SASL_SSL");
kafkaProps.put("sasl.mechanism","PLAIN");
kafkaProps.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
kafkaProps.put("value.serializer","io.confluent.kafka.serializers.KafkaAvroSerializer");
kafkaProps.put("sasl.jaas.config","org.apache.kafka.common.security.plain.PlainLoginModule required username='\<\>' password='\<\>';");

Producer\<String, Object\> producer = new KafkaProducer\<\>(kafkaProps);
try
{
producer.send(new ProducerRecord\<String, Object\>(topic, user, msg)).get();
}
finally
{
producer.close();
}

Getting the below error message:

Caused by: javax.script.ScriptException: org.apache.kafka.common.errors.SerializationException: Error retrieving Avro schema"string"

shakti
  • 1
  • 1

1 Answers1

0

You need to configure you kafkaProps object exactly the same way like it's done in your upstream system you're trying to mimic.

As a workaround you could enable auto schema registration like:

kafkaProps.put("auto.register.schemas","true");

More information: How to Do Kafka Testing With JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133