c#---Socean.Rpc之EasyProxy
2021-03-20 14:26
标签:简介 mic oid bind 使用 res return ipa json 目录 1.高性能RPC框架:Socean.RPC 2.Socean.RPC框架实测 简介 EasyProxy是Socean.RPC的一个动态代理实现,特点是性能高、稳定性好、使用简便 使用入门: 服务端 : 1.定义序列化器和消息处理器 2.定义服务 3.启动服务 客户端: 1.定义序列化器 2.定义服务接口 3.生成代理服务 4.执行函数 其他 简单测试了一下IBookService.AddStock方法,在我的破旧笔记本上测试,并发量大约5w/秒(压测时请注释掉AddStock内部的Console.WriteLine函数,因为此函数并发不高,会影响测试结果) 项目地址 c#---Socean.Rpc之EasyProxy 标签:简介 mic oid bind 使用 res return ipa json 原文地址:https://www.cnblogs.com/ch00486259/p/12294567.htmlpublic class RpcSerializer : Socean.Rpc.DynamicProxy.IRpcSerializer
{
public object Deserialize(string content, Type type)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject(content, type);
}
public string Serialize(object obj)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
}
}
public class CustomMessageProcessor : Socean.Rpc.DynamicProxy.EasyProxyMessageProcessor
{
public override void Init()
{
RegisterServices(Assembly.GetExecutingAssembly(), new RpcSerializer());
}
}
public class Book
{
public string Name { get; set; }
public double Price { get; set; }
}
[RpcService]
public class BookService
{
public bool RegisterForSale(Book book)
{
Console.WriteLine("RegisterForSale,bookName:{0},bookPrice:{1}", book.Name, book.Price);
return true;
}
public void AddStock(string bookName, int count)
{
Console.WriteLine("AddStock,bookName:{0},count:{1}", bookName, count);
}
}
var server = new RpcServer();
server.Bind(IPAddress.Parse("127.0.0.1"), 11111);
server.Start
public class RpcSerializer : Socean.Rpc.DynamicProxy.IRpcSerializer
{
public object Deserialize(string content, Type type)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject(content, type);
}
public string Serialize(object obj)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
}
}
[RpcProxy(ServiceName = "BookService")]
public interface IBookService
{
bool RegisterForSale(Book book);
void AddStock(string bookName, int count);
}
public class Book
{
public string Name { get; set; }
public double Price { get; set; }
}
var bookServiceProxy = EasyProxyGenerator
bookServiceProxy.RegisterForSale(new Book { Name = "相对论", Price = 108.88 });
bookServiceProxy.AddStock("相对论", 1000);
项目地址:https://github.com/ch00486259/Socean.Rpc
文章标题:c#---Socean.Rpc之EasyProxy
文章链接:http://soscw.com/index.php/essay/66744.html