Class AvroSchemaRegistryClientMessageConverter
java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.cloud.stream.schema.registry.avro.AbstractAvroMessageConverter
org.springframework.cloud.stream.schema.registry.avro.AvroSchemaRegistryClientMessageConverter
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,org.springframework.messaging.converter.MessageConverter,org.springframework.messaging.converter.SmartMessageConverter
public class AvroSchemaRegistryClientMessageConverter
extends AbstractAvroMessageConverter
implements org.springframework.beans.factory.InitializingBean
A
MessageConverter for Apache Avro,
with the ability to publish and retrieve schemas stored in a schema server, allowing
for schema evolution in applications. The supported content types are in the form
`application/*+avro`.
During the conversion to a message, the converter will set the 'contentType' header to 'application/[prefix].[subject].v[version]+avro', where:
-
prefix is a configurable prefix (default 'vnd');
-
subject is a subject derived from the type of the outgoing object - typically
the class name;
-
version is the schema version for the given subject;
When converting from a message, the converter will parse the content-type and use it to
fetch and cache the writer schema using the provided SchemaRegistryClient.
- Author:
- Marius Bogoevici, Vinicius Carvalho, Oleg Zhurakousky, Sercan Karaoglu, Ish Mahajan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAvro format defined in the Mime type.static final StringSpring Cloud Stream schema property prefix.static final org.springframework.util.MimeTypeDefault Mime type for Avro.static final PatternPattern for validating the prefix to be used in the publised subtype.static final StringProperty for reference cache.static final StringProperty for reflection cache.static final StringProperty for schema cache.protected org.springframework.core.io.Resource[]Fields inherited from class org.springframework.messaging.converter.AbstractMessageConverter
logger -
Constructor Summary
ConstructorsConstructorDescriptionAvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient, org.springframework.cache.CacheManager cacheManager, AvroSchemaServiceManager manager) Creates a new instance, configuring it withSchemaRegistryClientandCacheManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanprotected org.apache.avro.SchemaresolveReaderSchemaForDeserialization(Class<?> targetClass) protected org.apache.avro.SchemaresolveSchemaForWriting(Object payload, org.springframework.messaging.MessageHeaders headers, org.springframework.util.MimeType hintedContentType) protected org.apache.avro.SchemaresolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType) voidsetDynamicSchemaGenerationEnabled(boolean dynamicSchemaGenerationEnabled) Allows the converter to generate and register schemas automatically.voidsetIgnoreSchemaRegistryServer(boolean ignoreSchemaRegistryServer) voidSet the prefix to be used in the published subtype.voidsetReaderSchema(org.springframework.core.io.Resource readerSchema) voidsetSchemaImports(org.springframework.core.io.Resource[] schemaImports) A set of schema locations where should be imported first.voidsetSchemaLocations(org.springframework.core.io.Resource[] schemaLocations) A set of locations where the converter can load schemas from.voidsetSubjectNamePrefix(String subjectNamePrefix) voidsetSubjectNamingStrategy(SubjectNamingStrategy subjectNamingStrategy) protected booleanprotected booleansupportsMimeType(org.springframework.messaging.MessageHeaders headers) protected StringMethods inherited from class org.springframework.cloud.stream.schema.registry.avro.AbstractAvroMessageConverter
avroSchemaServiceManager, canConvertFrom, convertFromInternal, convertToInternal, parseSchemaMethods inherited from class org.springframework.messaging.converter.AbstractMessageConverter
addSupportedMimeTypes, canConvertTo, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, toMessage, toMessage
-
Field Details
-
AVRO_FORMAT
Avro format defined in the Mime type.- See Also:
-
PREFIX_VALIDATION_PATTERN
Pattern for validating the prefix to be used in the publised subtype. -
CACHE_PREFIX
Spring Cloud Stream schema property prefix.- See Also:
-
REFLECTION_CACHE_NAME
Property for reflection cache.- See Also:
-
SCHEMA_CACHE_NAME
Property for schema cache.- See Also:
-
REFERENCE_CACHE_NAME
Property for reference cache.- See Also:
-
DEFAULT_AVRO_MIME_TYPE
public static final org.springframework.util.MimeType DEFAULT_AVRO_MIME_TYPEDefault Mime type for Avro. -
schemaImports
protected org.springframework.core.io.Resource[] schemaImports
-
-
Constructor Details
-
AvroSchemaRegistryClientMessageConverter
public AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient, org.springframework.cache.CacheManager cacheManager, AvroSchemaServiceManager manager) Creates a new instance, configuring it withSchemaRegistryClientandCacheManager.- Parameters:
schemaRegistryClient- theSchemaRegistryClientused to interact with the schema registry server.cacheManager- instance ofCacheManagerto cache parsed schemas. If caching is not required useNoOpCacheManagermanager- instance ofAvroSchemaServiceManagerto manage schemas.
-
-
Method Details
-
isDynamicSchemaGenerationEnabled
public boolean isDynamicSchemaGenerationEnabled() -
setDynamicSchemaGenerationEnabled
public void setDynamicSchemaGenerationEnabled(boolean dynamicSchemaGenerationEnabled) Allows the converter to generate and register schemas automatically. If set to false, it only allows the converter to use pre-registered schemas. Default 'true'.- Parameters:
dynamicSchemaGenerationEnabled- true if dynamic schema generation is enabled
-
setSchemaLocations
public void setSchemaLocations(org.springframework.core.io.Resource[] schemaLocations) A set of locations where the converter can load schemas from. Schemas provided at these locations will be registered automatically.- Parameters:
schemaLocations- array of locations
-
setSchemaImports
public void setSchemaImports(org.springframework.core.io.Resource[] schemaImports) A set of schema locations where should be imported first. Schemas provided at these locations will be reference, thus they should not reference each other.- Parameters:
schemaImports- array of schema imports
-
setPrefix
Set the prefix to be used in the published subtype. Default 'vnd'.- Parameters:
prefix- prefix to be set
-
setReaderSchema
public void setReaderSchema(org.springframework.core.io.Resource readerSchema) -
setSubjectNamingStrategy
-
setSubjectNamePrefix
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
toSubject
-
supports
- Specified by:
supportsin classorg.springframework.messaging.converter.AbstractMessageConverter
-
supportsMimeType
protected boolean supportsMimeType(org.springframework.messaging.MessageHeaders headers) - Overrides:
supportsMimeTypein classorg.springframework.messaging.converter.AbstractMessageConverter
-
resolveSchemaForWriting
protected org.apache.avro.Schema resolveSchemaForWriting(Object payload, org.springframework.messaging.MessageHeaders headers, org.springframework.util.MimeType hintedContentType) - Specified by:
resolveSchemaForWritingin classAbstractAvroMessageConverter
-
resolveWriterSchemaForDeserialization
protected org.apache.avro.Schema resolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType) - Specified by:
resolveWriterSchemaForDeserializationin classAbstractAvroMessageConverter
-
resolveReaderSchemaForDeserialization
- Specified by:
resolveReaderSchemaForDeserializationin classAbstractAvroMessageConverter
-
setIgnoreSchemaRegistryServer
public void setIgnoreSchemaRegistryServer(boolean ignoreSchemaRegistryServer)
-