项目作者: leocavalcante

项目描述 :
🎸 Just some fun with Kafka, PHP and Swoole
高级语言: PHP
项目地址: git://github.com/leocavalcante/kafka-phplayground.git
创建时间: 2020-10-17T15:44:17Z
项目社区:https://github.com/leocavalcante/kafka-phplayground

开源协议:MIT License

下载


Kafka PHPlayground

🎸 Just some fun with Kafka, PHP and Swoole.

Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.

Swoole is a Coroutine based Async PHP Programming Framework to Build high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket services with PHP and fluent Coroutine API.

Requirements

Instructions

Kafka

Start the services

  • kafka/bin/zookeeper-server-start.sh kafka/config/zookeeper.properties
  • kafka/bin/kafka-server-start.sh kafka/config/server.properties

Create a topic

  • kafka/bin/kafka-topics.sh --create --topic my-topic --bootstrap-server localhost:9092
    • Created topic my-topic. should be the response

PHP

If you don’t have Swoole already:

  • pecl install swoole

Install dependencies

Mainly https://github.com/easy-swoole/kafka

  • composer install

Start the consumer

  • php consumer.php

Let’s play!

Write some events

  • kafka/bin/kafka-console-producer.sh --topic my-topic --bootstrap-server localhost:9092

Then just type some messages to the stdin. Press Ctrl+C to stop.

Screenshot 01

A PHP producer

Just checkout producer.php.

Screenshot 02

Let’s Rock

Easy

Screenshot 03

Screenshot 04

Medium

Screenshot 05

Hard

Screenshot 06

⚠ Actually, I’m not sure if this is rocking. If you have a proper way to benchmark a consumer, please issue me.