Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the role of the Apache Kafka expansion pack in Laravel

Shulou Source: shulou.com Published: 2022-06-03 10:16:47 09月10日 Update

This article is to share with you about the role of the Apache Kafka expansion pack in Laravel, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article, without saying much, follow the editor to have a look.

The Laravel Kafka expansion Pack (https://github.com/mateusjunges/laravel-kafka) makes it easy for you to use Apache Kafka producers and consumers in Laravel applications. Using the publishOn method, you can configure and publish messages smoothly:

Use Junges\ Kafka\ Facades\ Kafka;Kafka::publishOn ('broker',' topic')-> withConfigOption ('property-name',' property-value')-> withConfigOptions (['property-name' = >' property-value'])

The following shows how to send a message to Kafka in the Laravel application through this package:

Use Junges\ Kafka\ Facades\ Kafka;/** @ var\ Junges\ Kafka\ Producers\ ProducerBuilder $producer * / $producer = Kafka::publishOn ('broker',' topic')-> withConfigOptions (['key' = >' value'])-> withKafkaKey ('your-kafka-key')-> withKafkaKey (' kafka-key')-> withHeaders (['header-key' = >' header-value']); $producer- > send ()

Here is an example of a consumer subscription message:

Use Junges\ Kafka\ Facades\ Kafka;$consumer = Kafka::createConsumer ('broker')-> subscribe (' topic'); / / processed by callback function: $consumer- > withHandler (function (\ RdKafka\ Message $message) {/ / message handling}); / / Invokable handler:class Handler {public function _ invoke (\ RdKafka\ Message $message) {/ / message handling} $consumer- > withHandler (Handler::class)

For other features of this package, please see readme: (https://github.com/mateusjunges/laravel-kafka/blob/master/README.md)

Configuration of maximum message consumption quantity

Dead letter queue-Wikipedia configuration

Middleware configuration

Use the Kafka::fake () method to simulate the Kafka producer in the test

Turn on debugging in development mode

The message body is configurable

This package requires the rdkafka extension to provide an efficient PHP client at the Kafka generation level. There are detailed installation instructions and source code for the package on Github.

The above is the role of the Apache Kafka expansion pack in Laravel, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Message configuration processing consumption function method more consumer producer knowledge article application production utility maximum fluency middleware function function customer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Linux Apple OPPO Reno