All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.kafka.producer.SchemaManager Maven / Gradle / Ivy

There is a newer version: 2.1.37
Show newest version
/*
 * Copyright 2021 Confluent Inc.
 *
 * Licensed under the Confluent Community License (the "License"); you may not use
 * this file except in compliance with the License.  You may obtain a copy of the
 * License at
 *
 * http://www.confluent.io/confluent-community-license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.networknt.kafka.producer;

import io.confluent.kafka.serializers.subject.strategy.SubjectNameStrategy;
import com.networknt.kafka.entity.EmbeddedFormat;

import java.util.Optional;

/**
 * A manager for Schema Registry {@link RegisteredSchema schemas}.
 */
public interface SchemaManager {
    /**
     * Returns a {@link RegisteredSchema 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 {@code subject} and {@code subjectNameStrategy}, which are * mutually exclusive. If {@code subject} is passed, that's the subject used. If {@code * 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 {@code schemaId} * or {@code rawSchema}, but only TOPIC_NAME is valid for everything else. If neither {@code * subject} or {@code subjectNameStrategy} are passed, a default strategy is used based off the * configs {@code schema.registry.key.subject.name.strategy} and {@code * schema.registry.value.subject.name.strategy}. The same considerations above apply for which * default strategies are valid. * *

The second bit is handled by {@code schemaId}, {@code schemaVersion} and {@code rawSchema}, * which are mutually exclusive. If {@code 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 {@code schemaVersion} is used, then that version of subject is going to be used. If {@code * 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 {@code schemaId}, {@code * schemaVersion} or {@code rawSchema} are passed, the latest version of the subject is used. * *

If passing {@code rawSchema}, {@code format} is mandatory. {@code 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 {@link * org.apache.kafka.common.errors.SerializationException}, as it will any other Schema Registry * related error. Invalid combination of options will result in {@link IllegalArgumentException}. * @return RegisteredSchema * @param topicName the topic name * @param format the format * @param subject the subject * @param subjectNameStrategy subject name strategy * @param schemaId schema id * @param schemaVersion schema version * @param rawSchema raw schema * @param isKey indicator if it is the key */ RegisteredSchema getSchema( String topicName, Optional format, Optional subject, Optional subjectNameStrategy, Optional schemaId, Optional schemaVersion, Optional rawSchema, boolean isKey); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy