Download the PHP package m6web/kafka-bundle without Composer
On this page you can find all versions of the php package m6web/kafka-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package kafka-bundle
KafkaBundle
Configuration and use of KafkaBundle are based on the RdKafka extension. To consume messages, we decided to use the high level consumer.
Installation
For Symfony
`
Register the bundle:
Install the bundle:
Usage
Add the m6_web_kafka
section in your configuration file.
By default, the sf3 event dispatcher will throw an event on each command. To disable this feature:
Here a configuration example:
Librdkafka global configuration properties
Note that we decided to use the high level consumer. So you can set the "group.id" option in the consumer configuration.
For the producers, we have one topic configuration for each topic:
Whereas for the consumers, we have one topic configuration for all topics:
Producer
A producer will be used to send messages to the server.
In the Kafka Model, messages are sent to topics partitioned and stored on brokers. This means that in the configuration for a producer you will have to specify the brokers and the topics. You can optionnaly configure the log level and the strategy partitioner.
Because of RdKafka extension limitations, you cannot configure the partitions number or replication factor from the bundle. You must do that from the command line.
After setting your producers with their options, you will be able to produce a message using the produce
method :
- The first argument is the message to send.
- The second argument is the partition where to produce the message.
By default, the value is
RD_KAFKA_PARTITION_UA
which means that the message will be sent to a random partition. - The third argument is a key if the strategy partitioner is by key.
The RD_KAFKA_PARTITION_UA
constant is used according the strategy partitioner.
- If the strategy partitioner is
random
(RD_KAFKA_MSG_PARTITIONER_RANDOM
), messages are assigned to partitions randomly. - If the stratefy partitioner is
consistent
(RD_KAFKA_MSG_PARTITIONER_CONSISTENT
) with a key defined, messages are assigned to the partition whose the id maps the hash of the key. If there is no key defined, messages are assigned to the same partition.
Consumer
A consumer will be used to get a message from different topics. You can choose to set only one topic by consumer.
In the Kafka Model, messages are consumed from topics partitioned and stored on brokers. This means that for a consumer you will have to specify the brokers and topics in the configuration.
To consume messages, you will have to use the consume
method to consume a message:
The messages will be automatically committed except if there is an error. But you can choose not to do it by adding an argument as following:
You can decide to commit manually your message with:
It will commit the last consumed message.
It will give you an object \RdKafka\Message
with information about the message : payload, topic, or partition for instance.
It is the \RdKafka\Message
from the RdKafka extension.
In case there is no more message, it will give you a No more message string. In case there is a time out, it will give you a Time out string.
Exceptions list
- EntityNotSetException
- KafkaException
- LogLevelNotSetException
- NoBrokerSetException
All versions of kafka-bundle with dependencies
ext-rdkafka Version *
kwn/php-rdkafka-stubs Version ^0.0.5
symfony/dependency-injection Version ~2.6||~3.0