Download the PHP package kafka-bus/laravel-bridge without Composer

On this page you can find all versions of the php package kafka-bus/laravel-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-bridge

Kafka Bus for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style GitHub PHPStan Total Downloads

Laravel integration for kafka-bus — a configuration-driven Apache Kafka client built on top of ext-rdkafka. The package wires producers, consumer workers, topic routing, and middleware into the framework, and ships an optional Commiter component for idempotent message handling backed by the database.

Requirements

Installation

Install the package via Composer:

Publish the main configuration file:

To use the Commiter component (idempotency and commit tracking), additionally publish its configuration and migrations:

Configuration

The main configuration lives in config/kafka-bus.php and is split into four sections:

Connections

Each connection is selected by a driver and a set of options passed straight to librdkafka. The default key picks the active connection by name.

The null driver is useful for tests — calls to the bus succeed without touching a real broker.

Topics

Topic names usually depend on the environment. The bus prepends topic_prefix to every physical topic name, and the topics map binds a short logical key to that physical name.

With APP_ENV=production, products resolves to production.fact.products.1.

Producers

A producer route binds a message class to a logical topic key. The shortest form maps the class directly to a topic key:

The verbose form lets you override timeouts, append per-route middleware, and pass driver options:

Publish a message through the bus:

Or via the KafkaBus facade:

Consumers

Workers are the units consumed by the artisan command. Each worker subscribes to one or more topics and dispatches incoming messages to handler classes.

Each worker resolves options in this order: additional_options, auto_commit, consume_timeout, and middleware are taken from the worker entry, then merged with the global consumers.* defaults.

Run a worker:

Artisan commands

Command Description
kafka:consume {workerName} Start a long-running consumer for the given worker.
kafka:worker:list Show registered workers, their topic keys, resolved topic names, handlers, consumer middleware, and route middleware.
kafka:route:list Show registered producer routes (message class → topic) and middleware.
kafka:offset:show {workerName} Show current / min / max offsets for every partition of every topic the worker subscribes to.
kafka:offset:set {workerName} {topicKey} {offset} {--partition=} Set the committed offset for a topic. offset accepts earliest, latest, or a numeric value. Omit --partition to apply to all partitions of the topic.

Inspecting workers and routes

Inspecting and resetting offsets

Reset all partitions of a topic to the earliest available offset:

Move a single partition to an explicit numeric offset:

Jump every partition to the high-water mark (skip backlog):

The command prints the resulting offsets:

The worker must not be running while you reset its offsets — otherwise the active consumer group will overwrite the new position on its next commit.

Commiter

The Commiter component (powered by micromus/kafka-bus-commiter) provides:

It is registered automatically by CommiterServiceProvider (loaded via package auto-discovery).

Configuration

Enabling the consumer middleware

Add ConsumerCommiterMiddleware to the consumer middleware stack — either globally for every worker, or only for specific workers/topics:

For each message the middleware:

  1. Resolves a dedup key via the configured repository.
  2. If the key was already committed — the message is skipped and a warning is logged.
  3. If the per-key attempt count exceeds maxAttempt (when configured) — the message is skipped and an error is logged.
  4. Otherwise the pipeline is executed; on success the key is committed, on failure the attempt counter is incremented and the exception is re-thrown.

Producing idempotent messages

Implement HasIdempotency on the producer message and enable ProducerIdempotencyMiddleware:

The middleware adds the x-idempotency-key header to every outgoing message; consumers running ConsumerCommiterMiddleware with the idempotency repository will use it as the dedup key.

Testing

KafkaBus::fake()

The KafkaBus facade ships a first-class fake that works exactly like Event::fake() or Mail::fake(). Call KafkaBus::fake() at the start of a test to replace the real BusInterface binding with an in-memory FakeBus. From that point on every call to the facade is forwarded to the fake — publish() calls are intercepted and stored, consumer pipelines can be triggered directly, and the full set of assertion methods becomes available.

Asserting producer messages

Assert with a callback to inspect the serialised ProducerMessage (after the full producer pipeline, including middleware). The callback receives a Micromus\KafkaBus\Producers\Messages\ProducerMessage instance:

Other available assertions:

Retrieve the published messages directly for custom assertions:

Dispatching and asserting consumer messages

addMessage() queues an RdKafka\Message into the fake connection. Once queued, call listen() to run the full consumer path — ConnectionFakerConsumerFakerConsumerStream → consumer middleware → route middleware → handler → commit — without touching a real broker.

Queue multiple messages before triggering listen():

Asserting committed messages

After listen() each successfully processed message is committed into the fake connection. Use the commit assertions to verify that your handler ran and the offset was acknowledged:

Retrieve committed messages directly for custom assertions:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-bridge with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-rdkafka Version *
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0 || ^13.0
kafka-bus/core Version ^1.3
kafka-bus/commiter Version ^1.2
kafka-bus/messages Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kafka-bus/laravel-bridge contains the following files

Loading the files please wait ...