Maybe there is an established way to do this but I...
# troubleshooting
h
Maybe there is an established way to do this but I would like to send messages that are not proper JSON messages to a separate error topic. Ideally I would like to have this done declaratively somewhere in the pipeline maybe something like:
Copy code
KafkaSource.<MyObject>......setDeserializer(new MyObjectSerializer()).setDeserializinfErrorTopic("error-topic").build()
t
Hi Henrik, what you can do is add process function right after Kafka source(If you detect that the record in your custom serializer is not valid you return an invalid object) then check the record whether its valid or not. given process function (i.e CustomProcessFunc)
Copy code
@Override
    public void processElement(final MyObject myObj,
            final ProcessFunctionMyObject , MyObject.Context context,
            final CollectorMyObject collector) {
        if (myObj.isValid()) {
            collector.collect(myObj);
        } else {
                MyObject invalid = MyObject.from(obj);
                context.output("invalidOutput", invalid);
            }
        }
    }
then: var source = KafkaSource..... var filteredStream = source.process(new CustomProcessFunc()); filteredStream .getSideOutput("invalidOutput").sinkTo(KafkaSink....)'
πŸ‘ 2
h
.process(...)
is where I have landed now actually. It is more or less exactly what you have outlined above. Fighting a little with type erasure but it seems solved now. It's all in all not so bad just hard to know when you haven't done it before.
Thx for validating what I was doing I was just taking a stab at it πŸ™‚
πŸ’― 1