Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rdkafka Laravel Package

enqueue/rdkafka

Kafka transport for Enqueue using the RdKafka (librdkafka) extension. Implements Queue Interop so you can produce and consume messages via Kafka with Enqueue tooling. Links to docs, support channels, and issue tracker.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Architecture (EDA) Alignment: The package enables Kafka integration for Laravel via Queue Interop, making it ideal for microservices, event sourcing, or real-time architectures. It bridges Laravel’s queue system with Kafka’s distributed model, enabling scalable, decoupled workflows.
  • Polyglot Compatibility: Leverages librdkafka (C library) for high-performance Kafka communication, ensuring low-latency message processing. This is critical for Laravel apps interacting with polyglot systems (e.g., Python, Java, or Go services) via Kafka.
  • Protocol Adherence: Implements Queue Interop, ensuring seamless integration with other Enqueue transports (e.g., RabbitMQ, Redis) for hybrid queue strategies.

Integration Feasibility

  • Laravel Queue Integration:
    • Can be used as a custom queue driver in Laravel’s config/queue.php by extending Enqueue\Client\Producer/Consumer and wrapping it in Laravel’s Queue facade.
    • Supports delayed jobs, batch processing, and retry mechanisms via Enqueue’s abstractions.
  • Kafka-Specific Features:
    • Partitioning: Explicit control over Kafka partitions for ordered processing or load balancing.
    • Consumer Groups: Native support for Kafka consumer groups (critical for horizontal scaling).
    • Schema Registry: Can integrate with Avro/Protobuf via Kafka’s schema tools (though this requires additional setup).
  • Dependency Overhead:
    • Requires librdkafka (C extension) and PHP’s ext-kafka or rdkafka PECL extension. Docker/Kubernetes deployments simplify this via pre-built images (e.g., confluentinc/cp-kafka).
    • PHP 8.0+ recommended (compatibility with Enqueue 3.x).

Technical Risk

  • Extension Dependencies:
    • librdkafka must be installed system-wide or via Docker. Misconfiguration (e.g., wrong Kafka broker URLs, SASL/SSL misalignment) can cause silent failures.
    • PECL conflicts: If other Kafka-related PECL extensions (e.g., kafka) are installed, version clashes may arise.
  • Laravel-Specific Gaps:
    • No native support for Laravel’s job middleware (e.g., AfterCommitMiddleware). Workarounds require custom middleware wrapping Enqueue’s Context.
    • Job batching: Laravel’s batch() method may not translate cleanly to Kafka’s producer->produceBatch() without custom logic.
  • Operational Complexity:
    • Kafka’s offset management (e.g., manual commits) requires careful handling to avoid duplicate processing or missed messages.
    • Monitoring: Lack of built-in Laravel Scout/Horizon integration for Kafka metrics (e.g., lag, throughput).

Key Questions

  1. Deployment Model:
    • Will Kafka brokers be self-hosted (e.g., Strimzi on Kubernetes) or managed (e.g., Confluent Cloud)? This affects SSL/SASL configuration and scaling.
  2. Message Serialization:
    • Will messages use JSON, Protobuf, or Avro? Protobuf/Avro require schema registry integration (e.g., confluentinc/schema-registry).
  3. Fault Tolerance:
    • How will failed jobs be handled? Kafka’s max.in.flight.requests.per.connection and retries must align with Laravel’s queue retry logic.
  4. Performance Baseline:
    • What are the expected throughput requirements (e.g., 1K vs. 100K messages/sec)? This dictates partition count and consumer scaling.
  5. Team Expertise:
    • Does the team have experience with Kafka’s consumer groups, offset commits, or exactly-once semantics? Training may be needed.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Queue Drivers: Replace or extend Laravel’s default drivers (database, redis) with Kafka via Enqueue\Dbal\DbalContext or custom QueueServiceProvider.
    • Event Dispatching: Use Kafka as a pub/sub backbone for domain events (e.g., OrderCreated) alongside Laravel’s bus or events.
    • Task Queues: Offload long-running tasks (e.g., PDF generation) to Kafka consumers with horizontal scaling.
  • Tech Stack Synergy:
    • Symfony/Enqueue: If the app uses Symfony components, this package integrates natively.
    • Docker/K8s: Ideal for containerized deployments with sidecar Kafka clients (e.g., bitnami/kafka).
    • CI/CD: Kafka topics can serve as pipeline triggers (e.g., GitHub Actions webhooks → Kafka → Laravel consumers).

