mateusjunges/confluent-schema-registry-api
PHP 7.4+ client for Confluent Schema Registry REST API. Provides high-level sync/async helpers plus low-level PSR-7 request builders, Avro schema support, and optional caching integration for fetching, registering, and managing schemas.
order_created) against registered schemas before processing.flix-tech/avro-php for schema parsing, which is critical for Laravel apps using Kafka Avro serialization (e.g., via rdkafka or laravel-kafka). Ensures compatibility with Confluent’s schema evolution rules.Illuminate\Http\Client) or custom middleware for schema validation.PromisingRegistry/BlockingRegistry to the container, enabling dependency injection in controllers/jobs.
// app/Providers/SchemaRegistryServiceProvider.php
public function register() {
$this->app->singleton(PromisingRegistry::class, function ($app) {
return new PromisingRegistry(
new Client(['base_uri' => config('kafka.schema_registry_url')])
);
});
}
PromisingRegistry allows non-blocking schema checks before publishing events.Illuminate\Validation) against schemas stored in the registry, ensuring consistency between HTTP payloads and Kafka topics.order_created is published, verify its schema matches the registry).| Risk Area | Mitigation Strategy |
|---|---|
| Async API Complexity | Use BlockingRegistry for synchronous workflows (e.g., API validation) and PromisingRegistry for background jobs. Document clear use cases. |
| Schema Evolution | Leverage Confluent’s built-in schema compatibility checks. Add Laravel middleware to reject incompatible schemas. |
| Caching Overhead | Start with CachedRegistry in development; monitor cache hit ratios before enabling in production. |
| Dependency Updates | Pin guzzlehttp/promises to ^2.0 and avro-php to ^4.1 in composer.json to avoid breaking changes. |
| Error Handling | Wrap registry calls in Laravel’s try-catch blocks and log SchemaRegistryException via Monolog. |
| PHP 8+ Requirement | Ensure Laravel app uses PHP 8.1+ (LTS) and update composer.json to enforce this. |
AvroSchema class or use middleware.Psr16CacheAdapter) be critical? Benchmark CachedRegistry vs. direct API calls.PromisingRegistry in unit tests.schemaId/subject lookups.spatie/flysystem-circuit-breaker).Illuminate\Validation\Rule) or Kafka payloads.KafkaEventPublished or JobProcessed to validate schemas post-publication.App\Jobs\PublishKafkaEvent).App\Listeners\HandleKafkaEvent).Psr16CacheAdapter) or Doctrine Cache for CachedRegistry to reduce registry API calls.md5((string) $schema)) or override with sha1 for consistency.register, schemaForId) in a local Kafka/Laravel setup.rdkafka/laravel-kafka packages.StoreOrderRequest) and Kafka producers.CachedRegistry with Redis and measure cache hit ratios.SchemaRegistry::register() calls).| Component | Compatibility Notes |
|---|---|
| Laravel | Works with Laravel 8+ (PHP 8.1+ recommended). Tested with guzzlehttp/guzzle v7+. |
| Kafka Clients | Compatible with rdkafka (PHP extension) or laravel-kafka for Avro serialization. |
| Caching Backends | Supports Redis, Doctrine Cache, or PSR-16/PSR-6 adapters. |
| Schema Formats | Primarily Avro (via avro-php). Protobuf support requires additional adapters. |
| Confluent Schema Registry | Tested with Confluent Platform 5.2+. Ensure API endpoints match your registry version. |
order-events → order-value subject).composer require flix-tech/confluent-schema-registry-api guzzlehttp/guzzle doctrine/cache
config/kafka.php with registry URL and caching settings.ValidateKafkaSchema).make phpunit-integration).guzzlehttp/promises (v2.x) and avro-php (v4.x) for breaking changes. Use composer why-not to assess risks.composer.json to avoid surprises:
"require": {
"flix-tech/confluent-schema-registry-api": "^9.0",
"guzzlehttp/promises": "^2.0",
"flix-tech/avro-php": "^4.1"
}
How can I help you explore Laravel packages today?