Class CachingSchemaStore

  • All Implemented Interfaces:
    SchemaStore

    public class CachingSchemaStore
    extends java.lang.Object
    implements SchemaStore
    Recommended implementation of SchemaStore that detects schema changes and regenerates Avro schema. Pass in a `SchemaStorePublisherFactory` to publish the schema downstream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.avro.generic.GenericDatumReader<org.apache.avro.generic.GenericRecord> getReader​(java.lang.String namespace, java.lang.String name)
      Get the datum reader
      org.apache.avro.Schema getSchema​(java.lang.String namespace, java.lang.String name)
      Get the avro corresponding to the namespace and the name of the schema
      java.util.Map<java.lang.String,​org.apache.avro.Schema> getSchemas()  
      java.lang.String getVersion​(java.lang.String namespace, java.lang.String name)
      Get the schema version corresponding to the namespace and the name of the schema
      org.apache.avro.generic.GenericDatumWriter<org.apache.avro.generic.GenericRecord> getWriter​(java.lang.String namespace, java.lang.String name)
      Get the datum writer
      void initialize()
      `initialize()` must be called on server start-up once all other dependencies are initialized, e.g.
      void onConfigChange()
      `onConfigChange()` should be called whenever the Kafka config is changed and the publisher needs to be rebuilt.
      void onSchemaChange()
      `onSchemaChanged()` should be called whenever a Cassandra CQL schema change is detected.
      protected org.apache.cassandra.cdc.avro.CqlToAvroSchemaConverter schemaConverter()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CachingSchemaStore

        public CachingSchemaStore​(SchemaStoreStats schemaStoreStats,
                                  java.util.function.Supplier<org.apache.cassandra.bridge.CassandraVersion> cassandraVersionSupplier,
                                  org.apache.cassandra.cdc.api.SchemaSupplier schemaSupplier,
                                  SchemaStorePublisherFactory schemaStorePublisherFactory,
                                  KafkaOptions kafkaOptions)
    • Method Detail

      • initialize

        public void initialize()
        `initialize()` must be called on server start-up once all other dependencies are initialized, e.g. when Sidecar has fully initialized connections to Cassandra.
      • onConfigChange

        public void onConfigChange()
        `onConfigChange()` should be called whenever the Kafka config is changed and the publisher needs to be rebuilt.
      • onSchemaChange

        public void onSchemaChange()
        `onSchemaChanged()` should be called whenever a Cassandra CQL schema change is detected.
      • schemaConverter

        @NotNull
        protected org.apache.cassandra.cdc.avro.CqlToAvroSchemaConverter schemaConverter()
      • getSchema

        public org.apache.avro.Schema getSchema​(java.lang.String namespace,
                                                java.lang.String name)
        Description copied from interface: SchemaStore
        Get the avro corresponding to the namespace and the name of the schema
        Specified by:
        getSchema in interface SchemaStore
        Returns:
        avro schema, or return null if nothing can be found
      • getWriter

        public org.apache.avro.generic.GenericDatumWriter<org.apache.avro.generic.GenericRecord> getWriter​(java.lang.String namespace,
                                                                                                           java.lang.String name)
        Description copied from interface: SchemaStore
        Get the datum writer
        Specified by:
        getWriter in interface SchemaStore
        Returns:
        datum writer or null if schema is not found
      • getReader

        public org.apache.avro.generic.GenericDatumReader<org.apache.avro.generic.GenericRecord> getReader​(java.lang.String namespace,
                                                                                                           java.lang.String name)
        Description copied from interface: SchemaStore
        Get the datum reader
        Specified by:
        getReader in interface SchemaStore
        Returns:
        datum reader or null if schema is not found
      • getVersion

        public java.lang.String getVersion​(java.lang.String namespace,
                                           java.lang.String name)
        Description copied from interface: SchemaStore
        Get the schema version corresponding to the namespace and the name of the schema
        Specified by:
        getVersion in interface SchemaStore
        Returns:
        a type 3 (name based) UUID generated based on the MD5 of the CQL schema, or return null if nothing can be found
      • getSchemas

        public java.util.Map<java.lang.String,​org.apache.avro.Schema> getSchemas()