-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
The following is my test code:
from celery import Celery
from kafka import KafkaProducer
app = Celery('test', broker='redis://127.0.0.1:6379/0')
producer = KafkaProducer(bootstrap_servers=['172.16.24.45:9092', '172.16.24.44:9092'])
@app.task
def send_msg():
# producer = KafkaProducer(bootstrap_servers=['172.16.24.45:9092', '172.16.24.44:9092'])
for i in range(10):
producer.send('test', b'this is the %dth test message' % i)
producer.flush()
if __name__ == '__main__':
app.start()
I use the following command to start worker:
celery -A app worker -l debug
then I enter python command line to send task:
from app import *
send_msg.delay()
If I use global producer variable, when I call send_msg.delay(), celery worker will hang and wait for producer flush, it will never end. But If I use local producer variable which is commented in above code, celery worker will work well.
I want to use global producer because It will work more efficient than local and not frequently create and close connections with kafka brokers. But how can I fix this problem?
Please help me and thanks.
glazari, syenchuk, Josh-IE and sikz1127
Metadata
Metadata
Assignees
Labels
No labels