• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sharpsvr: 企业级的c# rpc框架. 支持最多千个客户端同时连接. 支持部分服务治理功能(d ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

sharpsvr

开源软件地址:

https://gitee.com/yautacai/sharpsvr

开源软件介绍:

sharpsvr

what is sharpsvr

sharpsvr 是一个企业级的dotnetcore rpc框架,最新版本基于dotnetcore 2.0开发, 支持符合dotnetcore 规范的所有平台.传统企业级服务通过只需引用sharpsvr库简单的改造即可变成分布式服务.sharpsvr是一个轻量级\性能优秀的框架.可以同时支持多达上千个客户端链接提供稳定的服务支持.sharpsvr计划陆续支持"远程调用""服务发现""服务版本""服务升级降级""服务路由""自动节点检查"等功能.

简单demo:

  • 服务接口定义: ICalc.cs
using System.Collections.Generic;using sharpsvr.attributes;namespace commontest.src.test{    [RemoteService]    public interface ICalc    {        [RemoteMethod]        void SayHello(string name="yangyang");        [RemoteMethod]        int TestA(short b);        [RemoteMethod]        int TestA(int c, long d);        [RemoteMethod]        double Add(int a, long b, float c=1.0f, double d = 2.0);        [RemoteMethod]        List<User> GetUserList(User user = null);        [RemoteMethod]        User GetUser(User a=null, User b=null);    }}
  • 服务实现
using System.Collections.Generic;namespace commontest.src.test{    public class Calc : ICalc    {        public double Add(int a, long b, float c = 1, double d = 2)        {            return a + b + c + d;        }        public User GetUser(User a = null, User b = null)        {            System.Console.WriteLine($"a={a}, b={b}");            throw new System.NotImplementedException();        }        public List<User> GetUserList(User user = null)        {            var result = new List<User>();            result.Add(user);            result.Add(new User{Id=1, Age=2, Sex=true, Message = "hello,hahah", Child=user});            return result;        }        public void SayHello(string name = "yangyang")        {            System.Console.WriteLine("hello:" + name);        }        public int TestA(short b)        {            return b++;        }        public int TestA(int c, long d)        {            return (int)(c * d);        }    }}
  • server端实现
using System;using System.Threading.Tasks;using commontest.src.test;using sharpsvr.net;namespace svrtest{    class Program    {        static void Main(string[] args)        {            var svr = new sharpsvr.net.SharpServer();            ICalc cal = new Calc();            Action<IServer> action = async (IServer server)=>{                svr.WithService(cal);                svr.StartUp();                await Task.Run(()=> server.MainLoop());            };            action(svr);            Console.ReadKey();            svr.ShutDown();        }    }}
  • 客户端调用
using System;using System.Threading.Tasks;using commontest.src.test;namespace clienttest{    class Program    {        static void RunAsync()        {            Action<Int32> action = async (Int32 number) =>            {                await Task.Run(() =>                {                    try                    {                        Console.WriteLine("thread start number:" + number + ", current thread:" + System.Threading.Thread.CurrentThread.GetHashCode());                        ICalc proxy = sharpsvr.proxy.ProxyGenerator.Of<ICalc>(new sharpsvr.proxy.SharpInterceptor());                        while (true)                        {                            try                            {                                Console.WriteLine("hello:" + proxy.TestA(1, 2L));                                var userList = proxy.GetUserList(new User { Id = 123 });                                foreach (var user in userList) Console.WriteLine("hello:" + user);                                Console.WriteLine("proxy.GetUser:" + proxy.GetUser(new User { Id = 1 }, new User { Age = 2 }));                            }                            catch (Exception ex)                            {                                Console.WriteLine("error exception:" + ex);                            }                        }                    }                    finally                    {                        Console.WriteLine("exception not catched!");                    }                });            };            for (int i = 0; i < 100; ++i)            {                action(i);            }        }        static void RunSync()        {            try            {                ICalc proxy = sharpsvr.proxy.ProxyGenerator.Of<ICalc>(new sharpsvr.proxy.SharpInterceptor());                while (true)                {                    try                    {                        Console.WriteLine("hello:" + proxy.TestA(1, 2L));                        var userList = proxy.GetUserList(new User { Id = 123 });                        foreach (var user in userList) Console.WriteLine("hello:" + user);                        Console.WriteLine("proxy.GetUser:" + proxy.GetUser(new User { Id = 1 }, new User { Age = 2 }));                    }                    catch (Exception ex)                    {                        Console.WriteLine("error exception:" + ex);                    }                }            }            finally            {                Console.WriteLine("exception not catched!");            }        }        static void Main(string[] args)        {            RunAsync();            Console.ReadKey();            //while(true) System.Threading.Thread.Sleep(100000);            Environment.Exit(0);        }    }}

v 0.1.0

以下是sharpsvr 0.1.0 支持的功能:

  • 分布式服务.
  • 服务名称发现\服务版本支持
  • 故障节点剔除\重连
  • 长链接\短链接
  • 通用的tcp\udp协议支持,自定义编码解码器支持

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap