diff --git a/docs/src/main/asciidoc/spring-cloud-stream.adoc b/docs/src/main/asciidoc/spring-cloud-stream.adoc index 1cc38237c..69ecd119d 100644 --- a/docs/src/main/asciidoc/spring-cloud-stream.adoc +++ b/docs/src/main/asciidoc/spring-cloud-stream.adoc @@ -1994,6 +1994,10 @@ Default: `empty` spring.cloud.stream.schema.avro.prefix:: The prefix to be used on the Content-Type header. + Default: `vnd` +spring.cloud.stream.schema.avro.subjectNamingStrategy:: Determines the subject name used to register the Avro schema in the schema registry. Two implementations are available, `org.springframework.cloud.stream.schema.avro.DefaultSubjectNamingStrategy`, +where the subject is the schema name, and `org.springframework.cloud.stream.schema.avro.QualifiedSubjectNamingStrategy`, which returns a fully qualified subject using the Avro schema namespace and name. Custom strategies can be created by implementing `org.springframework.cloud.stream.schema.avro.SubjectNamingStrategy`. ++ +Default: `org.springframework.cloud.stream.schema.avro.DefaultSubjectNamingStrategy` === Apache Avro Message Converters diff --git a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/CustomSubjectNamingStrategy.java b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/avro/QualifiedSubjectNamingStrategy.java similarity index 69% rename from spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/CustomSubjectNamingStrategy.java rename to spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/avro/QualifiedSubjectNamingStrategy.java index 71ff5d526..2d103e82b 100644 --- a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/CustomSubjectNamingStrategy.java +++ b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/avro/QualifiedSubjectNamingStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,15 @@ * limitations under the License. */ -package org.springframework.cloud.schema.avro; +package org.springframework.cloud.stream.schema.avro; import org.apache.avro.Schema; -import org.springframework.cloud.stream.schema.avro.SubjectNamingStrategy; - /** - * @author David Kalosi + * @author José A. Íñigo + * @since 2.2.0 */ -class CustomSubjectNamingStrategy implements SubjectNamingStrategy { - - CustomSubjectNamingStrategy() { - } +public class QualifiedSubjectNamingStrategy implements SubjectNamingStrategy { @Override public String toSubject(Schema schema) { diff --git a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/SubjectNamingStrategyTest.java b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/SubjectNamingStrategyTest.java index 843ed63f7..2b6fb3410 100644 --- a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/SubjectNamingStrategyTest.java +++ b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/SubjectNamingStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,20 +37,21 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author David Kalosi + * @author José A. Íñigo */ public class SubjectNamingStrategyTest { - static StubSchemaRegistryClient stubSchemaRegistryClient = new StubSchemaRegistryClient(); + private static StubSchemaRegistryClient stubSchemaRegistryClient = new StubSchemaRegistryClient(); @Test - public void testCustomNamingStrategy() throws Exception { + public void testQualifiedSubjectNamingStrategy() throws Exception { ConfigurableApplicationContext sourceContext = SpringApplication.run( - AvroSourceApplication.class, "--server.port=0", "--debug", - "--spring.jmx.enabled=false", - "--spring.cloud.stream.bindings.output.contentType=application/*+avro", - "--spring.cloud.stream.schema.avro.subjectNamingStrategy=" - + "org.springframework.cloud.schema.avro.CustomSubjectNamingStrategy", - "--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true"); + AvroSourceApplication.class, "--server.port=0", "--debug", + "--spring.jmx.enabled=false", + "--spring.cloud.stream.bindings.output.contentType=application/*+avro", + "--spring.cloud.stream.schema.avro.subjectNamingStrategy=" + + "org.springframework.cloud.stream.schema.avro.QualifiedSubjectNamingStrategy", + "--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true"); Source source = sourceContext.getBean(Source.class); User1 user1 = new User1(); @@ -59,12 +60,12 @@ public class SubjectNamingStrategyTest { source.output().send(MessageBuilder.withPayload(user1).build()); MessageCollector barSourceMessageCollector = sourceContext - .getBean(MessageCollector.class); + .getBean(MessageCollector.class); Message message = barSourceMessageCollector.forChannel(source.output()) - .poll(1000, TimeUnit.MILLISECONDS); + .poll(1000, TimeUnit.MILLISECONDS); assertThat(message.getHeaders().get("contentType")).isEqualTo(MimeType.valueOf( - "application/vnd.org.springframework.cloud.schema.avro.User1.v1+avro")); + "application/vnd.org.springframework.cloud.schema.avro.User1.v1+avro")); } @EnableBinding(Source.class)