Hey so I was experimenting with both Kafka Streams and MP Reactive Messaging to read from a Kafka Topic and then to produce back to it.
The Kafka Streams error -
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.
The Reactive Messaging error is similar, but basically the POJO that the messaging is getting deserialized to looks like this -
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;
}
Note that there is a default empty constructor and a constructor with all the fields.
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;
}
}
However, I guess it's called a "poison pill" but a single message produced from MQ with a payload of 'Aloha' breaks it and I can't deserialize it. I'm guessing the reason for this is that 'Aloha' is not recognized as a String since it's in single quotes. I don't have access to how that data is sent since it was sent by ways of MQ. Is there a way to skip processing this non-deserializable message and just continue with processing from the topic?
As indicate in the error message
please set the default.deserialization.exception.handler appropriately
you can configure a different deserialization exception handler to skip over messages that cannot be deserialized.
Check out the docs for more details: https://kafka.apache.org/documentation/streams/developer-guide/config-streams.html#default-deserialization-exception-handler
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.