30

基于 Pub/Sub 的同步 RRPC 调用实战

 5 years ago
source link: https://mp.weixin.qq.com/s/K-doO3-E8Rhdcq3athcj9A?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1.同步调用场景

1.1 背景

MQTT协议是基于PUB/SUB的异步通信模式,无法实现服务端下发指令给设备端,同时需要设备端返回响应结果的场景。

IoT物联网平台基于MQTT协议制定了一套请求和响应的同步机制,无需改动MQTT协议即可实现同步通信。应用服务器通过POP API发起RRPC调用,IoT设备端只需要在Timeout内,按照固定的格式回复Pub消息,服务端即可同步获取IoT设备端的响应结果。

具体流程如下:

V326R3b.jpg!web

1.2 Topic格式约定

RJRfAjm.jpg!web

2.同步调用RRPC示例

2.1 设备端代码

ZFB7ZfM.jpg!web

2.2 服务端POP调用Rrpc

BjyAjy3.jpg!web

rrpc响应:

yAf6nmu.png!web

3.物模型-服务同步调用

InvokeThingService示例

注意:物模型 服务调用 POP接口

是InvokeThingService,不是RRPC

nAveemF.jpg!web

3.1 物模型- 同步服务定义

jINVfa7.jpg!web

3.2 设备端实现

RNBnI33.jpg!web

注意:设备端响应的payload要满足物模型定义的出参结构

3.3 物模型-服务调用

POP接口 InvokeThingService

7jUjiaf.jpg!web

服务调用返回结果:

2u2ABzJ.png!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK