All Projects → Superbalist → php-pubsub-kafka

Superbalist / php-pubsub-kafka

Licence: MIT license
A Kafka adapter for the php-pubsub package

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to php-pubsub-kafka

php-pubsub
A PHP abstraction for the pub-sub pattern
Stars: ✭ 36 (+38.46%)
Mutual labels:  pubsub, superbalist, php-pubsub
php-pubsub-redis
A Redis adapter for the php-pubsub package
Stars: ✭ 24 (-7.69%)
Mutual labels:  superbalist, php-pubsub
console-chat
Chat on your terminal with other users through a gRPC service
Stars: ✭ 21 (-19.23%)
Mutual labels:  pubsub
u-observers
Simple and powerful implementation of the observer pattern.
Stars: ✭ 31 (+19.23%)
Mutual labels:  pubsub
souls
SOULs 🔥 Build Serverless Apps faster like Rails. Powered by Ruby GraphQL, RBS/Steep, Active Record, RSpec, RuboCop, and Google Cloud.
Stars: ✭ 327 (+1157.69%)
Mutual labels:  pubsub
kane
Google Pub/Sub client for Elixir
Stars: ✭ 92 (+253.85%)
Mutual labels:  pubsub
WebApiWithBackgroundWorker
Small demo showing how to implement Pub/Sub with a BackgroundWorker in .NET Core
Stars: ✭ 55 (+111.54%)
Mutual labels:  pubsub
phoenix-postgresql-notify-listen-example
Publish/subscribe with PostgreSQL and Phoenix Framework
Stars: ✭ 16 (-38.46%)
Mutual labels:  pubsub
shimmer animation
This shimmer animation widget can help you bring simple yet beautiful skeleton loaders to your flutter app with ease.
Stars: ✭ 29 (+11.54%)
Mutual labels:  pubsub
simple redis
Simple and resilient redis client for rust.
Stars: ✭ 21 (-19.23%)
Mutual labels:  pubsub
azure-iothub-pubsub-esp8266
Using Arduino PubSub library with Azure IoT Hub on an ESP8266
Stars: ✭ 17 (-34.62%)
Mutual labels:  pubsub
Pubbie
A high performance pubsub client/server implementation for .NET Core
Stars: ✭ 122 (+369.23%)
Mutual labels:  pubsub
metamorphosis
Easy and flexible Kafka Library for Laravel and PHP 7
Stars: ✭ 39 (+50%)
Mutual labels:  pubsub
hanbo-db
hanboDB is a high available,low latency memory database system
Stars: ✭ 29 (+11.54%)
Mutual labels:  pubsub
iris3
An upgraded and improved version of the Iris automatic GCP-labeling project
Stars: ✭ 38 (+46.15%)
Mutual labels:  pubsub
rclex
Rclex: ROS 2 Client Library for Elixir
Stars: ✭ 77 (+196.15%)
Mutual labels:  pubsub
emulator-tools
Google Cloud BigTable and PubSub emulator tools to make development a breeze
Stars: ✭ 16 (-38.46%)
Mutual labels:  pubsub
monolog-google-cloud-json-formatter
A Monolog extension for formatting log entries for Google Cloud Logging
Stars: ✭ 15 (-42.31%)
Mutual labels:  superbalist
terraform-splunk-log-export
Deploy Google Cloud log export to Splunk using Terraform
Stars: ✭ 26 (+0%)
Mutual labels:  pubsub
watermill-amqp
AMQP Pub/Sub for the Watermill project.
Stars: ✭ 27 (+3.85%)
Mutual labels:  pubsub

php-pubsub-kafka

A Kafka adapter for the php-pubsub package.

Author Build Status StyleCI Software License Packagist Version Total Downloads

Installation

  1. Install librdkafka c library

    $ cd /tmp
    $ mkdir librdkafka
    $ cd librdkafka
    $ git clone https://github.com/edenhill/librdkafka.git .
    $ ./configure
    $ make
    $ make install
  2. Install the php-rdkafka PECL extension

    $ pecl install rdkafka
  3. Add the following to your php.ini file to enable the php-rdkafka extension extension=rdkafka.so

  4. composer require superbalist/php-pubsub-kafka

Usage

// create consumer
$topicConf = new \RdKafka\TopicConf();
$topicConf->set('auto.offset.reset', 'largest');

$conf = new \RdKafka\Conf();
$conf->set('group.id', 'php-pubsub');
$conf->set('metadata.broker.list', '127.0.0.1');
$conf->set('enable.auto.commit', 'false');
$conf->set('offset.store.method', 'broker');
$conf->set('socket.blocking.max.ms', 50);
$conf->setDefaultTopicConf($topicConf);

$consumer = new \RdKafka\KafkaConsumer($conf);

// create producer
$conf = new \RdKafka\Conf();
$conf->set('socket.blocking.max.ms', 50);
$conf->set('queue.buffering.max.ms', 20);

$producer = new \RdKafka\Producer($conf);
$producer->addBrokers('127.0.0.1');

$adapter = new \Superbalist\PubSub\Kafka\KafkaPubSubAdapter($producer, $consumer);

// consume messages
// note: this is a blocking call
$adapter->subscribe('my_channel', function ($message) {
    var_dump($message);
});

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', ['hello' => 'world']);
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);

// publish multiple messages
$messages = [
    ['hello' => 'world'],
    'lorem ipsum',
];
$adapter->publishBatch('my_channel', $messages);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts.

Run make up.

You will start at a bash prompt in the /opt/php-pubsub directory.

If you need another shell to publish a message to a blocking consumer, you can run make shell

To run the examples:

$ php examples/KafkaConsumerExample.php
$ php examples/KafkaPublishExample.php (in a separate shell)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].