Migration Path

  1. Phase 1: Proof of Concept
    • Replace a single Laravel queue driver (e.g., redis) with Kafka for a non-critical workflow (e.g., notifications).
    • Validate:
      • Message serialization/deserialization.
      • Consumer group behavior (no duplicates/misses).
      • End-to-end latency.
  2. Phase 2: Hybrid Integration
    • Use Enqueue’s Context to route messages between Kafka and other transports (e.g., Redis for local jobs, Kafka for distributed).
    • Example:
      $context = new Enqueue\Context\Context();
      $context->addTransport(new Enqueue\Kafka\KafkaTransport($producer));
      $context->addTransport(new Enqueue\Redis\RedisTransport($redis));
      
  3. Phase 3: Full Adoption
    • Migrate all background jobs to Kafka, leveraging:
      • Partitioned topics for ordered processing.
      • Consumer groups for horizontal scaling.
      • Schema Registry for structured data.

Compatibility

  • Laravel Versions:
    • Tested with Laravel 8+ (PHP 8.0+). For Laravel 7, use Enqueue 2.x.
  • Kafka Compatibility:
    • Supports Kafka 0.10+ (including schema registry).
    • SASL/SSL: Configure via rdkafka.conf or KafkaTransport constructor.
  • Enqueue Extensions:
    • Works with enqueue/doctrine, enqueue/horizon (limited), or enqueue/amqp for hybrid setups.

Sequencing

  1. Infrastructure Setup:
    • Deploy Kafka cluster (or use managed service).
    • Install librdkafka and PHP extensions (pecl install rdkafka).
  2. Laravel Configuration:
    • Add to composer.json:
      "enqueue/rdkafka": "^3.0",
      "ext-kafka": "*"
      
    • Configure in config/queue.php:
      'connections' => [
          'kafka' => [
              'driver' => 'kafka',
              'hosts' => env('KAFKA_HOSTS', 'localhost:9092'),
              'username' => env('KAFKA_USERNAME'),
              'password' => env('KAFKA_PASSWORD'),
              'topic' => env('KAFKA_TOPIC', 'laravel-jobs'),
          ],
      ],
      
  3. Consumer Setup:
    • Create a Kafka consumer service (e.g., app/Services/KafkaConsumer.php):
      use Enqueue\Kafka\KafkaConsumer;
      use Enqueue\Client\ProducerInterface;
      
      class KafkaConsumerService {
          public function __construct(ProducerInterface $producer) {
              $consumer = new KafkaConsumer($producer, [
                  'group.id' => 'laravel-consumers',
              ]);
              $consumer->consume(function ($message) {
                  dispatch(new HandleJob($message->getBody()));
              });
          }
      }
      
  4. Job Dispatch:
    • Dispatch jobs via Laravel’s queue facade:
      dispatch(new ProcessPodcast)->onConnection('kafka');
      
    • Or manually:
      $producer = app(ProducerInterface::class);
      $producer->send(new Message($job->payload));
      

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor enqueue/rdkafka and librdkafka for CVE patches (e.g., Kafka’s CVE-2021-4612).
    • PHP extensions (ext-kafka) may require recompilation on OS upgrades.
  • Configuration Drift:
    • Kafka broker URLs, SASL mechanisms, or topic names may change. Use environment variables (e.g., .env) and config validation.
  • Schema Management:
    • If using Avro/Protobuf, maintain schema registry compatibility (e.g., Confluent Schema Registry) and versioning strategies.
  • Logging and Observability:
    • Implement structured logging for Kafka consumers/producers (e.g., JSON logs with message_id, partition, timestamp).
    • Integrate with **Prometheus/Grafana
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme