SOHU-Co / kafka-node

Node.js client for Apache Kafka 0.8 and later.
MIT License
2.66k stars 628 forks source link

How do you use the producer and consumer to expose as an API using node express? #1428

Open kprytsm opened 4 years ago

kprytsm commented 4 years ago

I am new to Kafka and recently I want to develop a producer and consumer API using node express framework.

While developing I encounter 2 issues:

  1. After I consume once with the consumer.js file, I cannot get any response if I try to call the consumer api again

producer.txt consumer.txt app.txt no_response

  1. What is the best way to control the consumer group (for this part I haven't implemented into the code yet). For example, if my topic has two partition, and I want two different API session to consume each of the partition, how should I set the consumer option properly in the Kafka-node consumer?

Appreciate if you can help me on these issues, sorry if it is being too simple.

kprytsm commented 4 years ago

I am suspecting "process.exit()" cause me the issue mentioned in point 1.....

I am using nodemon to run app.js btw.

kprytsm commented 4 years ago

after some trial and error, I use pm2 to host the app.js and I can now call the consumer api again and again, but anyone can explain why?