智能边缘平台 IEF-云端下发消息到边缘节点:接收消息

时间:2024-09-05 15:36:09

接收消息

  1. 登录边缘节点。
  2. 使用MQTT客户端接收消息。

    当前边缘节点MQTT支持两种模式。

    • 一种是内置的MQTT broker(使用8883端口),需要使用节点证书认证,然后订阅对应Topic接收消息,具体使用方式请参见使用证书进行安全认证
    • 另外一种是使用外置的MQTT broker(使用1883端口),需要先安装第三方MQTT broker,然后订阅对应Topic接收消息。

    这里介绍使用外置的MQTT broker的方式,外置的MQTT broker需要先安装MQTT broker,例如安装Mosquitto,步骤如下。

    • 对于Ubuntu操作系统,可以使用如下命令安装mosquitto:
      apt-get install mosquitto
      systemctl start mosquitto
      systemctl enable mosquitto
    • 对于CentOS操作系统,使用如下命令安装mosquitto:
      yum install epel-release
      yum install mosquitto
      systemctl start mosquitto
      systemctl enable mosquitto

    安装完成后,使用订阅命令订阅,订阅后如果有消息发送,就会收到消息,如下所示。其中#表示订阅任何主题,可以替换为指定的主题,如/aaa/bbb等。

    [root@ief-node ~]# mosquitto_sub -t '#' -d 
    Client mosq-m02iwjsp4j2ISMw6rw sending CONNECT 
    Client mosq-m02iwjsp4j2ISMw6rw received CONNACK (0)
    Client mosq-m02iwjsp4j2ISMw6rw sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0, Options: 0x00) 
    Client mosq-m02iwjsp4j2ISMw6rw received SUBACK 
    Subscribed (mid: 1): 0
    Client mosq-m02iwjsp4j2ISMw6rw received PUBLISH (d0, q0, rQ, mQ, '/aaa', ... (31 bytes))
    {
        "test-key": "test-value"
    }

support.huaweicloud.com/usermanual-ief/ief_01_0062.html