.NET 跨平台RPC框架DotNettyRPC
程序员文章站
2022-07-06 11:54:21
DotNettyRPC 1.简介 DotNettyRPC是一个基于DotNetty的跨平台RPC框架,支持.NET45以及.NET Standard2.0 2.产生背景 传统.NET开发中遇到远程调用服务时,多以WCF为主。而WCF虽然功能强大,但是其配置复杂,不易于上手。而且未来必定是.NET C ......
dotnettyrpc
1.简介
dotnettyrpc是一个基于dotnetty的跨平台rpc框架,支持.net45以及.net standard2.0
2.产生背景
传统.net开发中遇到远程调用服务时,多以wcf为主。而wcf虽然功能强大,但是其配置复杂,不易于上手。而且未来必定是.net core的天下,wcf暂不支持.net core(只有客户端,无法建立服务端)。市面上的其他.net的 rpc框架诸如grpc、surging甚至微服务框架orleans等,这些框架功能强大,性能也很好,并且比较成熟,但是使用起来不够简单。基于上述比较(无任何吹捧贬低的意思),鄙人不才撸了一个*dotnettyrpc,它的定位是一个跨平台(.net45和.net standard)、简单却实用的rpc框架
3.使用方法
3.1引入dotnettyrpc
打开nuget包管理器,搜索dotnettyrpc即可找到并使用
或输入nuget命令:install-package dotnettyrpc
3.2定义服务接口
public interface ihello { string sayhello(string msg); } public class hello : ihello { public string sayhello(string msg) { return msg; } }
3.3服务端
using coldairarrow.dotnettyrpc; using common; using system; namespace server { class program { static void main(string[] args) { rpcserver rpcserver = new rpcserver(9999); rpcserver.registerservice<ihello, hello>(); rpcserver.start(); console.readline(); } } }
3.4客户端
using coldairarrow.dotnettyrpc; using common; using system; namespace client { class program { static void main(string[] args) { ihello client = rpcclientfactory.getclient<ihello>("127.0.0.1", 9999); var msg = client.sayhello("hello"); console.writeline(msg); console.readline(); } } }
3.5运行
先运行服务端,再运行客户端,即可在客户端输出hello
4.结语
本机测试一次rpc请求平均0.4ms左右,性能不高,但是足以应对绝大多数业务场景,重在简单实用。可以优化的地方很多,还望大家多多支持。
github地址:https://github.com/coldairarrow/dotnettyrpc
qq群:373144077
上一篇: Python的描述符
推荐阅读
-
简单谈谈.NET Core跨平台开发
-
Net Core平台灵活简单的日志记录框架NLog+SqlServer初体验
-
.NET Core跨平台部署
-
分享一个C++与Python开发的中小型通用游戏服务端框架(跨平台,开源,适合MMORPG游戏)
-
物联网框架ServerSuperIO.Core(.netcore)跨平台,一套设备驱动通吃嵌入式、上位机、云服务
-
.NET Core跨平台部署于Docker(Centos)- 视频教程
-
.Net Core应用程序跨平台应用研究-HelloArm(串口篇)
-
Docker 部署net5程序实现跨平台功能
-
【.NET Core项目实战-统一认证平台】第十六章 网关篇-Ocelot集成RPC服务
-
.NET Core 跨平台 串口通讯 ,Windows/Linux 串口通讯,flyfire.CustomSerialPort 的使用