Added RecordNamingStrategy and spring.cloud.stream.schema.avro.subjectNamingStrategy documentation
Renamed SubjectNamingStrategyImplementation - Improved documentation - Added required changes Polishing
This commit is contained in:
committed by
Soby Chacko
parent
e9baeea5a9
commit
414b4313c0
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user