From 2e290aa7d0fdabf9c33cd539ab4637c80c551963 Mon Sep 17 00:00:00 2001 From: Andy Palmer Date: Tue, 8 Apr 2025 12:42:45 +0100 Subject: [PATCH] GH-3103 Fix the retrieval of the schema version registered on serializing an Avro message with the ConfluentSchemaRegistryClient Signed-off-by: Andy Palmer Resolves #3103 Resolves #3107 --- .../client/ConfluentSchemaRegistryClient.java | 16 ++++++++-------- .../ConfluentSchemaRegistryClientTests.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java b/schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java index f33cd5d5f..1657120fd 100644 --- a/schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java +++ b/schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java @@ -16,14 +16,8 @@ package org.springframework.cloud.stream.schema.registry.client; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; - import org.springframework.cloud.stream.schema.registry.SchemaNotFoundException; import org.springframework.cloud.stream.schema.registry.SchemaReference; import org.springframework.cloud.stream.schema.registry.SchemaRegistrationResponse; @@ -37,6 +31,11 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author Vinicius Carvalho * @author Marius Bogoevici @@ -102,11 +101,12 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { try { ResponseEntity response = this.template.getForEntity( - this.endpoint + "/subjects/" + subject + "/versions", List.class); + this.endpoint + "/schemas/ids/" + id + "/versions", List.class); final List body = response.getBody(); if (!CollectionUtils.isEmpty(body)) { - version = (Integer) body.get(body.size() - 1); + // Assume only a single version is registered for this ID + version = (Integer) ((Map) body.get(0)).get("version"); } } catch (HttpStatusCodeException httpException) { diff --git a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/client/ConfluentSchemaRegistryClientTests.java b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/client/ConfluentSchemaRegistryClientTests.java index 2dcbaac98..1932638b0 100644 --- a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/client/ConfluentSchemaRegistryClientTests.java +++ b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/client/ConfluentSchemaRegistryClientTests.java @@ -66,9 +66,9 @@ class ConfluentSchemaRegistryClientTests { .andRespond(withSuccess("{\"id\":101,\"version\":1}", MediaType.APPLICATION_JSON)); this.mockRestServiceServer - .expect(requestTo("http://localhost:8081/subjects/user/versions")) + .expect(requestTo("http://localhost:8081/schemas/ids/101/versions")) .andExpect(method(HttpMethod.GET)) - .andRespond((withSuccess("[1]", MediaType.APPLICATION_JSON))); + .andRespond((withSuccess("[{\"subject\":\"user\",\"version\":1}]", MediaType.APPLICATION_JSON))); ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient( this.restTemplate);