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 |
static String |
CACHE_PREFIX |
static org.springframework.util.MimeType |
DEFAULT_AVRO_MIME_TYPE |
static Pattern |
PREFIX_VALIDATION_PATTERN |
static String |
REFERENCE_CACHE_NAME |
static String |
REFLECTION_CACHE_NAME |
static String |
SCHEMA_CACHE_NAME |
protected org.springframework.core.io.Resource[] |
schemaImports |
| Constructor and Description |
|---|
AvroSchemaRegistryClientMessageConverter(SchemaRegistryClient schemaRegistryClient,
org.springframework.cache.CacheManager cacheManager)
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 publised 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) |
canConvertFrom, convertFromInternal, convertToInternal, getDatumReader, parseSchemacanConvertTo, fromMessage, fromMessage, getContentTypeResolver, getDefaultContentType, getMimeType, getSerializedPayloadClass, getSupportedMimeTypes, isStrictContentTypeMatch, setContentTypeResolver, setSerializedPayloadClass, setStrictContentTypeMatch, toMessage, toMessagepublic 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
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 NoOpCacheManagerpublic boolean isDynamicSchemaGenerationEnabled()
public void setDynamicSchemaGenerationEnabled(boolean dynamicSchemaGenerationEnabled)
dynamicSchemaGenerationEnabled - true if dynamic schema generation is enabledpublic void setSchemaLocations(org.springframework.core.io.Resource[] schemaLocations)
schemaLocations - public void setSchemaImports(org.springframework.core.io.Resource[] schemaImports)
schemaImports - public void setPrefix(String prefix)
prefix - public 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.InitializingBeanExceptionprotected String toSubject(org.apache.avro.Schema schema)
protected boolean supports(Class<?> clazz)
supports in class org.springframework.messaging.converter.AbstractMessageConverterprotected boolean supportsMimeType(org.springframework.messaging.MessageHeaders headers)
supportsMimeType in class org.springframework.messaging.converter.AbstractMessageConverterprotected org.apache.avro.Schema resolveSchemaForWriting(Object payload, org.springframework.messaging.MessageHeaders headers, org.springframework.util.MimeType hintedContentType)
resolveSchemaForWriting in class AbstractAvroMessageConverterprotected org.apache.avro.Schema resolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType)
resolveWriterSchemaForDeserialization in class AbstractAvroMessageConverterprotected org.apache.avro.Schema resolveReaderSchemaForDeserialization(Class<?> targetClass)
resolveReaderSchemaForDeserialization in class AbstractAvroMessageConverterCopyright © 2019 Pivotal Software, Inc.. All rights reserved.