티스토리 뷰

라라벨에서 카프카 사용하기

laravel 에서 php8.1 이상일 경우 kafka 를 이용할 수 있다. 최근에 업데이트 된 2.x 버전부턴 8.2이상 지원된다.

https://junges.dev/documentation/laravel-kafka/v2.0/1-introduction

 

Mateus Junges's blog on PHP and Laravel

Mateus JUnges is a Laravel developer at Interaction Design Foundation.

junges.dev

설치하기

 

- librdkafka-dev 설치하기.

apt-get update && apt-get install -y librdkafka-dev

 

- rdkafka 설치

pecl install rdkafka

# auto yes
echo '' | pecl install rdkafka

 

- php.ini

$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php/8.2/cli
Loaded Configuration File => /etc/php/8.2/cli/php.ini

# php.ini
$ echo extension=rdkafka.so >> /etc/php/8.2/cli/php.ini

# php-fpm.ini
$ echo "extension=rdkafka.so" > /etc/php/8.2/fpm/conf.d/rdkafka.ini

$ php -m | grep rdkafka
rdkafka

 

- php-fpm 재시작, docker 환경이거나 php-fpm 미사용 시 생략

service php8.2-fpm restart

-  laravel-kafka 설치하기 
$ composer require mateusjunges/laravel-kafka

#확인하기
$ composer show mateusjunges/laravel-kafka
name     : mateusjunges/laravel-kafka
descrip. : A kafka driver for laravel
keywords : 
versions : * v1.13.10
released : 2024-02-14, 7 months ago
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : 
path     : /www/vendor/mateusjunges/laravel-kafka
names    : mateusjunges/laravel-kafka

 

댓글