Shared XMPP connection between Celery workers

旧巷老猫 提交于 2019-12-05 04:22:47

You can create a connection globally in your celery task module and use it from your tasks to send messages. In that case the connection will be established at start-up and will be shared between worker processes.

import socket 
from celery.task import task

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.connect(('localhost', 9999)) 

@task
def echo(arg):
    s.send(arg) 
    return s.recv()

How about a long-running background job whose job it would be to receive messages from other short-lived processes and push them onto an XMPP socket?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!