PHPackages                             simpod/kafka-bundle - 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. simpod/kafka-bundle

ActiveLibrary

simpod/kafka-bundle
===================

Kafka Symfony bundle.

0.7.4(1mo ago)8126.1k—0.3%7[1 issues](https://github.com/simPod/PhpKafkaBundle/issues)MITPHPPHP ^8.4CI passing

Since Aug 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/simPod/PhpKafkaBundle)[ Packagist](https://packagist.org/packages/simpod/kafka-bundle)[ GitHub Sponsors](https://github.com/simPod)[ RSS](/packages/simpod-kafka-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (30)Versions (27)Used By (0)

PHP Kafka Symfony bundle for php-rdkafka
========================================

[](#php-kafka-symfony-bundle-for-php-rdkafka)

[![GitHub Actions](https://github.com/simPod/PhpKafkaBundle/workflows/CI/badge.svg)](https://github.com/simPod/PhpKafkaBundle/actions?query=workflow%3A%22CI%22+branch%3Amaster)[![Code Coverage](https://camo.githubusercontent.com/3623727deadfa423be0f0593b37a3c6d03c7c75e817c3e95288da8498ade594e/68747470733a2f2f636f6465636f762e696f2f67682f73696d506f642f5068704b61666b6142756e646c652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/simPod/PhpKafkaBundle/branch/master)[![Downloads](https://camo.githubusercontent.com/b4e9c5586cced12619eb551bee13529e4f51e98a945543d220018481105a7672/68747470733a2f2f706f7365722e707567782e6f72672f73696d706f642f6b61666b612d62756e646c652f642f746f74616c2e737667)](https://packagist.org/packages/simpod/kafka-bundle)[![Packagist](https://camo.githubusercontent.com/319381908a526591725fdb9048ed95de603d3ff449bfc95646e5c95f5edfe44b/68747470733a2f2f706f7365722e707567782e6f72672f73696d706f642f6b61666b612d62756e646c652f762f737461626c652e737667)](https://packagist.org/packages/simpod/kafka-bundle)[![Infection MSI](https://camo.githubusercontent.com/5bf3730919f80611023d7abfbc0d8524d8d9b006247a3a03f2af772f24bf0014/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324673696d506f642532465068704b61666b6142756e646c652532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/simPod/PhpKafkaBundle/master)

Installation
------------

[](#installation)

Add as [Composer](https://getcomposer.org/) dependency:

```
composer require simpod/kafka-bundle
```

Then add `KafkaBundle` to Symfony's `bundles.php`:

```
use SimPod\KafkaBundle\SimPodKafkaBundle;

return [
    ...
    new SimPodKafkaBundle()
    ...
];
```

Usage
-----

[](#usage)

This package simply makes it easier to integrate  with Symfony. For more details how to work with Kafka in PHP, refer to its documentation.

### Available console commands:

[](#available-console-commands)

- `bin/console debug:kafka:consumers` to list all available consumer groups
- `bin/console kafka:consumer:run ` to run consumer instance

### Config:

[](#config)

You can create eg. `kafka.yaml` file in your config directory with following content:

```
kafka:
    authentication: '%env(KAFKA_AUTHENTICATION)%'
    bootstrap_servers: '%env(KAFKA_BOOTSTRAP_SERVERS)%'
    client:
        id: 'your-application-name'
```

- `authentication` reads env var `KAFKA_AUTHENTICATIOn` that contains authentication uri (`sasl-plain://user:password`, or it might be just empty indicating no authentication).
- `bootstrap_servers` reads env var `KAFKA_BOOTSTRAP_SERVERS` that contains comma-separated list of bootstrap servers (`broker-1.kafka:9092,broker-2.kafka:9092`).

If `bootstrap_servers` isn't set, it defaults to `127.0.0.1:9092`

### Services

[](#services)

Following services are registered in container and can be DI injected.

#### Configuration

[](#configuration)

class: `\SimPod\KafkaBundle\Kafka\Configuration`

Configuration service allows easy access to all the configuration properties.

```
$config->set(ConsumerConfig::CLIENT_ID_CONFIG, $this->configuration->getIdWithHostname());
```

### Consuming

[](#consuming)

There's interface `NamedConsumer` available. When your consumer implements it, this bundle autoregisters it.

This is example of simple consumer, it can be then run via `bin/console kafka:consumer:run consumer1`

```
