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
Apache kafka Vertx Kafka使用者异常处理问题_Apache Kafka_Vert.x - Fatal编程技术网

Apache kafka Vertx Kafka使用者异常处理问题

Apache kafka Vertx Kafka使用者异常处理问题,apache-kafka,vert.x,Apache Kafka,Vert.x,一旦使用者无法反序列化请求,kafka就不会使用来自生产者的下一个请求。生产者能够发送请求,但消费者由于异常而无法接收请求。我希望kafka使用请求,即使存在异常,它也不应该阻止后续请求 @Component public class PrometheusConsumer extends AbstractVerticle { private KafkaConsumer<String, String> prometheusConsumer; private final

一旦使用者无法反序列化请求,kafka就不会使用来自生产者的下一个请求。生产者能够发送请求,但消费者由于异常而无法接收请求。我希望kafka使用请求,即使存在异常,它也不应该阻止后续请求

@Component
public class PrometheusConsumer extends AbstractVerticle {

    private KafkaConsumer<String, String> prometheusConsumer;
    private final KafkaConfig kafkaConfig;

    public PrometheusConsumer(KafkaConfig kafkaConfig) {
        this.kafkaConfig = kafkaConfig;
    }

    @Override
    public void start(Promise<Void> startPromise)  {
        configureConsumer();
        this.prometheusConsumer.handler(record -> {
            Dummy dummy = Json.decodeValue(record.value(), Dummy.class);
            System.out.println("Processing key=" + record.key() + ",value=" + record.value() +
                    ",partition=" + record.partition() + ",offset=" + record.offset());

        }).exceptionHandler(ex->{
            System.out.println("EXCEPTION HANDLED IN CONSUMER: "+ex.getMessage());
        });


//
    }

    private void configureConsumer() {
        this.prometheusConsumer = KafkaConsumer.create(vertx, kafkaConfig.getConsumerConfig());
        prometheusConsumer.subscribe("dummy-topic", ar -> {
            if (ar.succeeded()) {
                System.out.println("dummy-topic consumer subscribed");
            }
        });

        this.vertx.exceptionHandler(handler->{
            System.err.println("EXCEPTION OCCURED WHILE CONSUMING");
        });
    }

}


        router.route("/").handler(StaticHandler.create().setCachingEnabled(false));

        try {
            router.get("/info").handler(routingContext -> {

                Person p = new Person();
                p.setName("test");
                p.setEmail("test@gmail.com");
                ObjectMapper mapper = new ObjectMapper();
                String s = null;

                try {
                    s = mapper.writeValueAsString(p);
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                }

                KafkaProducerRecord<String, JsonObject> producerRecord = KafkaProducerRecord.create("dummy-topic", new JsonObject(s));
                producer.send(producerRecord, handler -> {
                    System.out.println("Producer sent the request");
                    if (handler.succeeded()) {
                        System.out.println("kafka success");
                    }
                });
                kafkaCounter.inc();
                routingContext.response().end("aaa");
            });
@组件
公共类PrometheusConsumer扩展了AbstractVerticle{
私人卡夫卡消费者;
私人最终卡夫卡尼菲卡夫卡尼菲;
公共活尸消费者(卡夫卡尼菲卡夫卡尼菲){
this.kafkanconfig=kafkanconfig;
}
@凌驾
公共无效启动(承诺启动建议){
配置消费者();
this.prometheusConsumer.handler(记录->{
Dummy Dummy=Json.decodeValue(record.value(),Dummy.class);
System.out.println(“处理键=“+record.key()+”,value=“+record.value())+
“,partition=“+record.partition()+”,offset=“+record.offset());
}).例外处理程序(ex->{
System.out.println(“在使用者中处理的异常:+ex.getMessage());
});
//
}
私有void configureConsumer(){
this.prometheusConsumer=KafkaConsumer.create(vertx,kafkaConfig.getConsumerConfig());
prometheusConsumer.subscribe(“虚拟主题”,ar->{
如果(ar.successed()){
System.out.println(“虚拟主题消费者订阅”);
}
});
this.vertx.exceptionHandler(处理程序->{
System.err.println(“消费时发生异常”);
});
}
}
router.route(“/”).handler(StaticHandler.create().setCachingEnabled(false));
试一试{
router.get(“/info”).handler(routingContext->{
人员p=新人员();
p、 设置名称(“测试”);
p、 设置电子邮件(“test@gmail.com");
ObjectMapper mapper=新的ObjectMapper();
字符串s=null;
试一试{
s=mapper.writeValueAsString(p);
}捕获(JsonProcessingException e){
e、 printStackTrace();
}
KafkaProducerRecord producerRecord=KafkaProducerRecord.create(“虚拟主题”,新JsonObject));
producer.send(producerRecord,handler->{
System.out.println(“生产者发送请求”);
if(handler.successed()){
System.out.println(“卡夫卡成功”);
}
});
卡夫卡计数器公司();
routingContext.response().end(“aaa”);
});
您检查过这个吗-