cloudevents / sdk-java

Java SDK for CloudEvents
https://cloudevents.github.io/sdk-java/
Apache License 2.0
390 stars 159 forks source link

can't setup `cloudevents.serializer.event_format` in quarkus #595

Open dfiai opened 11 months ago

dfiai commented 11 months ago

Hello everyone, I want to express my appreciation for the fantastic work you're doing!

I've noticed that Quarkus reactive Kafka replaces all underscores (_) with periods (`.``). Here's a code snippet from quarkus code to illustrate this:

private static void extractConfigKey(Config config, JsonObject json, String originalKey, String prefixToStrip) {
    // Transform keys that may come from environment variables.
    // As Kafka properties use ".", transform "_" into "."
    String key = originalKey;
    if (key.contains("_") || allCaps(key)) {
        key = originalKey.toLowerCase().replace("_", ".");
    }
    // ...
}

This transformation is causing an issue for me when trying to pass event_format in the application.properties file:

/**
 * The configuration key for the {@link EventFormat} to use when serializing the event in structured mode.
 */
public final static String EVENT_FORMAT_CONFIG = "cloudevents.serializer.event_format";

Is there a way to also support event.format, or do you have any suggestions for a workaround? Your insights would be greatly appreciated!

pierDipi commented 7 months ago

Last I checked Quarkus, the CloudEvents integration wasn't based on the CE SDK, but that might have changed, can you please share more about your Quarkus and CloudEvents Java SDK setup/configuration/scenario?

pierDipi commented 7 months ago

cc @cescoffier

cescoffier commented 7 months ago

Unfortunately, as explained in the comment, this is done to handle env variables. While far from ideal, it's the best approach (and most reliable) we have found.

I will see what can be done, but the best approach would be to have the attributes use a . as the other Kafka properties.