swoole-src
swoole-src copied to clipboard
Keep kafka connection open while running httpserver and push messages from onRequest
I'm trying to implement kafka with rdkafka which i have working but with a major flaw. The connection while producing a message takes 1 second to close (https://github.com/arnaud-lb/php-rdkafka/issues/145).
I think the best option is to start a parallel process which keeps the kafka connection open so I can push messages from my controllers to kafka without creating/closing the kafka connection.
I've played with the Process, Pool and onWorkerStart httpserver listener but i'm not happy yet what I came up with.
If anyone can give me some pointers of the best setup for this specific scenario that would be great!
When I'm happy with my app I will publish my findings within a docker-compose file.
have you try AsyncTask ?
Well I tried using the go() function to async handle the dispatching of the event but my workers than have a 1 second timeout. I'm currently trying to create a process which keeps the connection open and dispatch events to that process like https://github.com/kcloze/swoole-jobs
Still have a feeling that It can be done more easily. Thought maybe about spawning a process with swoole timer with queue enabled (or pipe) for a fixed amount of time to minimize the change of timeout / errors without having to monitor the process.
Still would love for someone to point out the correct way to keep the connection open so I can push messages to a child process.
@rogierverbrugge see https://github.com/weiboad/kafka-php/issues/260#issuecomment-485226757