quarkus kafka流/React式消息传递反序列化异常

jm81lzqq  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(359)

嘿,所以我在尝试Kafka流和mpReact式消息传递,从Kafka主题中读取内容,然后再返回给它。
Kafka流错误-

org.apache.kafka.streams.errors.StreamsException: Deserialization exception handler is set to fail upon a deserialization error. If you would rather have the streaming pipeline continue after a deserialization error, please set the default.deserialization.exception.handler appropriately.

React式消息传递错误与此类似,但消息传递反序列化到的pojo基本上如下所示-

public class FinancialMessage {

    public String user_id;
    public String stock_symbol;
    public String exchange_id;
    public String trade_type;
    public String date_created;
    public String date_submitted;
    public int quantity;
    public double stock_price;
    public double total_cost;
    public int institution_id;
    public int country_id;
    public boolean compliance_services;
    public boolean technical_validation;
    public boolean schema_validation;
    public boolean business_validation;
    public boolean trade_enrichment;
   }

注意,有一个默认的空构造函数和一个包含所有字段的构造函数。

import java.time.Instant;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.Topology;
import org.apache.kafka.streams.kstream.Consumed;
import org.apache.kafka.streams.kstream.GlobalKTable;
import org.apache.kafka.streams.kstream.Materialized;
import org.apache.kafka.streams.kstream.Produced;
import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
import org.apache.kafka.streams.state.Stores;

import io.quarkus.kafka.client.serialization.JsonbSerde;
import io.quarkus.kafka.client.serialization.JsonbSerializer;

@ApplicationScoped
public class ComplianceTopology {

    private static final String KTABLE_TOPIC = "kstreams-ktable-topic";
    private static final String INCOMING_TOPIC = "kstreams-incoming-test";
    private static final String OUTGOING_TOPIC = "kstreams-outgoing-test";

    @Produces
    public Topology buildTopology() {

        StreamsBuilder builder = new StreamsBuilder();

        JsonbSerde<FinancialMessage> financialMessageSerde = new JsonbSerde<>(FinancialMessage.class);

        builder.stream(
            INCOMING_TOPIC,
            Consumed.with(Serdes.Integer(), financialMessageSerde)
        )
        .filter(
            (key, message) -> checkCompliance(message)
        )
        .mapValues (
            checkedMessage -> performComplianceCheck(checkedMessage)
        )
        .to (
            INCOMING_TOPIC,
            Produced.with(Serdes.Integer(), financialMessageSerde)
        );  

        return builder.build();
    }

    public boolean checkCompliance (FinancialMessage rawMessage) {
        return (rawMessage.compliance_services);
    }

    public FinancialMessage performComplianceCheck(FinancialMessage checkedMessage) {
        checkedMessage.compliance_services = false;

        return checkedMessage;
    }

}

然而,我猜它被称为“毒丸”,但是由mq生成的一条消息(有效负载为'aloha')会破坏它,我无法反序列化它。我猜原因是“aloha”不能被识别为字符串,因为它是单引号。我无法访问该数据的发送方式,因为它是通过mq发送的。有没有一种方法可以跳过处理这个不可反序列化的消息,直接从主题继续处理?

uemypmqf

uemypmqf1#

如错误消息所示

please set the default.deserialization.exception.handler appropriately

您可以配置不同的反序列化异常处理程序来跳过无法反序列化的消息。
查看文档了解更多详细信息:https://kafka.apache.org/documentation/streams/developer-guide/config-streams.html#default-反序列化异常处理程序

相关问题