This commit is contained in:
yumoqing 2026-03-02 20:16:47 +08:00
parent 2cc7746abc
commit 06c2299778

View File

@ -42,19 +42,18 @@ async def run_proxy():
debug('run_proxy stopped...........') debug('run_proxy stopped...........')
async def zmq_subcribe(special_key: str, callback=None): async def zmq_subcribe(special_key: str, callback=None):
config = getConfig()
subscribe_url = config.subscribe_url or 'tcp://127.0.0.1:5556'
ctx = Context()
sock = ctx.socket(zmq.SUB)
sock.connect(subscribe_url)
# 设置过滤:只接收以 special_key 开头的消息
sock.setsockopt_string(zmq.SUBSCRIBE, special_key)
debug(f"【服务端】启动,仅等待 Key 为 '{special_key}' 的消息...")
content = '' content = ''
try: try:
config = getConfig()
subscribe_url = config.subscribe_url or 'tcp://127.0.0.1:5556'
ctx = Context()
sock = ctx.socket(zmq.SUB)
sock.connect(subscribe_url)
# 设置过滤:只接收以 special_key 开头的消息
sock.setsockopt_string(zmq.SUBSCRIBE, special_key)
debug(f"【服务端】启动,仅等待 Key 为 '{special_key}' 的消息...")
while True: while True:
# 接收消息multipart 格式,第一部分是 key第二部分是内容 # 接收消息multipart 格式,第一部分是 key第二部分是内容
if callback: if callback:
@ -75,6 +74,8 @@ async def zmq_subcribe(special_key: str, callback=None):
except asyncio.CancelledError: except asyncio.CancelledError:
exception(f'Cancelled .......') exception(f'Cancelled .......')
pass pass
except Exception as e:
exception(f'{e}\n{format_exc()}'
finally: finally:
sock.close() sock.close()
ctx.term() ctx.term()