移除MQTT,更新launch文档,提供注册表示例文件,更新到0.10.5

This commit is contained in:
Xuwznln
2025-09-15 02:39:43 +08:00
parent 94cdcbf24e
commit 2ca0311de6
24 changed files with 1902 additions and 715 deletions

View File

@@ -3,7 +3,7 @@
"""
通信模块
提供MQTT和WebSocket的统一接口支持通过配置选择通信协议。
提供WebSocket的统一接口支持通过配置选择通信协议。
包含通信抽象层基类和通信客户端工厂。
"""
@@ -17,7 +17,7 @@ class BaseCommunicationClient(ABC):
"""
通信客户端抽象基类
定义了所有通信客户端(MQTT、WebSocket等需要实现的接口。
定义了所有通信客户端WebSocket等需要实现的接口。
"""
def __init__(self):
@@ -121,14 +121,12 @@ class CommunicationClientFactory:
protocol = protocol.lower()
if protocol == "mqtt":
return cls._create_mqtt_client()
elif protocol == "websocket":
if protocol == "websocket":
return cls._create_websocket_client()
else:
logger.error(f"[CommunicationFactory] Unsupported protocol: {protocol}")
logger.warning(f"[CommunicationFactory] Falling back to MQTT")
return cls._create_mqtt_client()
logger.warning(f"[CommunicationFactory] Falling back to WebSocket")
return cls._create_websocket_client()
@classmethod
def get_client(cls, protocol: Optional[str] = None) -> BaseCommunicationClient:
@@ -147,26 +145,16 @@ class CommunicationClientFactory:
return cls._client_cache
@classmethod
def _create_mqtt_client(cls) -> BaseCommunicationClient:
"""创建MQTT客户端"""
try:
from unilabos.app.mq import mqtt_client
return mqtt_client
except Exception as e:
logger.error(f"[CommunicationFactory] Failed to create MQTT client: {str(e)}")
raise
@classmethod
def _create_websocket_client(cls) -> BaseCommunicationClient:
"""创建WebSocket客户端"""
try:
from unilabos.app.ws_client import WebSocketClient
return WebSocketClient()
except Exception as e:
logger.error(f"[CommunicationFactory] Failed to create WebSocket client: {str(e)}")
logger.warning(f"[CommunicationFactory] Falling back to MQTT")
return cls._create_mqtt_client()
raise
@classmethod
def reset_client(cls):
@@ -188,7 +176,7 @@ class CommunicationClientFactory:
Returns:
支持的协议列表
"""
return ["mqtt", "websocket"]
return ["websocket"]
def get_communication_client(protocol: Optional[str] = None) -> BaseCommunicationClient: