私信发送成功
Watch Star Fork

endink / ThriftyC#Apache-2.0

Thrifty 是基于.net Attribute 实现了标准 Thrift 协议的 RPC 框架。Thrifty = Thrift + Netty。支持标准的 Thrift 数据类型,提供了 Thrift 到 C# 映射,除了标准映射外提供了额外的可用 C# 类型, 内置 Eureka 服务发现和注册、客户端连接池、连接数限制、SSL 支持等,.net 版本类 Dubbo 的 RPC 框架 https://github.com/endink/Thrifty
克隆/下载
AndersXiao 最后提交于 2017-12-05 13:14 change package description
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
2017-12-01 18:03
2017-12-01 17:49
2017-12-01 18:03
Loading...
README.md 6.93 KB

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.pm Github All Releases NuGet coverage

OS Testing
Linux test ok test ok
Windows test 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=4
Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSC
dotnet cli version=1.0.4
  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]
  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
Method Mean Error StdDev
'LogCase.Log (Direct)' 1.054 ms 0.0090 ms 0.0084 ms
'LogCase.GetMessages (Direct)' 1.047 ms 0.0109 ms 0.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=4
Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSC
dotnet cli version=1.0.4
  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]
  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
Method Mean Error StdDev
'LogCase.Log (Eureka)' 1.104 ms 0.0210 ms 0.0207 ms
'LogCase.GetMessages (Eureka)' 1.108 ms 0.0182 ms 0.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=4
Frequency=2250001 Hz, Resolution=444.4442 ns, Timer=TSC
dotnet cli version=1.0.4
  [Host]     : .NET Core 4.6.25211.01, 64bit RyuJIT [AttachedDebugger]
  DefaultJob : .NET Core 4.6.25211.01, 64bit RyuJIT
Method Mean Error StdDev Median
'LogCase.GetMessages (Eureka&Pool)' 302.1 us 6.023 us 14.55 us 298.5 us
'LogCase.Log (Eureka&Pool)' 294.9 us 6.789 us 19.70 us 289.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.

项目点评 ( 4 )

你可以在登录后,对此项目发表评论

4_float_left_people 4_float_left_close