jobcloud / php-kafka-schema-registry-client
Kafka Schema Registry API Client
Installs: 57 335
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 18
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- ext-json: *
- psr/http-client: ^1.0.1
- psr/http-message: ^1.0.1 || ^2.0.0
Requires (Dev)
- infection/infection: ^0.26.6
- kriswallsmith/buzz: ^1.2.1
- nyholm/psr7: ^1.5.1
- php-mock/php-mock-phpunit: ^2.6.0
- phpstan/phpstan: ^1.7.15
- phpunit/phpunit: ^9.5.21
- pimple/pimple: ^3.5.0
- rregeer/phpunit-coverage-check: ^0.3.1
- squizlabs/php_codesniffer: ^3.7.1
README
Kafka Schema Registry API Client
Description
An API Client written in PHP to communicate with Kafka Schema Registry.
Installation
composer require jobcloud/php-kafka-schema-registry-client
Requirements
- php: ^8.0
Supported API calls
Currently it supports:
- Get list of subjects
- Get list of schema versions for a subject
- Delete Subject
- Delete Schema version
- Get Subject's Schema by version
- Get Schema by ID
- Register new Schema Version for a subject
- Check Schema compatibility for schema version that exist for subject
- Get Default Compatibility level
- Set Default Compatibility level
- Get Compatibility level of subject
- Set Compatibility level for subject
- Get Version by providing schema for a subject
- Get Subject's latest schema version
- Setting the registry mode
Code example
<?php use Buzz\Client\Curl; use Jobcloud\Kafka\SchemaRegistryClient\ErrorHandler; use Jobcloud\Kafka\SchemaRegistryClient\HttpClient; use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClient; use Nyholm\Psr7\Factory\Psr17Factory; require 'vendor/autoload.php'; $psr17Factory = new Psr17Factory(); $client = new Curl($psr17Factory); $username = 'USERNAME'; $password = 'PASSWORD'; $registryClient = new HttpClient( $client, $psr17Factory, new ErrorHandler(), 'http://your-registry-schema-server-url:9081', $username ?? null, $password ?? null ); $schema = '{"type":"record","name":"something","namespace":"whatever.you.want","fields":[{"name":"id","type":"string"}]}'; $registryClientApi = new KafkaSchemaRegistryApiClient($registryClient); $subjectName = 'some.subject.name'; $results = $registryClientApi->getVersionForSchema($subjectName, $schema);
If you are using Pimple Container in you App, you can use Service Provider:
use Jobcloud\Kafka\SchemaRegistryClient\ServiceProvider\KafkaSchemaRegistryApiClientProvider; use Pimple\Container; $container = new Container(); $container['kafka.schema.registry'] = [ 'base.url' => 'http://your-registry-schema-server-url:9081', 'username' => 'your_username', 'password' => 'your_password', ]; $container->register(new KafkaSchemaRegistryApiClientProvider()); $api = $container['kafka.schema.registry.client.api']); $data = $api->getSubjects();
Contributing
This is an open source project that welcomes pull requests and issues from anyone.
This is the API reference to follow for any new functionality:
https://docs.confluent.io/current/schema-registry/develop/api.html