mirror of
https://gitee.com/quecpython/helios-service.git
synced 2025-05-19 06:08:22 +08:00
33 lines
934 B
Python
33 lines
934 B
Python
from usr.bin.guard import GuardContext
|
|
|
|
# 刷新容器
|
|
guard_context = GuardContext()
|
|
guard_context.refresh()
|
|
|
|
|
|
def func(*args, **kwargs):
|
|
"""
|
|
|
|
:param args: ('anonymous',) 发送人, 默认是'anonymous'无需关心
|
|
:param kwargs: 格式如下
|
|
{
|
|
'message':{
|
|
'message_id':2, # 消息ID
|
|
'sender':'anonymous', # 发送人
|
|
'message':'xxx', # 来的消息,
|
|
'from_event':'EXCEPTION', # 从那个事件或服务来的
|
|
'msg_type':255 # 消息类型, 默认是255
|
|
}
|
|
}
|
|
:return:
|
|
"""
|
|
print("func + {}".format(kwargs['message']['message']))
|
|
|
|
|
|
# 获取服务
|
|
exception_ser = guard_context.get_server("exception")
|
|
# 订阅服务
|
|
exception_ser.subscribe(func)
|
|
# publish消息
|
|
exception_ser.publish("this is a exception topic")
|