Search code examples
javaavrospring-kafkaconfluent-schema-registryspring-cloud-contract

Spring cloud contract tests for avro messages using Schema Registry


I am checking out the spring docs and spring github, and I can see some very basic examples of async kafka messaging (producer and consumer) that communicate via json messages and Kafka topics, but it seems that there are no examples for more production like setups where the messages are not json but avro ones, while a Schema Registry (e.g. the Confluent one) is also in the picture. I am quite surprise by this, as when having event based microservices communicating via producing/ consuming avro messages, then contract tests is a must have to avoid runtime exceptions when the avro schema evolves, and catch them during build time. I am wondering if someone else has already solved this. Any direction much appreciated!

EDIT: In my case I ended up adding Avro based contracts. Take a look here: github.com/vspiliop/kafka-contract-test-producer and github.com/vspiliop/kafka-contract-test-consumer.


Solution

  • There is no explicit support of spring cloud contract and avro. We do support however working against existing Middleware. Here you have an example of testing against a real kafka broker - producer: https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/producer_kafka_middleware and consumer: https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/consumer_kafka_middleware

    If necessary you can run additional Middleware including a schema registry.