Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Kafka Producer发送方法在发送avro记录时被阻塞_Java_Apache Kafka_Kafka Producer Api_Confluent Platform - Fatal编程技术网

Java Kafka Producer发送方法在发送avro记录时被阻塞

Java Kafka Producer发送方法在发送avro记录时被阻塞,java,apache-kafka,kafka-producer-api,confluent-platform,Java,Apache Kafka,Kafka Producer Api,Confluent Platform,如果我试图传输来自GenericRecord类型的avro记录,为什么我的代码在KafkaProducer.send()上执行受阻? 如果我将avro记录转换为字符串,则一切正常 查看两个代码片段(第一个发送avro记录,第二个只发送字符串)-我做错了什么吗 //sending AVRO records to KAFKA public kafka_facade() { this.registryUrl = Main.getFSMObject().getCfg().

如果我试图传输来自GenericRecord类型的avro记录,为什么我的代码在KafkaProducer.send()上执行受阻? 如果我将avro记录转换为字符串,则一切正常

查看两个代码片段(第一个发送avro记录,第二个只发送字符串)-我做错了什么吗

 //sending AVRO records to KAFKA 
  public kafka_facade()
    {
        this.registryUrl = Main.getFSMObject().getCfg().getKafka_registryUrl();
        this.brokers = Main.getFSMObject().getCfg().getKafka_brokers();

        this.producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.brokers);
        this.producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        this.producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,  KafkaAvroSerializer.class.getName());
        this.producerProps.put("schema.registry.url",  this.registryUrl);

        this.kafka_producer = new KafkaProducer(this.producerProps);
    }
    public void dispatchToKafka(GenericRecord avroRecord)
    {
        try
        {
            String topic = Main.getManagerName();
            ProducerRecord<Object, Object> record = new ProducerRecord<>(topic, "key", avroRecord);
            this.kafka_producer.send(record).get(5, TimeUnit.SECONDS); // is blocking and never goes to next line - programm is stopping here
            //this.kafka_producer.send(record).get(); // blocks as well - programm is stopping here
            //this.kafka_producer.send(record); // blocks as well - programm is stopping here
        }
        catch (Exception ex)
        {
            this.logging.logException(ex);
        }
    }

//sending non AVRO records to KAFKA 
  public kafka_facade()
    {
        this.registryUrl = Main.getFSMObject().getCfg().getKafka_registryUrl();
        this.brokers = Main.getFSMObject().getCfg().getKafka_brokers();

        this.producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.brokers);
        this.producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        this.producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,  StringSerializer.class.getName());
        this.producerProps.put("schema.registry.url",  this.registryUrl);

        this.kafka_producer = new KafkaProducer(this.producerProps);
    }
    public void dispatchToKafka(GenericRecord avroRecord)
    {
        try
        {
            String topic = Main.getManagerName();
            ProducerRecord<Object, Object> record = new ProducerRecord<>(topic, "key", avroRecord.toString);
            this.kafka_producer.send(record); //works super!!
        }
        catch (Exception ex)
        {
            this.logging.logException(ex);
        }
    }
//向卡夫卡发送AVRO记录
公共卡夫卡博物馆门面()
{
this.registryUrl=Main.getFSMObject().getCfg().getKafka_registryUrl();
this.brokers=Main.getFSMObject().getCfg().getKafka_brokers();
this.producerProps.put(ProducerConfig.BOOTSTRAP\u SERVERS\u CONFIG,this.brokers);
this.producerProps.put(ProducerConfig.KEY\u SERIALIZER\u CLASS\u CONFIG,StringSerializer.CLASS.getName());
this.producerProps.put(ProducerConfig.VALUE\u SERIALIZER\u CLASS\u CONFIG,KafkaAvroSerializer.CLASS.getName());
this.producerProps.put(“schema.registry.url”,this.registryUrl);
this.kafka_producer=新卡夫卡制作人(this.producerProps);
}
公共无效调度Tokafka(通用记录和自动记录)
{
尝试
{
字符串topic=Main.getManagerName();
产品记录记录=新产品记录(主题“关键”,avroRecord);
这个.kafka_producer.send(record).get(5,TimeUnit.SECONDS);//被阻塞并且永远不会转到下一行-程序在这里停止
//这个.kafka_producer.send(record).get();//也是块-程序停止在这里
//this.kafka_producer.send(record);//也会阻塞—程序停止在这里
}
捕获(例外情况除外)
{
this.logging.logException(ex);
}
}
//向卡夫卡发送非AVRO记录
公共卡夫卡博物馆门面()
{
this.registryUrl=Main.getFSMObject().getCfg().getKafka_registryUrl();
this.brokers=Main.getFSMObject().getCfg().getKafka_brokers();
this.producerProps.put(ProducerConfig.BOOTSTRAP\u SERVERS\u CONFIG,this.brokers);
this.producerProps.put(ProducerConfig.KEY\u SERIALIZER\u CLASS\u CONFIG,StringSerializer.CLASS.getName());
this.producerProps.put(ProducerConfig.VALUE\u SERIALIZER\u CLASS\u CONFIG,StringSerializer.CLASS.getName());
this.producerProps.put(“schema.registry.url”,this.registryUrl);
this.kafka_producer=新卡夫卡制作人(this.producerProps);
}
公共无效调度Tokafka(通用记录和自动记录)
{
尝试
{
字符串topic=Main.getManagerName();
ProducerRecord记录=新的ProducerRecord(主题“key”,avroRecord.toString);
这个.kafka_制作人.send(record);//超级棒!!
}
捕获(例外情况除外)
{
this.logging.logException(ex);
}
}