PHPackages                             chenxchen/laravel-kafka-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. chenxchen/laravel-kafka-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

chenxchen/laravel-kafka-php
===========================

kafka-php for laravel

9187[2 issues](https://github.com/CHENXCHEN/laravel-kafka-php/issues)PHP

Since Mar 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/CHENXCHEN/laravel-kafka-php)[ Packagist](https://packagist.org/packages/chenxchen/laravel-kafka-php)[ RSS](/packages/chenxchen-laravel-kafka-php/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Kafka Queue Driver for Laravel
==============================

[](#kafka-queue-driver-for-laravel)

How to use
----------

[](#how-to-use)

### 1. Install the [CHENXCHEN/kafka-php](https://github.com/CHENXCHEN/kafka-php)

[](#1-install-the-chenxchenkafka-php)

```
composer require chenxchen/kafka-php:dev-baoshi
```

Here is a minimal example of a composer.json file:

```
{
	"require": {
		"chenxchen/kafka-php": "dev-baoshi"
	}
}
```

### 2. Define you queue in `config/queue.php` :

[](#2-define-you-queue-in-configqueuephp-)

```
return [
// ...
    'connections' => [
        'kafka-demo' => [
            'driver' => 'd-kafka',
            'metadataBrokerList' => '127.0.0.1:9092', // If the producer and consumer do not configure this configuration item, this configuration item will be used by producers and consumers.
            'topics' => ['local_test', ], // If the producer and consumer do not configure this configuration item, this configuration item will be used by producers and consumers.
            'brokerVersion' => '2.0.0', // If the producer and consumer do not configure this configuration item, this configuration item will be used by producers and consumers.
            'producer' => [
//                 'topics' => ['local_test', 'local_test_2', ],
                'compression' => \Kafka\Protocol\Produce::COMPRESSION_GZIP,
                'metadataRefreshIntervalMs' => 10000,
//                'metadataBrokerList' => '',
//                'brokerVersion' => '2.0.0',
                'requiredAck' => '1',
                'produceInterval' => 500,
                'timeout' => 5000,
            ],
            'consumer' => [
//                'topics' => ['local_test', 'local_test_2', ],
                'metadataRefreshIntervalMs' => 10000,
                'consumeMode' => \Kafka\ConsumerConfig::CONSUME_BEFORE_COMMIT_OFFSET,
//                'metadataBrokerList' => '',
                'groupId' => 'test-chc',
//                'brokerVersion' => '2.0.0',
//                'sessionTimeout' => 30000,
//                'rebalanceTimeout' => 30000,
                'maxBytes' => 65536,
                'maxWaitTime' => 100,
                'executeHandle' => \App\Jobs\KafkaDemo\KafkaDemoHandle::class, // consumer handle
            ],
        ]
    ],
// ...
];
```

### 3. Define your Job

[](#3-define-your-job)

```
