public class AvroSchemaRegistryClientMessageConverter extends AbstractAvroMessageConverter implements org.springframework.beans.factory.InitializingBean
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:
SchemaRegistryClient
.Modifier and Type | Field and Description |
---|---|
static String |
AVRO_FORMAT
Avro format defined in the Mime type.
|
static String |
CACHE_PREFIX
Spring Cloud Stream schema property prefix.
|
static org.springframework.util.MimeType |
DEFAULT_AVRO_MIME_TYPE
Default Mime type for Avro.
|
static Pattern |
PREFIX_VALIDATION_PATTERN
Pattern for validating the prefix to be used in the publised subtype.
|
static String |
REFERENCE_CACHE_NAME
Property for reference cache.
|
static String |
REFLECTION_CACHE_NAME
Property for reflection cache.
|
static String |
SCHEMA_CACHE_NAME
Property for schema cache.
|
protected org.springframework.core.io.Resource[] |
schemaImports |
Constructor and Description |
---|
AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient,
org.springframework.cache.CacheManager cacheManager)
Deprecated.
|
AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient,
org.springframework.cache.CacheManager cacheManager,
AvroSchemaServiceManager manager)
Creates a new instance, configuring it with
SchemaRegistryClient and
CacheManager . |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
boolean |
isDynamicSchemaGenerationEnabled() |
protected org.apache.avro.Schema |
resolveReaderSchemaForDeserialization(Class<?> targetClass) |
protected org.apache.avro.Schema |
resolveSchemaForWriting(Object payload,
org.springframework.messaging.MessageHeaders headers,
org.springframework.util.MimeType hintedContentType) |
protected org.apache.avro.Schema |
resolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType) |
void |
setDynamicSchemaGenerationEnabled(boolean dynamicSchemaGenerationEnabled)
Allows the converter to generate and register schemas automatically.
|
void |
setPrefix(String prefix)
Set the prefix to be used in the published subtype.
|
void |
setReaderSchema(org.springframework.core.io.Resource readerSchema) |
void |
setSchemaImports(org.springframework.core.io.Resource[] schemaImports)
A set of schema locations where should be imported first.
|
void |
setSchemaLocations(org.springframework.core.io.Resource[] schemaLocations)
A set of locations where the converter can load schemas from.
|
void |
setSubjectNamingStrategy(SubjectNamingStrategy subjectNamingStrategy) |
protected boolean |
supports(Class<?> clazz) |
protected boolean |
supportsMimeType(org.springframework.messaging.MessageHeaders headers) |
protected String |
toSubject(org.apache.avro.Schema schema) |
avroSchemaServiceManager, canConvertFrom, convertFromInternal, convertToInternal, parseSchema
addSupportedMimeTypes, canConvertTo, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, toMessage, toMessage
public static final String AVRO_FORMAT
public static final Pattern PREFIX_VALIDATION_PATTERN
public static final String CACHE_PREFIX
public static final String REFLECTION_CACHE_NAME
public static final String SCHEMA_CACHE_NAME
public static final String REFERENCE_CACHE_NAME
public static final org.springframework.util.MimeType DEFAULT_AVRO_MIME_TYPE
protected org.springframework.core.io.Resource[] schemaImports
@Deprecated public AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient, org.springframework.cache.CacheManager cacheManager)
SchemaRegistryClient
and
CacheManager
.schemaRegistryClient
- the SchemaRegistryClient
used to interact with
the schema registry server.cacheManager
- instance of CacheManager
to cache parsed schemas. If
caching is not required use NoOpCacheManager
public AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient, org.springframework.cache.CacheManager cacheManager, AvroSchemaServiceManager manager)
SchemaRegistryClient
and
CacheManager
.schemaRegistryClient
- the SchemaRegistryClient
used to interact with
the schema registry server.cacheManager
- instance of CacheManager
to cache parsed schemas. If
caching is not required use NoOpCacheManager
manager
- instance of AvroSchemaServiceManager
to manage schemas.public boolean isDynamicSchemaGenerationEnabled()
public void setDynamicSchemaGenerationEnabled(boolean dynamicSchemaGenerationEnabled)
dynamicSchemaGenerationEnabled
- true if dynamic schema generation is enabledpublic void setSchemaLocations(org.springframework.core.io.Resource[] schemaLocations)
schemaLocations
- array of locationspublic void setSchemaImports(org.springframework.core.io.Resource[] schemaImports)
schemaImports
- array of schema importspublic void setPrefix(String prefix)
prefix
- prefix to be setpublic void setReaderSchema(org.springframework.core.io.Resource readerSchema)
public void setSubjectNamingStrategy(SubjectNamingStrategy subjectNamingStrategy)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
protected String toSubject(org.apache.avro.Schema schema)
protected boolean supports(Class<?> clazz)
supports
in class org.springframework.messaging.converter.AbstractMessageConverter
protected boolean supportsMimeType(org.springframework.messaging.MessageHeaders headers)
supportsMimeType
in class org.springframework.messaging.converter.AbstractMessageConverter
protected org.apache.avro.Schema resolveSchemaForWriting(Object payload, org.springframework.messaging.MessageHeaders headers, org.springframework.util.MimeType hintedContentType)
resolveSchemaForWriting
in class AbstractAvroMessageConverter
protected org.apache.avro.Schema resolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType)
resolveWriterSchemaForDeserialization
in class AbstractAvroMessageConverter
protected org.apache.avro.Schema resolveReaderSchemaForDeserialization(Class<?> targetClass)
resolveReaderSchemaForDeserialization
in class AbstractAvroMessageConverter
Copyright © 2020 Pivotal Software, Inc.. All rights reserved.