Giter Site home page Giter Site logo

laravel-kafka's Introduction

kafka

介绍

Kafka 分布式发布订阅消息系统扩展包。

环境

php >= 8.1
composer >= 2.0

扩展

RdKafka 自行安装php扩展

使用

1.安装

composer require buqiu/kafka

2.发布 kafka.php 配置文件

php artisan vendor:publish --tag=buqiu-kafka-config

3.修改 config/queue.php 文件,在 connections 数组中追加 kafka 配置信息

'kafka' => [
            'driver' => 'kafka',
            'queue' => env('KAFKA_TOPIC'),
        ],

4.配置 .env 文件

KAFKA_BROKERS=服务地址
KAFKA_SECURITY_PROTOCOL=SASL_SSL
KAFKA_SASL_MECHANISMS=PLAIN
KAFKA_SASL_USERNAME=用户名
KAFKA_SASL_PASSWORD=密码
KAFKA_DEBUG=false
KAFKA_TOPIC=自定义的 Topic
KAFKA_CONSUMER_GROUP_ID=自定义的 Group ID

5.启动 kafka 队列监听

php artisan queue:work kafka

6.代码示例

6.1 修改 .env 文件设置默认队列连接

.env

QUEUE_CONNECTION=kafka

php 代码中使用

KafkaJob::dispatch()->onQueue('default');

6.2 不修改 .env 默认队列连接,手动指定连接

方式一:调用处动态指定

KafkaJob::dispatch()->onQueue('default')->onConnection('kafka');

方式二、KafkaJob 中指定连接属性(推荐)

public function __construct()
{
    $this->onConnection('kafka');
}

laravel-kafka's People

Contributors

smallk1002 avatar buqiu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.