mateusjunges/confluent-schema-registry-api
A PHP library for consuming the Confluent Schema Registry REST API, offering low-level PSR-7 compliant requests plus high-level abstractions for easier developer experience. Includes async and sync APIs, caching support, and integration with Avro and Guzzle.
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) and reduces the risk of version conflicts with other Laravel packages that have already moved to Guzzle 8. The PSR-7 boundary means the registry client can be swapped for Illuminate\Http\Client-backed implementations 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).guzzlehttp/guzzle:^8. Previously, adopting this package forced a Guzzle 7 downgrade across sibling packages. This is a low-effort, high-value upgrade for teams currently pinned to guzzlehttp/promises:^2.0.| 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 | On 9.1.0+ you can pin either guzzlehttp/promises:^2.0 or ^3.0 and guzzlehttp/psr7:^2.0 or ^3.0. Keep avro-php at ^4.1. Validate with composer why-not before bumping. |
| Guzzle 7→8 Cutover (New) | 9.1.0 supports both majors, but mixed-version installs in a monorepo can resolve unpredictably. Pin guzzlehttp/guzzle explicitly and run composer update --with-dependencies in a branch, not in CI auto-updates. |
| PSR-7 v3 Behavioral Changes (New) | PSR-7 3.x normalizes header casing and stream semantics. If you wrap the registry client with custom middleware, add regression tests against header normalization and retry policies. |
| 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. |
guzzlehttp/guzzle:^8 that this release unblocks.AvroSchema class or use middleware.Psr16CacheAdapter) be critical? Benchmark CachedRegistry vs. direct API calls.PromisingRegistry in unit tests. Add Guzzle 8-specific regression tests post-upgrade.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.guzzlehttp/guzzle:^8 to match Laravel 11/12 defaults; Guzzle 7 remains supported for apps mid-upgrade. Avoid mixing majors across a monorepo; if unavoidable, isolate the registry client in its own package boundary.composer why-not guzzlehttp/guzzle ^8 and composer why-not guzzlehttp/promises ^3 to map blockers.flix-tech/avro-php:^4.1 is untouched — 9.1.0 does not change Avro parsing.register, schemaForId) in a local Kafka/Laravel setup.rdkafka/laravel-kafka packages.StoreOrderRequest) and Kafka producers.guzzlehttp/guzzle to ^8. Run the package’s Docker integration suite (make phpunit-integration) plus app-level contract tests.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+ and (as of 9.1.0) v8. |
| Guzzle / PSR-7 | 9.1.0 adds support for guzzlehttp/guzzle:^8, guzzlehttp/promises:^3, and guzzlehttp/psr7:^3, retaining backward compatibility with v7/v2. |
| 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).^7.0/^2.0 if not yet ready):
composer require flix-tech/confluent-schema-registry-api:^9.1 \
guzzlehttp/guzzle:^8.0 guzzlehttp/promises:^3.0 guzzlehttp/psr7:^3.0 \
doctrine/cache
config/kafka.php with registry URL and caching settings.ValidateKafkaSchema).make phpunit-integration)."require": {
"flix-tech/confluent-schema-registry-api": "^9.1",
"guzzlehttp/guzzle": "^8.0",
"guzzlehttp/promises": "^3.0",
"guzzlehttp/psr7": "^3.0",
"flix-tech/avro-php": "^4.1"
}
composer why-not and composer update --with-dependencies --dry-run before merging.SchemaRegistryException rates through the cutover window.composer conflict — expect faster, cleaner installs.CachedRegistry + Redis) remains the primary scaling lever.PromisingRegistry path is unchanged; batching registry lookups and caching by md5/sha1 schema hash remain the recommended pattern.CachedRegistry hit ratios as before.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Mixed Guzzle majors across monorepo (New) | Non-deterministic dependency resolution; CI flakiness | Enforce a single major via root composer.json constraints and CI composer validate. |
| PSR-7 3 header normalization regressions (New) | Custom schema-validation middleware may mis-match headers or miss content-type checks | Add contract tests against schemaForId/register with representative headers. |
| Registry unavailable | Event publishing/validation blocked | Circuit breaker + queue-and-retry pattern (unchanged). |
| Cache stampede on cold Redis | Latency spike on registry calls | Warm cache on deploy; use jittered TTLs. |
| Schema incompatibility at publish | Producer rejection | Pre-publish compatibility check via BlockingRegistry in the job pipeline. |
How can I help you explore Laravel packages today?