Interface SchemaManager

  • All Known Implementing Classes:
    SchemaManagerImpl

    public interface SchemaManager
    A manager for Schema Registry schemas.
    • Method Detail

      • getSchema

        RegisteredSchema getSchema​(String topicName,
                                   Optional<EmbeddedFormat> format,
                                   Optional<String> subject,
                                   Optional<io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy> subjectNameStrategy,
                                   Optional<Integer> schemaId,
                                   Optional<Integer> schemaVersion,
                                   Optional<String> rawSchema,
                                   boolean isKey)
        Returns a schema matching the parameter options.

        There are two pieces of information required to get an schema: the subject to which the schema is/should be registered, and a schema identifier (or schema itself).

        The first bit is handled by subject and subjectNameStrategy, which are mutually exclusive. If subject is passed, that's the subject used. If subjectNameStrategy is passed instead, then it will be used to generate the subject. All strategies (TOPIC_NAME, RECORD_NAME and TOPIC_RECORD_NAME) are valid if using schemaId or rawSchema, but only TOPIC_NAME is valid for everything else. If neither subject or subjectNameStrategy are passed, a default strategy is used based off the configs schema.registry.key.subject.name.strategy and schema.registry.value.subject.name.strategy. The same considerations above apply for which default strategies are valid.

        The second bit is handled by schemaId, schemaVersion and rawSchema, which are mutually exclusive. If schemaId is passed, that schema is going to be used, but only if the subject (see previous paragraph) contains a version mapped to that schema ID. If schemaVersion is used, then that version of subject is going to be used. If rawSchema is used, a new version with that schema is going to be registered in the subject, unless the subject already has a version with exactly the same schema, in which case no new version is registered and that version is used instead. If neither schemaId, schemaVersion or rawSchema are passed, the latest version of the subject is used.

        If passing rawSchema, format is mandatory. format is otherwise illegal to be passed.

        Schema Registry is not very descriptive as for error causes, so non-existing subject, schema ID or schema version will result in SerializationException, as it will any other Schema Registry related error. Invalid combination of options will result in IllegalArgumentException.

        Parameters:
        topicName - the topic name
        format - the format
        subject - the subject
        subjectNameStrategy - subject name strategy
        schemaId - schema id
        schemaVersion - schema version
        rawSchema - raw schema
        isKey - indicator if it is the key
        Returns:
        RegisteredSchema