diff --git a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/SchemaRegistrationResponse.java b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/SchemaRegistrationResponse.java index 200b5a0..abe4135 100644 --- a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/SchemaRegistrationResponse.java +++ b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/SchemaRegistrationResponse.java @@ -21,24 +21,33 @@ */ public class SchemaRegistrationResponse { - private int id; + private int id; - private SchemaReference schemaReference; + private SchemaReference schemaReference; - public int getId() { - return this.id; - } + private String schema; - public void setId(int id) { - this.id = id; - } + public int getId() { + return this.id; + } - public SchemaReference getSchemaReference() { - return this.schemaReference; - } + public void setId(int id) { + this.id = id; + } - public void setSchemaReference(SchemaReference schemaReference) { - this.schemaReference = schemaReference; - } + public SchemaReference getSchemaReference() { + return this.schemaReference; + } + public void setSchemaReference(SchemaReference schemaReference) { + this.schemaReference = schemaReference; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } } diff --git a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/avro/AvroSchemaRegistryClientMessageConverter.java b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/avro/AvroSchemaRegistryClientMessageConverter.java index 3bf9cab..5643b99 100644 --- a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/avro/AvroSchemaRegistryClientMessageConverter.java +++ b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/avro/AvroSchemaRegistryClientMessageConverter.java @@ -308,8 +308,13 @@ protected Schema resolveSchemaForWriting(Object payload, MessageHeaders headers, if (parsedSchema.getRegistration() == null) { SchemaRegistrationResponse response = this.schemaRegistryClient.register(toSubject(this.subjectNamePrefix, schema), AVRO_FORMAT, parsedSchema.getRepresentation()); - parsedSchema.setRegistration(response); + // rely on schema in response + schema = new Schema.Parser().parse(response.getSchema()); + parsedSchema = new ParsedSchema(schema); + this.getCache(REFERENCE_CACHE_NAME).put(schema, parsedSchema); + + parsedSchema.setRegistration(response); } SchemaReference schemaReference = parsedSchema.getRegistration().getSchemaReference(); diff --git a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java index bce8f06..9d3efbe 100644 --- a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java +++ b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/ConfluentSchemaRegistryClient.java @@ -83,6 +83,8 @@ public SchemaRegistrationResponse register(String subject, String format, String String payload = null; Map maps = new HashMap<>(); maps.put("schema", schema); + SchemaRegistrationResponse schemaRegistrationResponse = new SchemaRegistrationResponse(); + schemaRegistrationResponse.setSchema(schema); try { payload = this.mapper.writeValueAsString(maps); } @@ -107,6 +109,7 @@ public SchemaRegistrationResponse register(String subject, String format, String final List body = response.getBody(); if (!CollectionUtils.isEmpty(body)) { version = (Integer) body.get(body.size() - 1); + schemaRegistrationResponse.setSchema(fetch(new SchemaReference(subject, version, "avro"))); } } catch (HttpStatusCodeException httpException) { @@ -114,7 +117,6 @@ public SchemaRegistrationResponse register(String subject, String format, String subject, httpException.getStatusCode().value()), httpException); } - SchemaRegistrationResponse schemaRegistrationResponse = new SchemaRegistrationResponse(); schemaRegistrationResponse.setId(id); schemaRegistrationResponse.setSchemaReference(new SchemaReference(subject, version, "avro")); return schemaRegistrationResponse; diff --git a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/DefaultSchemaRegistryClient.java b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/DefaultSchemaRegistryClient.java index e401b3d..4256d46 100644 --- a/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/DefaultSchemaRegistryClient.java +++ b/spring-cloud-schema-registry-client/src/main/java/org/springframework/cloud/schema/registry/client/DefaultSchemaRegistryClient.java @@ -73,6 +73,7 @@ public SchemaRegistrationResponse register(String subject, String format, String registrationResponse.setId((Integer) responseBody.get("id")); registrationResponse.setSchemaReference(new SchemaReference(subject, (Integer) responseBody.get("version"), responseBody.get("format").toString())); + registrationResponse.setSchema(schema); return registrationResponse; } throw new RuntimeException(