jobcloud / php-kafka-schema-registry-client
Kafka Schema Registry API 客户端
v2.1.0
2024-09-24 13:07 UTC
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 客户端
描述
一个用 PHP 编写的 API 客户端,用于与 Kafka Schema Registry 进行通信。
安装
composer require jobcloud/php-kafka-schema-registry-client
要求
- php: ^8.0
支持的 API 调用
目前它支持
- 获取主题列表
- 获取某个主题的架构版本列表
- 删除主题
- 删除架构版本
- 按版本获取主题的架构
- 按 ID 获取架构
- 为主题注册新的架构版本
- 检查主题存在的架构版本的兼容性
- 获取默认兼容性级别
- 设置默认兼容性级别
- 获取主题的兼容性级别
- 为主题设置兼容性级别
- 提供架构以获取版本的版本
- 获取主题的最新架构版本
- 设置注册模式
代码示例
<?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);
如果您在应用程序中使用 Pimple 容器,您可以使用 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();
贡献
这是一个开源项目,欢迎任何人提交拉取请求和问题。
这是遵循任何新功能的 API 参考:https://docs.confluent.io/current/schema-registry/develop/api.html