mateusjunges / laravel-kafka

Use Kafka Producers and Consumers in your laravel app with ease!
https://laravelkafka.com/docs/v2.0/introduction
MIT License
581 stars 83 forks source link

[QUESTION] Undefined constant `Junges\Kafka\RD_KAFKA_PARTITION_UA` #39

Closed irfanpathanudr closed 2 years ago

mateusjunges commented 2 years ago

@irfanpathanudr this constant comes from librdkafka, not this package. You need to install this library in order to use laravel-kafka. This is the installation guide

irfanpathanudr commented 2 years ago

My PHP Version 8.0.12 Screenshot

run commond

composer require mateusjunges/laravel-kafka

but composer show error

run commond with

composer require mateusjunges/laravel-kafka --ignore-platform-reqs

no error come but kafka client throw error

Undefined constant "Junges\Kafka\RD_KAFKA_PARTITION_UA"

@mateusjunges Can you pl. help me to come out of this issue? It'll huge thanks for you :)

rtuin commented 2 years ago

@irfanpathanudr This phpinfo() shows the web configuration for PHP. Some installations have a different configuration on CLI. Does rdkafka show up when you run php -i on the terminal, and which version? You can also checked if the rdkafka extension is enabled in terminal at all by running php -m

irfanpathanudr commented 2 years ago

thank you @rtuin

Error :Call to undefined method RdKafka\ProducerTopic::producev()

Screenshot

php -i

Screenshot from 2021-12-10 10-40-19

can you pl. help me @rtuin @mateusjunges

maquib12 commented 2 years ago

Undefined constant "Junges\Kafka\RD_KAFKA_PARTITION_UA" can you plz help out form this issue

mateusjunges commented 2 years ago

@irfanpathanudr The Call to undefined method RdKafka\ProducerTopic::producev() issue occured because the librdkafka version is under 0.11.4, if you upgrade it should work.

irfanpathanudr commented 2 years ago

@mateusjunges my requirement is to setup Kafka client and my system configuration is Ubuntu 18.04 php 7.2, laravel/framework: "^6.2" for Admin, laravel/lumen-framework": "^7.0" for API, Rdkafka 5.0 , librdkafka 0.11.3.

ubuntu 18.4 have only supporte librdkafka 0.11.3 version mention in bellow image or link.

Screenshot (1)

https://repology.org/project/librdkafka/versions http://213.146.141.13/upstreamproject/details/librdkafka

so please help me out to communicate with kafka

mateusjunges commented 2 years ago

@irfanpathanudr It will not work on php 7.2, the minimun php version required is 8.0. About the librdkafka version, i can add a workaround to use the produce method instead, if the version is under 0.11.4, but it will not be able to add message headers.

rtuin commented 2 years ago

I suggest you do not run composer require with the --ignore-platform-reqs flag. The platform requirements defined in laravel-kafka's composer.json is meant to prevent the issues you are running into. This applies to most if not all packages.

mateusjunges commented 2 years ago

@irfanpathanudr i've added support for librdkafka v0.11.3, but as @rtuin mentioned, you should not run composer with --ignore-platform-reqs flag. You are only running into issues because of that, and i can't support you if your system does not follow the minimun requirements needed to use this package. I closed this with #43, but feel free to reopen or create another issue after you fix your system with the minimun requirements of this package.

janpadiz commented 2 years ago

EDIT: Fixed it by using php-fpm

local.ERROR: Undefined constant "Junges\Kafka\RD_KAFKA_PARTITION_UA" {"exception":"[object] (Error(code: 0): Undefined constant \"Junges\Kafka\RD_KAFKA_PARTITION_UA\" at /var/www/html/smartplement-asset/vendor/mateusjunges/laravel-kafka/src/AbstractMessage.php:9)

Hi, im getting the same error while on Ubuntu 18.4 using build 1.6.6

image image

EDIT: upgrade rdkafka to 6.0.1 still the same

image

upraded to ubuntu 20.4, still the same

EDIT: Fixed it by using php-fpm

theaungmyatmoe commented 9 months ago

This issue still persist when I try to use phpfranken and octane.

```bash
Undefined constant "Junges\Kafka\RD_KAFKA_PARTITION_UA" {"exception":"[object] (Error(code: 0): Undefined constant \"Junges\\Kafka\\RD_KAFKA_PARTITION_UA\" at /var/www/gateway/vendor/mateusjunges/laravel-kafka/src/AbstractMessage.php:11)
[stacktrace]
#0 /var/www/gateway/app/Actions/CreateWalletAction.php(21): Junges\\Kafka\\AbstractMessage->__construct(NULL, NULL, NULL, '{\"id\":\"264e48de...')
#1 /var/www/gateway/app/Http/Controllers/Api/V1/Auth/AuthController.php(51): App\\Actions\\CreateWalletAction->handle(Object(App\\Models\\User))
#2 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\Api\\V1\\Auth\\AuthController->register(Object(App\\Http\\Requests\\V1\\Auth\\RegisterRequest))
#3 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction('register', Array)
#4 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Api\\V1\\Auth\\AuthController), 'register')
#5 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController()
#6 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#7 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#8 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#9 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#10 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(159): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#11 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(125): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest(Object(Illuminate\\Http\\Request), Object(Closure), Array)
#12 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(87): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter(Object(Illuminate\\Http\\Request), Object(Closure), 'api', Object(Closure))
#13 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#14 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#15 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#16 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#17 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#18 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#19 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#20 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#21 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#31 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#32 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#37 /var/www/gateway/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#38 /var/www/gateway/vendor/laravel/octane/src/ApplicationGateway.php(36): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#39 /var/www/gateway/vendor/laravel/octane/src/Worker.php(84): Laravel\\Octane\\ApplicationGateway->handle(Object(Illuminate\\Http\\Request))
#40 /var/www/gateway/vendor/laravel/octane/bin/frankenphp-worker.php(53): Laravel\\Octane\\Worker->handle(Object(Illuminate\\Http\\Request), Object(Laravel\\Octane\\RequestContext))
#41 [internal function]: {closure}()
#42 /var/www/gateway/vendor/laravel/octane/bin/frankenphp-worker.php(74): frankenphp_handle_request(Object(Closure))
#43 /var/www/gateway/public/frankenphp-worker.php(3): require('/var/www/gatewa...')
#44 {main}
"}
Dinesh-loma commented 3 months ago

@mateusjunges Facing below issue while producing message Undefined constant "Junges\Kafka\RD_KAFKA_PARTITION_UA"

configuration.

rdkafka
rdkafka support => enabled
librdkafka version (runtime) => 1.8.0
librdkafka version (build) => 1.8.0.255

I am following v2 documentation from this website https://junges.dev/documentation/laravel-kafka/v2.0/1-introduction.

I am using php -8.3 laravel - 11, mateusjunges/laravel-kafka : "^2.1"

thejohn commented 2 months ago

You need to restart apache (If you are using Octane reload and update)