面向工业物联网的远程过程调用技术原理、框架及应用

 2022-08-06 10:08

论文总字数:31451字

摘 要

本文探讨了远程过程调用(RPC)技术的原理、实现,以及在物联网领域的应用,根据实际需求编写了完整可运行的项目并进行了测试,其结果被用于相应的分析。

远程过程调用技术在互联网时代尤为重要。其一般使用HTTP、Socket等底层协议作为通信基础,Protocol Buffers、XML、Json等协议作为序列化编码,配合大量运行逻辑,可实现不同操作系统、不同设备间应用程序的相互调用。

本文重点针对知名远程过程调用框架gRPC进行了包括原理、协议栈、源码等方面的研读,并使用此框架实现了一个可监控、管理工厂中零件从原料加工为成品过程中各阶段参数的系统,涉及包含数据库功能的Java服务端和录入、查询功能的Android客户端程序。经测试,系统运行稳定、响应迅速,可投入实际生产环境使用。

最后,根据上述研究与实践,远程过程调用技术在物联网领域有着高可用性和易用性,可以承担起端到端的承接、通信任务。

关键词:远程过程调用、Protobuf、gRPC、序列化编码、数据库

Abstract

This article discusses the principle, implementation, and application of Remote Procedure Call (RPC) technology in the field of Internet of Things. A complete and operable project has been written and tested according to actual needs. The results have been used for corresponding analysis.

Remote procedure call technology is particularly important in the Internet age. It generally uses the underlying protocol such as HTTP and Socket as the communication basis. Protocols such as Protocol Buffers, XML, and Json are used as serialization codes. In combination with a large amount of running logic, mutual calls between application programs of different operating systems and different devices can be realized.

This paper focuses on the knowledge of the well-known remote procedure call framework gRPC, including the principles, protocol stack, source code, etc., and uses this framework to achieve a system that can monitor and manage the parameters of the parts in the factory from the processing of raw materials into finished products. The project involves a Java client that contains the database function and an Android client program that inputs, inquires about the function. After testing, the system is stable and responsive, and can be put into use in the actual production environment.

Finally, based on the above research and practice, the remote procedure call technology has high availability and ease of use in the field of the Internet of Things, and can undertake end-to-end acceptance and communication tasks.

KEY WORDS: Remote Procedure Call, Protobuf, gRPC, serialization codes, database

目 录

1. 绪论 3

2. 理论研究 3

2.1. RPC技术 3

2.2. 序列化编码方案 4

2.3. gRPC框架研读 5

i. Protocol Buffers 3 5

ii. gRPC 7

3. 准备工作 12

3.1. 开发环境配置 13

3.2. 运行环境配置 13

3.3. 数据库 14

3.4. 动态页面加载 15

3.5. 蓝牙打印(TSC)协议 15

3.6. Proto编写 16

4. 服务端开发 16

4.1. 架构设计 16

4.2. 方案选择 17

4.3. 实现 18

5. Android客户端开发 20

5.1. 业务设计 20

5.2. 方案选择 20

5.3. 实现 22

6. 实测 23

7. 总结 24

7.1. 性能评估 24

7.2. 改进方向 24

7.3. 综述 25

8. 参考文献 25

9. 致 谢 25

绪论

如今互联网已经延伸到了世界的各个角落,但这并不意味着其广度已无处延伸。很显然,其还没有深入到生活当中,即物联网领域。现在很火的“智能设备”就是这方面的尝试。这种尝试比智能手机和PC晚的原因也是显而易见的:原先的网络环境、硬件性能并不能满足这类设备接入网络的需求,因为它们的工作环境并不如前者那般稳定,对成本的敏感度也更高。所以即便是现在,物联网设备依然较为羸弱,这就需要在应用中着重优化这方面,以避免成为瓶颈。

抛开物联网设备各自功能实现的部分,每个设备所共有的业务之一便是通信。一个完整的通信过程包括数据的编码、网络连接的建立、数据的传输和到端后数据的解码。通常,这些设备会在有线/无线网络上与远端服务器建立连接,然后通过远程调用(RPC)/Socket/HTTP等手段达到通信的目的。这里我们考虑实现相对成熟且功能完善的RPC作为考虑对象。

这一技术简单来说就是赋予了不同设备上应用之间的相互调用的能力,通信双方仅需要在网络上建立连接即可。这一技术的底层一般为Socket或基于Socket的协议,上层经过封装向外暴露接口方便开发者的使用。技术的重点在于如何跨设备、跨平台地传输调用过程中需要用到的参数。常见的RPC框架一般选用了XML、Json、Protobuf等编码方式传输这些数据,而这些协议的特点和优劣将是本文讨论的重点。同样的,基于这些编码方式构建的不同RPC框架也会被作为考察对象。

鉴于几乎所有物联网设备都无法绕开通信的环节,而RPC又是这个环节中非常常用的技术,这一技术的各项指标就显得尤为重要。通过对RPC技术全面的考察,选出(不同场景下)最适宜的框架可以大面积、大幅度地优化各物联网设备的运行性能或降低硬件需求从而缩减成本。

理论研究

RPC技术

RPC,即Remote Procedure Call,是一类计算机通信协议,该协议可以实现处在不同内存空间的程序的相互调用[1]。这里的不处于同一内存空间,即对程序的运行环境不做限制,可以是同一台计算机的不同进程,也可以是运行在不同计算机甚至不同操作系统的程序。

剩余内容已隐藏,请支付后下载全文,论文总字数:31451字

您需要先支付 80元 才能查看全部内容!立即支付

该课题毕业论文、开题报告、外文翻译、程序设计、图纸设计等资料可联系客服协助查找;