Download the PHP package vadimon/kafka-router-for-laravel without Composer
On this page you can find all versions of the php package vadimon/kafka-router-for-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vadimon/kafka-router-for-laravel
More information about vadimon/kafka-router-for-laravel
Files in vadimon/kafka-router-for-laravel
Package kafka-router-for-laravel
Short Description Package for Laravel to route consumed kafka messages to controllers same way as HTTP requests
License MIT
Homepage https://github.com/vadimonus/kafka-router-for-laravel
Informations about the package kafka-router-for-laravel
Laravel router for Kafka messages
Introduction
This package provides a way to route Kafka messages to controllers same way as for web routes.
Installation
Require this package with composer.
Install application service provider and route map file.
Register KafkaRouteServiceProvider
in config/app.php
Usage
Consume
This package is aimed only to route messages. You need some other solution to consume message.
Route
Simply pass consumed message to KafkaRoute::dispatch
, and it will be routed to controller, specified by route map.
If you consume messages from multiple connections, you can also provide connection name.
Route map
By default, route map is defined in routes/kafka.php
. You can override this in KafkaRouterServiceProvider::map()
method.
Topics
The handler for messages is defined by KafkaRoute::topic
method.
Topic names are case-sensitive. *
mean any topic.
Fallback route
Routes are matched in order, in which they are provided. If you need some fallback, put handler
for *
after all other routes
Connections
You can use KafkaRoute::connection
to specify different handlers for different connections.
Connection names are case-sensitive. *
mean any connection.
Middleware
You can assign middleware in route table
Groups
Groups allow to specify connection
and middleware
in one call.
Controller
You can write controllers same way, you write them for HTTP requests. The only difference - you do not need to return anything from controller.
To access message, connection name and router in controller method, you can
use Dependency Injection or KafkaRoute
facade.
Middleware
You can write middleware same way, you write them for HTTP requests. The only difference - you do not need to return anything from middleware.
Writing middleware
Closure middleware example:
Class middleware example:
Assigning middleware
You can assign middleware in routing table (see above), or in controller constructor, same way this is done in HTTP controllers.
All versions of kafka-router-for-laravel with dependencies
ext-rdkafka Version >=3.1.2
laravel/framework Version ^6.20.1|^7.29.1|^8.12.1|>=9