Skip to content

ConfluentSchemaRegistryClient picks wrong subject version when using SpecificRecord types #3103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
palmski opened this issue Mar 26, 2025 · 3 comments

Comments

@palmski
Copy link

palmski commented Mar 26, 2025

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:

  1. Send an event which registers an avro schema with the schema registry
  2. Observe the ContentType header (let's say it is application/vnd.user.v1+avro)
  3. Evolve the schema, produce a new version of the SpecificRecord type
  4. Send a new version of the event which registers a new version of the schema
  5. Observe the ContentType header (it will be application/vnd.user.v2+avro)
  6. Send an event using the older SpecificRecord type
  7. Observe the ContentType header (it will be application/vnd.user.v2+avro)
  8. 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

@palmski
Copy link
Author

palmski commented Mar 26, 2025

For reference, using this code (Kotlin, sorry) to replace the linked code above does the job

            template.getForEntity<List<Map<String, Any>>>("$endpoint/schemas/ids/$id/versions").body?.let {
                if (!CollectionUtils.isEmpty(it) && it.isNotEmpty()) {
                    version = it[0]["version"] as Int
                }
            }

@sobychacko
Copy link
Contributor

@palmski Thanks for the report. That seems like an issue. Are you willing to send a PR to fix this issue? If so, please do it; we will gladly review it. Thanks!

palmski pushed a commit to palmski/spring-cloud-stream that referenced this issue Apr 8, 2025
Fix the retrieval of the schema version registered on serializing an Avro message with the ConfluentSchemaRegistryClient
@palmski
Copy link
Author

palmski commented Apr 8, 2025

@sobychacko #3107 raised

Sorry it took so long, getting the build running within our corporate network has been... challenging :)

palmski pushed a commit to palmski/spring-cloud-stream that referenced this issue Apr 8, 2025
Fix the retrieval of the schema version registered on serializing an Avro message with the ConfluentSchemaRegistryClient

Signed-off-by: Andy Palmer <[email protected]>
@olegz olegz closed this as completed in 906eae8 Apr 8, 2025
olegz pushed a commit that referenced this issue Apr 8, 2025
…zing an Avro message with the ConfluentSchemaRegistryClient

Signed-off-by: Andy Palmer <[email protected]>

Resolves #3103
olegz pushed a commit that referenced this issue Apr 8, 2025
…zing an Avro message with the ConfluentSchemaRegistryClient

Signed-off-by: Andy Palmer <[email protected]>

Resolves #3103
Resolves #3107
@olegz olegz added this to the 4.3.0 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants