Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8790

Kafka producer hard coded to use Strings

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.14.2, 2.15.2, 2.16.0
    • Fix Version/s: 2.15.3, 2.16.0
    • Component/s: camel-kafka
    • Labels:
      None
    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Unknown
    • Flags:
      Patch

      Description

      Kafka natively supports two encoders for messages:

      1. kafka.serializer.DefaultEncoder - encodes as byte arrays
      2. kafka.serializer.StringEncoder - encodes as Strings

      Camel-kafka exposes settings to select the encoder ((serializerClass and keySerializerClass), but the org.apache.camel.component.kafka.KafkaProducer class hard-codes String for both the key and value types. This results in a ClassCastException when using the DefaultDecoder.

      The attached patch fixes this as follows (conforming to kafka itself):

      • If no serializerClass option is specified, the DefaultDecoder is used.
      • If no keySerializerClass option is specified, the same encoder as serializerClass is used

      This fix shouldn't break any existing code, as there was not previously a default setting (i.e., StringEncoder always had to be specified).

      I created the patch against master, but it should backport easily to 2.15.x and 2.14.x.

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              mmindenhall Mark Mindenhall
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: