嘿,所以我正在尝试使用 Kafka Streams 和 MP Reactive Messaging 来读取 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.
Reactive Messaging 错误类似,但基本上消息被反序列化为的 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 发送的。有没有办法跳过处理这个不可反序列化的消息并继续从主题处理?