Open shah-smit opened 3 years ago
Issue is tracked here: https://github.com/logstash-plugins/logstash-input-kafka/pull/239#issuecomment-734330093
I have tried externalising the particular failing script, but that particular is not throwing any error:
require 'faraday'
require 'json'
def test_schema_registry
client = Faraday.new("http://127.0.0.1:8081") do |conn|
puts conn
end
begin
response = client.get('/subjects')
registered_subjects = JSON.parse response.body
puts registered_subjects
expected_subjects = ["customer-avro"].map { |t| "#{t}-value"}
puts expected_subjects
if (expected_subjects & registered_subjects).size != expected_subjects.size
undefined_topic_subjects = expected_subjects - registered_subjects
puts "ERRPRRRRRRRR"
end
rescue Faraday::Error => e
raise LogStash::ConfigurationError.new("Schema registry service doesn't respond, error: #{e.message}")
end
end
test_schema_registry
Kafka Config for Producing the Message
import com.example.Customer;
import io.confluent.kafka.serializers.KafkaAvroSerializer;
import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.StringSerializer;
import java.util.Properties;
public class KafkaAvroJavaProducerV1Demo {
public static void main(String[] args) {
Properties properties = new Properties();
// normal producer
properties.setProperty("bootstrap.servers", "127.0.0.1:9092");
properties.setProperty("acks", "all");
properties.setProperty("retries", "10");
// avro part
properties.setProperty("key.serializer", StringSerializer.class.getName());
properties.setProperty("value.serializer", KafkaAvroSerializer.class.getName());
properties.setProperty("schema.registry.url", "http://127.0.0.1:8081");
Producer<String, Customer> producer = new KafkaProducer<String, Customer>(properties);
String topic = "customer-avro";
// copied from avro examples
Customer customer = Customer.newBuilder()
.setAge(3)
.setAutomatedEmail(true)
.setFirstName("Smit")
.setLastName("Shah")
.setHeight(181f)
.setWeight(100f)
.build();
ProducerRecord<String, Customer> producerRecord = new ProducerRecord<String, Customer>(
topic, customer
);
System.out.println(customer);
producer.send(producerRecord, new Callback() {
@Override
public void onCompletion(RecordMetadata metadata, Exception exception) {
if (exception == null) {
System.out.println(metadata);
} else {
exception.printStackTrace();
}
}
});
producer.flush();
producer.close();
}
}
logstash.conf.v1_5 file:
When running
I am getting below error:
Here is the way to get a schema registered under schema_registry:
Output:
Also, if particular schema,