swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

Keep kafka connection open while running httpserver and push messages from onRequest

Open vrgenl opened this issue 6 years ago • 3 comments

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.

vrgenl avatar Aug 10 '18 08:08 vrgenl

have you try AsyncTask ?

patrickkh7788 avatar Aug 16 '18 11:08 patrickkh7788

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.

vrgenl avatar Aug 21 '18 07:08 vrgenl

@rogierverbrugge see https://github.com/weiboad/kafka-php/issues/260#issuecomment-485226757

lragon avatar Apr 29 '19 09:04 lragon