spring-kafka icon indicating copy to clipboard operation
spring-kafka copied to clipboard

Consider to add Producer and Consumer Factories for CloudEvents Kafka support

Open artembilan opened this issue 5 years ago • 4 comments

See more info on the official CloudEvents GH project: https://github.com/cloudevents/sdk-java/tree/master/kafka

In addition we can consider to implement a RecordMessageConverter to map to/from a Spring Message<?> which could be handy interacting with other Spring Messaging based projects.

artembilan avatar Nov 04 '19 23:11 artembilan

More info is also here: https://github.com/cloudevents/spec/blob/master/kafka-protocol-binding.md

artembilan avatar Nov 04 '19 23:11 artembilan

I took a swing at this... I'm not sure if it's what you were looking for, but with some guidance I could make changes to be inline with what you were thinking for this integration.

https://github.com/wkennedy/spring-kafka-cloud-events

Here is the overview:

  • Creates a static producer and consumer factory that returns a DefaultKafkaProducerFactory. This DefaultKafkaProducerFactory uses a CloudEvents value serializer based on the specified encoding (binary or structured).
  • Create a converter that extracts the data from the CloudEvent in the ConsumerRecord and returns a Spring message with the payload being the CloudEvent data.

wkennedy avatar Oct 15 '20 17:10 wkennedy

Thank you for sharing your effort, but looks like with upcoming CloudEvents SDK v2 we don't need any custom Producer/Consumer factories: https://github.com/cloudevents/sdk-java/tree/master/kafka. It is only now a matter to specify the proper CloudEventSerializer/CloudEventDeserializer in the producer/consumer config.

So, we probably just end up adding some docs note about CloudEvents. Or we just can live without anything over here since it is covered from CloudEvents SDK.

WDYT?

artembilan avatar Oct 20 '20 19:10 artembilan

@artembilan Thanks for the reply! I agree, with your assessment which is partly why I didn't create a PR. The factories I wrote are essentially just some just helpers in order to create the serializer/deserializer and set it on the producer/consumer. I would say it's pretty straightforward to integrate cloud-events into your project that uses Spring-Kafka and doesn't warrant introducing the cloud-events dependency to Spring-Kafka.

The Cloud Events message converter could be helpful, though it would need more investigation and thought, especially when handling Cloud Events using the structured content mode.

wkennedy avatar Oct 20 '20 19:10 wkennedy