kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

Help: Could not find multiple consumers example

Open shenzhun opened this issue 10 years ago • 2 comments

Hi there,

When I use the kafka-python 1.0.0, old multiple consumer will be deprecated. I am not very familar with new API, I tried to find how to use mutiple consmuers in the docs, but found not result. Could you please give some examples ? Many thanks.

shenzhun avatar Feb 22 '16 12:02 shenzhun

I have also been trying to figure out how multiple consumers are expected to be used.

With 0.9.5, you could use the MultiProcessConsumer, which worked fairly well. Understandably, this is deprecated in 1.0.0.

Is it expected that users will do something like this?:

  • Use Python's multiprocessing and spin up a consumer in each process, then send the results to a Python Queue for processing

If I had some guidance about what was expected, I could craft some examples for documentation.

movermeyer avatar Feb 22 '16 18:02 movermeyer

You are free to use any concurrency model you wish. It really will depend on what you are trying to scale. multiprocessing is reasonable if you need more CPU but plan to stick on a single node. threading is probably not ever useful b/c KafkaConsumer multiplexes I/O internally.

In any event, multiple KafkaConsumer instances generally do not need to coordinate other than via the Kafka server APIs. the online documentation we've got right now is at http://kafka-python.readthedocs.org/en/1.0.0/usage.html :

# Use multiple consumers in parallel w/ 0.9 kafka brokers
# typically you would run each on a different server / process / CPU
consumer1 = KafkaConsumer('my-topic',
                          group_id='my-group',
                          bootstrap_servers='my.server.com')
consumer2 = KafkaConsumer('my-topic',
                          group_id='my-group',
                          bootstrap_servers='my.server.com')

dpkp avatar Feb 22 '16 20:02 dpkp