michaeldouglas/debeziumstream

一个用于数据库流处理的与debezium和Apache Kafka一起工作的客户端库。

0.06 2018-09-27 04:32 UTC

This package is not auto-updated.

Last update: 2024-09-20 09:43:44 UTC


README

要求

  1. Guzzle HTTP
  2. Laravel 5.2+

安装库

在项目文件夹中运行

$ composer require michaeldouglas/debeziumstream

配置Apache KAFKA和DEBEZIUM

将以下配置插入到.env文件中,例如:

KAFKA_HOST=18.231.179.169
KAFKA_PORT=9092
KAFKA_CONNECT_HOST=18.231.179.169:8083"
KAFKA_CONSUMER_BINARY="kafka-console-consumer"
KAFKA_CONSUMER_BINARY_PATH=/usr/local/etc/confluent/bin
 
DEBEZIUM_DB_CONNECTOR=mysql
DEBEZIUM_DB_CONNECTOR_NAME=otrs3-connector
DEBEZIUM_DB_HOST=127.0.0.1
DEBEZIUM_DB_DATABASE=otrs5
DEBEZIUM_DB_SERVER_ID=1
DEBEZIUM_DB_SERVER_NAME=localdb
DEBEZIUM_DB_USER=root
DEBEZIUM_DB_PASSWORD=

配置服务提供者

在config\app.php文件中的providers部分添加以下代码:

 MichaelDouglas\DebeziumStream\Providers\DebeziumKafkaServiceProvider::class

发布配置文件

$ php artisan vendor:publish

配置接收KAFKA事件的类

在config\kafka.php文件中

 /*
    |--------------------------------------------------------------------------
    | Handle Class
    |--------------------------------------------------------------------------
    | The class who will receive Kafka Topic Messages
    */
    'handler_class' => 'your class here',
 
    /*
    |--------------------------------------------------------------------------
    | Handle Methods
    |--------------------------------------------------------------------------
    | The class methods who will receiver Kafka Events
    */
    'event_methods' => [
       'create' => 'your method here',
       'update' => 'your method here',
       'delete' => 'your method here'
    ]

参数如下示例所示:

class TestService
{


    public function create($after, $topic)
    {

    }


    public function update($before, $after, $topic)
    {

    }



    public function delete($before, $topic)
    {

    }


}

初始化Kafka消费者工作

$ php artisan kafka:listen --topic=topic_name

laravel-debeziumstream