Java Quarkus Kafka流/反应式消息传递反序列化异常

Java Quarkus Kafka流/反应式消息传递反序列化异常,java,apache-kafka,apache-kafka-streams,quarkus,smallrye-reactive-messaging,Java,Apache Kafka,Apache Kafka Streams,Quarkus,Smallrye Reactive Messaging,嘿,所以我在试验卡夫卡流和MP反应式消息,阅读卡夫卡主题,然后制作回它 卡夫卡流错误- 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 deserializat

嘿,所以我在试验卡夫卡流和MP反应式消息,阅读卡夫卡主题,然后制作回它

卡夫卡流错误-

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.
反应式消息错误与此类似,但消息被反序列化到的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;
    }

}
导入java.time.Instant;
导入javax.enterprise.context.ApplicationScoped;
导入javax.enterprise.inject.products;
导入org.apache.kafka.common.serialization.Serdes;
导入org.apache.kafka.streams.StreamsBuilder;
导入org.apache.kafka.streams.Topology;
导入org.apache.kafka.streams.kstream.com;
导入org.apache.kafka.streams.kstream.GlobalKTable;
导入org.apache.kafka.streams.kstream.Materialized;
导入org.apache.kafka.streams.kstream.producted;
导入org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
导入org.apache.kafka.streams.state.Stores;
导入io.quarkus.kafka.client.serialization.JsonbSerde;
导入io.quarkus.kafka.client.serialization.JsonbSerializer;
@适用范围
公共类顺应论{
私有静态最终字符串KTABLE_TOPIC=“kstreams KTABLE TOPIC”;
私有静态最终字符串传入\u TOPIC=“kstreams传入测试”;
私有静态最终字符串传出\u TOPIC=“kstreams传出测试”;
@产生
公共拓扑buildTopology(){
StreamsBuilder builder=新的StreamsBuilder();
JsonbSerde financialMessageSerde=新的JsonbSerde(FinancialMessage.class);
建设者流(
新主题,
使用(Serdes.Integer(),financialMessageSerde)
)
.过滤器(
(键,消息)->检查合规性(消息)
)
.mapValues(
checkedMessage->performComplianceCheck(checkedMessage)
)
.到(
新主题,
使用(Serdes.Integer(),financialMessageSerde)生成
);  
返回builder.build();
}
公共布尔检查符合性(FinancialMessage rawMessage){
返回(rawMessage.compliance_services);
}
公共财务消息性能符合性检查(财务消息检查消息){
checkedMessage.compliance\u services=false;
返回checkedMessage;
}
}

然而,我猜它被称为“毒药丸”,但是从MQ生成的负载为“Aloha”的单个消息会破坏它,我无法反序列化它。我猜这是因为'Aloha'不被识别为字符串,因为它在单引号中。我无法访问该数据的发送方式,因为它是通过MQ发送的。有没有办法跳过处理此不可反序列化的消息,直接从主题继续处理?

如错误消息所示

please set the default.deserialization.exception.handler appropriately
您可以配置不同的反序列化异常处理程序,以跳过无法反序列化的消息


查看文档了解更多详细信息:

如错误消息所示

please set the default.deserialization.exception.handler appropriately
您可以配置不同的反序列化异常处理程序,以跳过无法反序列化的消息

有关更多详细信息,请查看文档: