schemaregistry

package module
v0.0.0-...-9665dd9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

Schema Registry Client

Additional

FORKED FROM https://github.com/lensesio/schema-registry Updating more things in order to have a fully functional registry client

Documentation

Overview

Package schemaregistry provides a client for Confluent's Kafka Schema Registry REST API.

Index

Constants

View Source
const DefaultURL = "http://localhost:8081"

DefaultURL is the address where a local schema registry listens by default.

View Source
const SchemaLatestVersion = "latest"

SchemaLatestVersion is the only one valid string for the "versionID", it's the "latest" version string and it's used on `GetLatestSchema`.

Variables

This section is empty.

Functions

func IsSchemaNotFound

func IsSchemaNotFound(err error) bool

IsSchemaNotFound checks the returned error to see if it is kind of a schema not found error code.

func IsSubjectNotFound

func IsSubjectNotFound(err error) bool

IsSubjectNotFound checks the returned error to see if it is kind of a subject not found error code.

func JSONAvroSchema

func JSONAvroSchema(avroSchema string) (json.RawMessage, error)

JSONAvroSchema converts and returns the json form of the "avroSchema" as []byte.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the registry schema REST API client.

func NewClient

func NewClient(host string, port int, useSSL bool, options ...Option) (*Client, error)

NewClient creates & returns a new Registry Schema Client based on the passed url and the options.

func (*Client) DeleteSubject

func (c *Client) DeleteSubject(subject string) (versions []int, err error)

DeleteSubject deletes the specified subject and its associated compatibility level if registered. It is recommended to use this API only when a topic needs to be recycled or in development environment. Returns the versions of the schema deleted under this subject.

func (*Client) GetConfig

func (c *Client) GetConfig(subject string) (Config, error)

GetConfig returns the configuration (Config type) for global Schema-Registry or a specific subject. When Config returned has "compatibilityLevel" empty, it's using global settings.

func (*Client) GetLatestSchema

func (c *Client) GetLatestSchema(subject string) (Schema, error)

GetLatestSchema returns the latest version of a schema. See `GetSchemaAtVersion` to retrieve a subject schema by a specific version.

func (*Client) GetSchemaByID

func (c *Client) GetSchemaByID(subjectID int) (string, error)

GetSchemaByID returns the Auro schema string identified by the id. id (int) – the globally unique identifier of the schema.

func (*Client) GetSchemaBySubject

func (c *Client) GetSchemaBySubject(subject string, versionID int) (Schema, error)

GetSchemaBySubject returns the schema for a particular subject and version.

func (*Client) IsLatestSchemaCompatible

func (c *Client) IsLatestSchemaCompatible(subject string, avroSchema string) (bool, error)

IsLatestSchemaCompatible tests compatibility with the latest version of a subject's schema.

func (*Client) IsRegistered

func (c *Client) IsRegistered(subject, schema string) (bool, Schema, error)

IsRegistered tells if the given "schema" is registered for this "subject".

func (*Client) IsSchemaCompatible

func (c *Client) IsSchemaCompatible(subject string, avroSchema string, versionID int) (bool, error)

IsSchemaCompatible tests compatibility with a specific version of a subject's schema.

func (*Client) RegisterNewSchema

func (c *Client) RegisterNewSchema(subject string, avroSchema string) (int, error)

RegisterNewSchema registers a schema. The returned identifier should be used to retrieve this schema from the schemas resource and is different from the schema’s version which is associated with that name.

func (*Client) SetConfigLevel

func (c *Client) SetConfigLevel(cl CompatibilityLevel, subject string) (Config, error)

SetConfigLevel according to the predefined compatibility levels

func (*Client) SetConfigLevelFull

func (c *Client) SetConfigLevelFull(subject string) (Config, error)

func (*Client) Subjects

func (c *Client) Subjects() (subjects []string, err error)

Subjects returns a list of the available subjects(schemas). https://docs.confluent.io/current/schema-registry/docs/api.html#subjects

func (*Client) Versions

func (c *Client) Versions(subject string) (versions []int, err error)

Versions returns all schema version numbers registered for this subject.

type CompatibilityLevel

type CompatibilityLevel int
const (
	Backward CompatibilityLevel = iota
	BackwardTransitive
	Forward
	ForwardTransitive
	Full
	FullTransitive
	None
)

func (CompatibilityLevel) String

func (d CompatibilityLevel) String() string

Not needed so far

type Config

type Config struct {
	// CompatibilityLevel mode of subject or global
	Compatibility      string `json:"compatibility,omitempty"`
	CompatibilityLevel string `json:"compatibilityLevel,omitempty"`
}

Config describes a subject or globa schema-registry configuration

type Option

type Option func(*Client)

Option describes an optional runtime configurator that can be passed on `NewClient`. Custom `Option` can be used as well, it's just a type of `func(*schemaregistry.Client)`.

Look `UsingClient`.

func UsingClient

func UsingClient(httpClient *http.Client) Option

UsingClient modifies the underline HTTP Client that schema registry is using for contact with the backend server.

type ResourceError

type ResourceError struct {
	ErrorCode int    `json:"error_code"`
	Method    string `json:"method,omitempty"`
	URI       string `json:"uri,omitempty"`
	Message   string `json:"message,omitempty"`
}

ResourceError is being fired from all API calls when an error code is received.

func (ResourceError) Error

func (err ResourceError) Error() string

type Schema

type Schema struct {
	// Schema is the Avro schema string.
	Schema string `json:"schema"`
	// Subject where the schema is registered for.
	Subject string `json:"subject"`
	// Version of the returned schema.
	Version int `json:"version"`
	ID      int `json:"id,omitempty"`
}

Schema describes a schema, look `GetSchema` for more.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL