Description
Describe the issue
ConfluentSchemaRegistryClient picks wrong subject version when serialising a message if the schema registry has a newer version of the schema registered. This results in the wrong version being encoded in the ContentType header as calculated here https://github.com/spring-cloud/spring-cloud-stream/blob/main/schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java#L103-L111
To Reproduce
Steps to reproduce the behavior:
- Send an event which registers an avro schema with the schema registry
- Observe the ContentType header (let's say it is application/vnd.user.v1+avro)
- Evolve the schema, produce a new version of the SpecificRecord type
- Send a new version of the event which registers a new version of the schema
- Observe the ContentType header (it will be application/vnd.user.v2+avro)
- Send an event using the older SpecificRecord type
- Observe the ContentType header (it will be application/vnd.user.v2+avro)
- Observe the consumer fail to deserialise because the reader schema (v2) does not match the writer schema (v1)
Version of the framework
4.2.0
Expected behavior
When registering the schema on sending the event the schema registry client should not assume that the most recent subject version is being used, but should instead take the ID returned from the POST to "/subjects/" + subject + "/versions"
and invoke https://docs.confluent.io/platform/current/schema-registry/develop/api.html#get--schemas-ids-int-%20id-versions to fetch the correct version