接口 Schema<T>

    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static Schema<java.lang.Boolean> BOOL
      Boolean Schema.
      static Schema<java.nio.ByteBuffer> BYTEBUFFER
      ByteBuffer Schema.
      static Schema<byte[]> BYTES
      Schema that doesn't perform any encoding on the message payloads.
      static Schema<java.util.Date> DATE
      Date Schema.
      static Schema<java.lang.Double> DOUBLE
      Double Schema.
      static Schema<java.lang.Float> FLOAT
      Float Schema.
      static Schema<java.time.Instant> INSTANT
      Instant Schema.
      static Schema<java.lang.Short> INT16
      INT16 Schema.
      static Schema<java.lang.Integer> INT32
      INT32 Schema.
      static Schema<java.lang.Long> INT64
      INT64 Schema.
      static Schema<java.lang.Byte> INT8
      INT8 Schema.
      static Schema<java.time.LocalDate> LOCAL_DATE
      LocalDate Schema.
      static Schema<java.time.LocalDateTime> LOCAL_DATE_TIME
      LocalDateTime Schema.
      static Schema<java.time.LocalTime> LOCAL_TIME
      LocalTime Schema.
      static Schema<java.lang.String> STRING
      Schema that can be used to encode/decode messages whose values are String.
      static Schema<java.sql.Time> TIME
      Time Schema.
      static Schema<java.sql.Timestamp> TIMESTAMP
      Timestamp Schema.
    • 方法概要

      所有方法 静态方法 实例方法 抽象方法 默认方法 已过时的方法 
      修饰符和类型 方法 说明
      static Schema<GenericRecord> AUTO()
      已过时。
      static Schema<GenericRecord> AUTO_CONSUME()
      Create a schema instance that automatically deserialize messages based on the current topic schema.
      static Schema<byte[]> AUTO_PRODUCE_BYTES()
      Create a schema instance that accepts a serialized payload and validates it against the topic schema.
      static Schema<byte[]> AUTO_PRODUCE_BYTES​(Schema<?> schema)
      Create a schema instance that accepts a serialized payload and validates it against the schema specified.
      static <T> Schema<T> AVRO​(java.lang.Class<T> pojo)
      Create a Avro schema type by default configuration of the class.
      static <T> Schema<T> AVRO​(SchemaDefinition<T> schemaDefinition)
      Create a Avro schema type with schema definition.
      Schema<T> clone()
      Duplicates the schema.
      default void configureSchemaInfo​(java.lang.String topic, java.lang.String componentName, SchemaInfo schemaInfo)
      Configure the schema to use the provided schema info.
      default T decode​(byte[] bytes)
      Decode a byte array into an object using the schema definition and deserializer implementation.
      default T decode​(byte[] bytes, byte[] schemaVersion)
      Decode a byte array into an object using a given version.
      default T decode​(java.nio.ByteBuffer data, byte[] schemaVersion)
      Decode a ByteBuffer into an object using a given version.
      byte[] encode​(T message)
      Encode an object representing the message content into a byte array.
      static GenericSchema<GenericRecord> generic​(SchemaInfo schemaInfo)
      Returns a generic schema of existing schema info.
      default java.util.Optional<java.lang.Object> getNativeSchema()
      Return the native schema that is wrapped by Pulsar API.
      static Schema<?> getSchema​(SchemaInfo schemaInfo)  
      SchemaInfo getSchemaInfo()  
      static <T> Schema<T> JSON​(java.lang.Class<T> pojo)
      Create a JSON schema type by extracting the fields of the specified class.
      static <T> Schema<T> JSON​(SchemaDefinition schemaDefinition)
      Create a JSON schema type with schema definition.
      static <K,​V>
      Schema<KeyValue<K,​V>>
      KeyValue​(java.lang.Class<K> key, java.lang.Class<V> value)
      Key Value Schema whose underneath key and value schemas are JSONSchema.
      static <K,​V>
      Schema<KeyValue<K,​V>>
      KeyValue​(java.lang.Class<K> key, java.lang.Class<V> value, SchemaType type)
      Key Value Schema using passed in schema type, support JSON and AVRO currently.
      static <K,​V>
      Schema<KeyValue<K,​V>>
      KeyValue​(Schema<K> key, Schema<V> value)
      Key Value Schema using passed in key and value schemas.
      static <K,​V>
      Schema<KeyValue<K,​V>>
      KeyValue​(Schema<K> key, Schema<V> value, KeyValueEncodingType keyValueEncodingType)
      Key Value Schema using passed in key, value and encoding type schemas.
      static Schema<KeyValue<byte[],​byte[]>> KV_BYTES()
      Schema that can be used to encode/decode KeyValue.
      static <T extends com.google.protobuf.GeneratedMessageV3>
      Schema<T>
      PROTOBUF​(java.lang.Class<T> clazz)
      Create a Protobuf schema type by extracting the fields of the specified class.
      static <T extends com.google.protobuf.GeneratedMessageV3>
      Schema<T>
      PROTOBUF​(SchemaDefinition<T> schemaDefinition)
      Create a Protobuf schema type with schema definition.
      static <T extends com.google.protobuf.GeneratedMessageV3>
      Schema<T>
      PROTOBUF_NATIVE​(java.lang.Class<T> clazz)
      Create a Protobuf-Native schema type by extracting the fields of the specified class.
      static <T extends com.google.protobuf.GeneratedMessageV3>
      Schema<T>
      PROTOBUF_NATIVE​(SchemaDefinition<T> schemaDefinition)
      Create a Protobuf-Native schema type with schema definition.
      default boolean requireFetchingSchemaInfo()
      Check if this schema requires fetching schema info to configure the schema.
      default void setSchemaInfoProvider​(SchemaInfoProvider schemaInfoProvider)  
      default boolean supportSchemaVersioning()
      Returns whether this schema supports versioning.
      default void validate​(byte[] message)
      Check if the message is a valid object for this schema.
    • 字段详细资料

      • BYTES

        static final Schema<byte[]> BYTES
        Schema that doesn't perform any encoding on the message payloads. Accepts a byte array and it passes it through.
      • BYTEBUFFER

        static final Schema<java.nio.ByteBuffer> BYTEBUFFER
        ByteBuffer Schema.
      • STRING

        static final Schema<java.lang.String> STRING
        Schema that can be used to encode/decode messages whose values are String. The payload is encoded with UTF-8.
      • INT8

        static final Schema<java.lang.Byte> INT8
        INT8 Schema.
      • INT16

        static final Schema<java.lang.Short> INT16
        INT16 Schema.
      • INT32

        static final Schema<java.lang.Integer> INT32
        INT32 Schema.
      • INT64

        static final Schema<java.lang.Long> INT64
        INT64 Schema.
      • BOOL

        static final Schema<java.lang.Boolean> BOOL
        Boolean Schema.
      • FLOAT

        static final Schema<java.lang.Float> FLOAT
        Float Schema.
      • DOUBLE

        static final Schema<java.lang.Double> DOUBLE
        Double Schema.
      • DATE

        static final Schema<java.util.Date> DATE
        Date Schema.
      • TIME

        static final Schema<java.sql.Time> TIME
        Time Schema.
      • TIMESTAMP

        static final Schema<java.sql.Timestamp> TIMESTAMP
        Timestamp Schema.
      • INSTANT

        static final Schema<java.time.Instant> INSTANT
        Instant Schema.
      • LOCAL_DATE

        static final Schema<java.time.LocalDate> LOCAL_DATE
        LocalDate Schema.
      • LOCAL_TIME

        static final Schema<java.time.LocalTime> LOCAL_TIME
        LocalTime Schema.
      • LOCAL_DATE_TIME

        static final Schema<java.time.LocalDateTime> LOCAL_DATE_TIME
        LocalDateTime Schema.
    • 方法详细资料

      • validate

        default void validate​(byte[] message)
        Check if the message is a valid object for this schema.

        The implementation can choose what its most efficient approach to validate the schema. If the implementation doesn't provide it, it will attempt to use decode(byte[]) to see if this schema can decode this message or not as a validation mechanism to verify the bytes.

        参数:
        message - the messages to verify
        抛出:
        SchemaSerializationException - if it is not a valid message
      • encode

        byte[] encode​(T message)
        Encode an object representing the message content into a byte array.
        参数:
        message - the message object
        返回:
        a byte array with the serialized content
        抛出:
        SchemaSerializationException - if the serialization fails
      • supportSchemaVersioning

        default boolean supportSchemaVersioning()
        Returns whether this schema supports versioning.

        Most of the schema implementations don't really support schema versioning, or it just doesn't make any sense to support schema versionings (e.g. primitive schemas). Only schema returns GenericRecord should support schema versioning.

        If a schema implementation returns false, it should implement decode(byte[]); while a schema implementation returns true, it should implement decode(byte[], byte[]) instead.

        返回:
        true if this schema implementation supports schema versioning; otherwise returns false.
      • setSchemaInfoProvider

        default void setSchemaInfoProvider​(SchemaInfoProvider schemaInfoProvider)
      • decode

        default T decode​(byte[] bytes)
        Decode a byte array into an object using the schema definition and deserializer implementation.
        参数:
        bytes - the byte array to decode
        返回:
        the deserialized object
      • decode

        default T decode​(byte[] bytes,
                         byte[] schemaVersion)
        Decode a byte array into an object using a given version.
        参数:
        bytes - the byte array to decode
        schemaVersion - the schema version to decode the object. null indicates using latest version.
        返回:
        the deserialized object
      • decode

        default T decode​(java.nio.ByteBuffer data,
                         byte[] schemaVersion)
        Decode a ByteBuffer into an object using a given version.
        参数:
        data - the ByteBuffer to decode
        schemaVersion - the schema version to decode the object. null indicates using latest version.
        返回:
        the deserialized object
      • getSchemaInfo

        SchemaInfo getSchemaInfo()
        返回:
        an object that represents the Schema associated metadata
      • requireFetchingSchemaInfo

        default boolean requireFetchingSchemaInfo()
        Check if this schema requires fetching schema info to configure the schema.
        返回:
        true if the schema requires fetching schema info to configure the schema, otherwise false.
      • configureSchemaInfo

        default void configureSchemaInfo​(java.lang.String topic,
                                         java.lang.String componentName,
                                         SchemaInfo schemaInfo)
        Configure the schema to use the provided schema info.
        参数:
        topic - topic name
        componentName - component name
        schemaInfo - schema info
      • clone

        Schema<T> clone()
        Duplicates the schema.
        返回:
        The duplicated schema.
      • getNativeSchema

        default java.util.Optional<java.lang.Object> getNativeSchema()
        Return the native schema that is wrapped by Pulsar API. For instance with this method you can access the Avro schema
        返回:
        the internal schema or null if not present
      • PROTOBUF

        static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF​(java.lang.Class<T> clazz)
        Create a Protobuf schema type by extracting the fields of the specified class.
        参数:
        clazz - the Protobuf generated class to be used to extract the schema
        返回:
        a Schema instance
      • PROTOBUF

        static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF​(SchemaDefinition<T> schemaDefinition)
        Create a Protobuf schema type with schema definition.
        参数:
        schemaDefinition - schemaDefinition the definition of the schema
        返回:
        a Schema instance
      • PROTOBUF_NATIVE

        static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF_NATIVE​(java.lang.Class<T> clazz)
        Create a Protobuf-Native schema type by extracting the fields of the specified class.
        参数:
        clazz - the Protobuf generated class to be used to extract the schema
        返回:
        a Schema instance
      • PROTOBUF_NATIVE

        static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF_NATIVE​(SchemaDefinition<T> schemaDefinition)
        Create a Protobuf-Native schema type with schema definition.
        参数:
        schemaDefinition - schemaDefinition the definition of the schema
        返回:
        a Schema instance
      • AVRO

        static <T> Schema<T> AVRO​(java.lang.Class<T> pojo)
        Create a Avro schema type by default configuration of the class.
        参数:
        pojo - the POJO class to be used to extract the Avro schema
        返回:
        a Schema instance
      • AVRO

        static <T> Schema<T> AVRO​(SchemaDefinition<T> schemaDefinition)
        Create a Avro schema type with schema definition.
        参数:
        schemaDefinition - the definition of the schema
        返回:
        a Schema instance
      • JSON

        static <T> Schema<T> JSON​(java.lang.Class<T> pojo)
        Create a JSON schema type by extracting the fields of the specified class.
        参数:
        pojo - the POJO class to be used to extract the JSON schema
        返回:
        a Schema instance
      • JSON

        static <T> Schema<T> JSON​(SchemaDefinition schemaDefinition)
        Create a JSON schema type with schema definition.
        参数:
        schemaDefinition - the definition of the schema
        返回:
        a Schema instance
      • KeyValue

        static <K,​V> Schema<KeyValue<K,​V>> KeyValue​(java.lang.Class<K> key,
                                                                java.lang.Class<V> value,
                                                                SchemaType type)
        Key Value Schema using passed in schema type, support JSON and AVRO currently.
      • KV_BYTES

        static Schema<KeyValue<byte[],​byte[]>> KV_BYTES()
        Schema that can be used to encode/decode KeyValue.
      • KeyValue

        static <K,​V> Schema<KeyValue<K,​V>> KeyValue​(java.lang.Class<K> key,
                                                                java.lang.Class<V> value)
        Key Value Schema whose underneath key and value schemas are JSONSchema.
      • KeyValue

        static <K,​V> Schema<KeyValue<K,​V>> KeyValue​(Schema<K> key,
                                                                Schema<V> value)
        Key Value Schema using passed in key and value schemas.
      • AUTO_CONSUME

        static Schema<GenericRecord> AUTO_CONSUME()
        Create a schema instance that automatically deserialize messages based on the current topic schema.

        The messages values are deserialized into a GenericRecord object, that extends the GenericObject interface.

        返回:
        the auto schema instance
      • AUTO_PRODUCE_BYTES

        static Schema<byte[]> AUTO_PRODUCE_BYTES()
        Create a schema instance that accepts a serialized payload and validates it against the topic schema.

        Currently this is only supported with Avro and JSON schema types.

        This method can be used when publishing a raw JSON payload, for which the format is known and a POJO class is not available.

        返回:
        the auto schema instance
      • AUTO_PRODUCE_BYTES

        static Schema<byte[]> AUTO_PRODUCE_BYTES​(Schema<?> schema)
        Create a schema instance that accepts a serialized payload and validates it against the schema specified.
        返回:
        the auto schema instance
        从以下版本开始:
        2.5.0
        另请参阅:
        AUTO_PRODUCE_BYTES()
      • generic

        static GenericSchema<GenericRecord> generic​(SchemaInfo schemaInfo)
        Returns a generic schema of existing schema info.

        Only supports AVRO and JSON.

        参数:
        schemaInfo - schema info
        返回:
        a generic schema instance