ConnectionMessage.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # # from hub import methods, Global
  2. #
  3. # import threading
  4. # import time
  5. # import json
  6. #
  7. # sys.path.append('/home/server/repositories/repositories/sri-project.demo-py/sri-server-bg03')
  8. # protobuf = importlib.import_module(f"protobuf.protocol_pb2")
  9. #
  10. #
  11. # class ConnectionMessage(object):
  12. # """消息处理"""
  13. #
  14. # fn_dict = {
  15. # protobuf.CS_Offer: ConnectionMessage.f1,
  16. # }
  17. #
  18. # @staticmethod
  19. # def f1(client, userdata, message):
  20. # pass
  21. #
  22. # @staticmethod
  23. # def decorate_method(client, userdata, message):
  24. # """消息处理方法"""
  25. # file_name = methods.now_string('%Y-%m-%d.log')
  26. # log_file_path = f"/home/server/logs/{file_name}"
  27. # log_dict = json.loads(message.payload)
  28. # # methods.debug_log(f"MessageListener.20", f"#log_dict: {log_dict}")
  29. #
  30. # log_list = list()
  31. # for i in range(1, 5):
  32. # v = str(log_dict.get(str(i)))
  33. # log_list.append(v)
  34. # methods.write_text(log_file_path, '|'.join(log_list) + '\n', 'a')
  35. # methods.debug_log(f"MessageListener.24", f"#message.payload: {json.loads(message.payload)}")
  36. #
  37. # @classmethod
  38. # def start_check_loop(cls):
  39. #
  40. # # --- check ---
  41. # save_dir = f"/home/server/logs"
  42. # if not methods.is_dir(save_dir):
  43. # out = methods.run_command(f'mkdir -p {save_dir}', callback=True)
  44. # methods.debug_log('MessageListener.33', f"#out: {out}")
  45. #
  46. # Global.emqx.start_subscribe_loop(
  47. # decorate_method=MessageListener.decorate_method,
  48. # subscribe_topic='bg/log'
  49. # )
  50. #
  51. # @classmethod
  52. # def run_background(cls, background_is=True):
  53. # """"""
  54. # p1 = threading.Thread(target=cls.start_check_loop)
  55. # p1.start()
  56. #
  57. #
  58. # if __name__ == '__main__':
  59. # MessageListener.run_background()