smallrye / smallrye-reactive-messaging

SmallRye Reactive Messaging
http://www.smallrye.io/smallrye-reactive-messaging/
Apache License 2.0
232 stars 174 forks source link

Can't recover from structured CloudEvents with invalid JSON #2492

Open ntkoopman opened 5 months ago

ntkoopman commented 5 months ago

When receiving a structured CloudEvent, the payload is converted to JSON by KafkaCloudEventHelper#createFromStructuredCloudEvent. If the actual data is not valid JSON, this throws an exception which is handled in KafkaSource by immediately closing the connection.

Both the value-deserialization-failure-handler and failure-strategy are never invoked, and since this is before any application code, it seems impossible to handle this failure case.

cescoffier commented 5 months ago

It should be considered as a deserialization failure. So definitely a bug.

Could you provide an example of such broken cloud events?

ntkoopman commented 5 months ago

Any invalid JSON will do:

content-type: application/cloudevents+json

{"type":
ozangunalp commented 5 months ago

An option is to use the io.quarkus.kafka.client.serialization.JsonObjectDeserializer which would do the Json parsing on the Kafka client and the failure handler and failure strategy would work as expected. Is there anything preventing you to use the JsonObject deserializer?

We may imagine a way to invoke the failure-strategy but once you use the StringDeserializer it is not possible to catch this in the value-deserialization-failure-handler.

ntkoopman commented 5 months ago

Using JsonObjectDeserializer would make it impossible to handle binary messages on the same topic. Just to be clear, I don't need a work around, I got it working by using the CloudEvents SDK deserializer.

One side effect in Quarkus, is that it also triggers the liveness and readiness checks to fail, effectively causing a denial of service.

cescoffier commented 5 months ago

It still needs to be fixed in reactive messaging. The SDK is not very Quarkus friendly (native issues, detection, reflection...). It works, but may lead to issues.