请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Thrifty: Thrifty 是基于.net Attribute 实现了标准 Thrift 协议的 RPC 框架。Thrifty ...

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

开源软件名称:

Thrifty

开源软件地址:

https://gitee.com/endink/Thrifty

开源软件介绍:

Thrifty Project

Thrifty.Net is a port of Swift(from facebook) for .Net , an attribute-based library for creating Thrift serializable types and services.

you can write C# attributed object instead of IDL file and IDL generation cli.

Thrifty = Thrift + Netty

Hex.pmGithub All ReleasesNuGetcoverage

OSTesting
Linuxtest ok test ok
Windowstest ok test ok

Thrifty Benchmark

end to end connection without connection pool

BenchmarkDotNet=v0.10.8, OS=Windows 10 Redstone 1 (10.0.14393)Processor=Intel Core i5-6300HQ CPU 2.30GHz (Skylake), ProcessorCount=4Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSCdotnet cli version=1.0.4  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
MethodMeanErrorStdDev
'LogCase.Log (Direct)'1.054 ms0.0090 ms0.0084 ms
'LogCase.GetMessages (Direct)'1.047 ms0.0109 ms0.0091 ms

locating services use Eureka,without connection pool

BenchmarkDotNet=v0.10.8, OS=Windows 10 Redstone 1 (10.0.14393)Processor=Intel Core i5-6300HQ CPU 2.30GHz (Skylake), ProcessorCount=4Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSCdotnet cli version=1.0.4  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
MethodMeanErrorStdDev
'LogCase.Log (Eureka)'1.104 ms0.0210 ms0.0207 ms
'LogCase.GetMessages (Eureka)'1.108 ms0.0182 ms0.0161 ms

locating services use Eureka,with connection pool

BenchmarkDotNet=v0.10.8, OS=Windows 10 Redstone 1 (10.0.14393)Processor=Intel Core i5-6300HQ CPU 2.30GHz (Skylake), ProcessorCount=4Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSCdotnet cli version=1.0.4  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
MethodMeanErrorStdDevMedian
'LogCase.GetMessages (Eureka&Pool)'302.1 us6.023 us14.55 us298.5 us
'LogCase.Log (Eureka&Pool)'294.9 us6.789 us19.70 us289.2 us

Serialization

Thrifty Codec convert POCO to and from Thrift.Thrifty support property、method、construction attributed. for example:

    [ThriftStruct]    public class LogEntry    {        [ThriftConstructor]        public LogEntry([ThriftField(1)]String category, [ThriftField(2)]String message)        {            this.Category = category;            this.Message = message;        }        [ThriftField(1)]        public String Category { get; }        [ThriftField(2)]        public String Message { get; }    }

Service

Thrifty Service attribute services to be exported with Thrift. For example:

    [ThriftService("scribe")]    public interface IScribe    {        [ThriftMethod("getMessages")]        List<LogEntry> GetMessages();        [ThriftMethod]        ResultCode Log(List<LogEntry> messages);    }    public class Scribe : IScribe    {        public List<LogEntry> GetMessages()        {            return new List<LogEntry>            {                new LogEntry { Category = "c1", Message = Guid.NewGuid().ToString() },                new LogEntry { Category = "c2", Message = Guid.NewGuid().ToString() },                new LogEntry { Category = "c3", Message = Guid.NewGuid().ToString() }            };        }        public ResultCode Log(List<LogEntry> messages)        {            return ResultCode.TRY_LATER;        }    }

Start Server

 var factory = new LoggerFactory();            factory.AddConsole(LogLevel.Debug);            var serverConfig = new ThriftyServerOptions            {                QueueTimeout = TimeSpan.FromMinutes(1),                TaskExpirationTimeout = TimeSpan.FromMinutes(1),                ConnectionLimit = 10000            };            var bootStrap = new ThriftyBootstrap(new object[] { new Scribe() },                serverConfig, new InstanceDescription("Sample", "EurekaInstance1", "127.0.0.1"), factory);            bootStrap                .SslConfig(new SslConfig                {                    CertFile = "server.pfx",                    CertPassword = "abc@123",                    CertFileProvider = new EmbeddedFileProvider(typeof(Program).GetTypeInfo().Assembly)                })               .AddService(typeof(IScribe), version: "1.0.0")               //true to register into eureka , disable eureka , set to false               .EurekaConfig(true,                              new EurekaClientConfig { EurekaServerServiceUrls = "http://192.168.0.10:8761/eureka" })               // bind any               .Bind(IPAddress.Any.ToString(), 3366)               .StartAsync();

Use Client

var factory = new LoggerFactory();using (var client = new ThriftyClient(new ThriftyClientOptions{    LoggerFactory = factory,    ConnectionPoolEnabled = true, // default is true    EurekaEnabled = true, //default is true    Eureka = new ThriftyClientEurekaConfig { EurekaServerServiceUrls = "http://192.168.0.10:8761/eureka" } //optional})){    /** *************if without eureka:*****************     *         var service = client.Create<Thrifty.IScribe>("127.0.0.1:3366",        new ClientSslConfig        {            CertFile = "ca.crt",            FileProvider = new EmbeddedFileProvider(typeof(ClientProgram).GetTypeInfo().Assembly)        });     */    var service = client.Create<Thrifty.IScribe>("1.0.0", "EurekaInstance1",        new ClientSslConfig        {            CertFile = "ca.crt",            FileProvider = new EmbeddedFileProvider(typeof(ClientProgram).GetTypeInfo().Assembly)        });    var logs = service.GetMessages();    ...}

Documents

document is here (Only Chinese documents are available now).

Dependecy (our another project)

Chopin

Chopin is a port of Apache Commons Object Pooling Library for .Net, to implement thrifty client connection pool.


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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