{"id":19804087,"url":"https://github.com/shoy160/spear","last_synced_at":"2025-08-31T11:39:27.212Z","repository":{"id":40849843,"uuid":"137171174","full_name":"shoy160/spear","owner":"shoy160","description":"Spear轻量级微服务框架，高扩展性，目前已支持TCP、HTTP、WebSocket以及GRPC协议，采用Consul/Nacos作为服务注册与发现组件，TCP协议采用DotNetty底层实现，HTTP协议采用ASP.NET CORE MVC实现。","archived":false,"fork":false,"pushed_at":"2023-03-04T10:50:59.000Z","size":18952,"stargazers_count":67,"open_issues_count":7,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T00:06:16.664Z","etag":null,"topics":["grpc","http","microservice","mvc","spear","tcp","websocket"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shoy160.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-13T06:19:53.000Z","updated_at":"2024-12-14T15:35:19.000Z","dependencies_parsed_at":"2024-06-19T00:16:04.139Z","dependency_job_id":null,"html_url":"https://github.com/shoy160/spear","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoy160%2Fspear","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoy160%2Fspear/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoy160%2Fspear/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoy160%2Fspear/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shoy160","download_url":"https://codeload.github.com/shoy160/spear/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143801,"owners_count":21054833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","http","microservice","mvc","spear","tcp","websocket"],"created_at":"2024-11-12T08:02:50.915Z","updated_at":"2025-04-10T02:27:07.862Z","avatar_url":"https://github.com/shoy160.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spear\nSpear轻量级微服务框架，高扩展性，目前已支持TCP、HTTP协议，采用Consul作为服务注册与发现组件，TCP协议采用DotNetty底层实现，HTTP协议采用ASP.NET CORE MVC实现。\n\n| Package Name |  NuGet | Downloads | |\n|--------------|  ------- |  ---- | -- |\n| Spear.ProxyGenerator | [![nuget](https://img.shields.io/nuget/v/Spear.ProxyGenerator.svg?style=flat-square)](https://www.nuget.org/packages/Spear.ProxyGenerator) | [![stats](https://img.shields.io/nuget/dt/Spear.ProxyGenerator.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.ProxyGenerator?groupby=Version) |\n| Spear.Core | [![nuget](https://img.shields.io/nuget/v/Spear.Core.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Core) | [![stats](https://img.shields.io/nuget/dt/Spear.Core.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Core?groupby=Version) | [Wiki](https://github.com/shoy160/spear/wiki) |\n| Spear.Codec.MessagePack | [![nuget](https://img.shields.io/nuget/v/Spear.Codec.MessagePack.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Codec.MessagePack) | [![stats](https://img.shields.io/nuget/dt/Spear.Codec.MessagePack.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Codec.MessagePack?groupby=Version) | \n| Spear.Codec.ProtoBuffer | [![nuget](https://img.shields.io/nuget/v/Spear.Codec.ProtoBuffer.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Codec.ProtoBuffer) | [![stats](https://img.shields.io/nuget/dt/Spear.Codec.ProtoBuffer.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Codec.ProtoBuffer?groupby=Version) | \n| Spear.Consul | [![nuget](https://img.shields.io/nuget/v/Spear.Consul.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Consul) | [![stats](https://img.shields.io/nuget/dt/Spear.Consul.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Consul?groupby=Version) |\n| Spear.Nacos | [![nuget](https://img.shields.io/nuget/v/Spear.Nacos.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Nacos) | [![stats](https://img.shields.io/nuget/dt/Spear.Nacos.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Nacos?groupby=Version) |\n| Spear.Protocol.Http | [![nuget](https://img.shields.io/nuget/v/Spear.Protocol.Http.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Protocol.Http) | [![stats](https://img.shields.io/nuget/dt/Spear.Protocol.Http.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Protocol.Http?groupby=Version) |\n| Spear.Protocol.Tcp | [![nuget](https://img.shields.io/nuget/v/Spear.Protocol.Tcp.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Protocol.Tcp) | [![stats](https://img.shields.io/nuget/dt/Spear.Protocol.Tcp.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Protocol.Tcp?groupby=Version) |\n| Spear.Protocol.WebSocket | [![nuget](https://img.shields.io/nuget/v/Spear.Protocol.WebSocket.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Protocol.WebSocket) | [![stats](https://img.shields.io/nuget/dt/Spear.Protocol.WebSocket.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Protocol.WebSocket?groupby=Version) |\n| Spear.Protocol.Grpc | [![nuget](https://img.shields.io/nuget/v/Spear.Protocol.Grpc.svg?style=flat-square)](https://www.nuget.org/packages/Spear.Protocol.Grpc) | [![stats](https://img.shields.io/nuget/dt/Spear.Protocol.Grpc.svg?style=flat-square)](https://www.nuget.org/stats/packages/Spear.Protocol.Grpc?groupby=Version) |\n\n### Contracts\n``` c#\n[ServiceRoute(\"test\")] //自定义路由键\npublic interface ITestContract : ISpearService\n{\n    Task Notice(string name);\n    Task\u003cstring\u003e Get(string name);\n}\n```\n### Server\n``` c#\nvar services = new MicroBuilder();\n//服务协议\nvar protocol = ServiceProtocol.Tcp;\nservices.AddMicroService(builder =\u003e\n{\n    //服务端需指定编解码器和使用协议\n    builder\n        .AddJsonCoder()             //Json编解码\n        //.AddMessagePackCodec()    //MessagePack\n        //.AddProtoBufCodec()       //ProtoBuf\n        .AddSession()\n        //.AddNacos()\n        .AddConsul(\"http://127.0.0.1:8500\"); //Consul服务注册与发现\n    switch (protocol)\n    {\n        case ServiceProtocol.Tcp:\n            builder.AddTcpProtocol();       //TCP\n            break;\n        case ServiceProtocol.Http:\n            builder.AddHttpProtocol();      //Http\n            break;\n        case ServiceProtocol.Ws:\n            builder.AddWebSocketProtocol(); //WebSocket\n            break;\n        case ServiceProtocol.Grpc:\n            builder.AddGrpcProtocol();      //GRpc\n            break;\n    }\n});\n\nservices.AddTransient\u003cITestContract, TestService\u003e();\n\nvar provider = services.BuildServiceProvider();\n\nprovider.UseMicroService(address =\u003e\n{\n    address.Service = \"192.168.1.xx\";   //服务注册地址,需要保持与客户端的网络访问\n    address.Host = \"localhost\";         //主机地址\n    address.Port = 5001;                //端口地址\n    address.Weight = 1.5;               //服务权重\n    address.Gzip = true;                //是否启用GZip压缩\n});\n```\n\n### Client\n``` c#\nvar services = new MicroBuilder()\n    .AddMicroClient(builder =\u003e\n    {\n        //支持多编解码\u0026多协议\n        builder\n            .AddJsonCodec()\n            .AddMessagePackCodec()\n            .AddProtoBufCodec()\n            .AddHttpProtocol()          //Http\n            .AddTcpProtocol()           //TCP\n            .AddWebSocketProtocol()     //WebSocket\n            .AddGrpcProtocol()          //GRpc\n            .AddSession()\n            //.AddNacos()\n            .AddConsul(\"http://127.0.0.1:8500\");\n    });\nvar provider = services.BuildServiceProvider();\nvar proxy = provider.GetService\u003cIProxyFactory\u003e();\nvar service = proxy.Create\u003cITestContract\u003e();\n```\n\n### BenchMark\n#### Protocol:Tcp,Codec:Json,Gzip:False\n![image](docs/images/benchmark-0-0-0.png)\n\n#### Protocol:Tcp,Codec:Json,Gzip:True\n![image](docs/images/benchmark-0-0-1.png)\n\n#### Protocol:Tcp,Codec:MessagePack,Gzip:True\n![image](docs/images/benchmark-0-1-1.png)\n\n#### Protocol:Tcp,Codec:ProtoBuf,Gzip:True\n![image](docs/images/benchmark-0-2-1.png)\n\n#### Protocol:Http,Codec:Json,Gzip:False\n![image](docs/images/benchmark-1-0-0.png)\n\n#### Protocol:Http,Codec:Json,Gzip:True\n![image](docs/images/benchmark-1-0-1.png)\n\n#### Protocol:Http,Codec:MessagePack,Gzip:True\n![image](docs/images/benchmark-1-1-1.png)\n\n#### Protocol:Http,Codec:ProtoBuf,Gzip:True\n![image](docs/images/benchmark-1-2-1.png)\n\n#### Protocol:WebSocket,Codec:Json,Gzip:False\n![image](docs/images/benchmark-2-0-0.png)\n\n#### Protocol:WebSocket,Codec:Json,Gzip:True\n![image](docs/images/benchmark-2-0-1.png)\n\n#### Protocol:WebSocket,Codec:MessagePack,Gzip:True\n![image](docs/images/benchmark-2-1-1.png)\n\n#### Protocol:WebSocket,Codec:ProtoBuf,Gzip:True\n![image](docs/images/benchmark-2-2-1.png)\n\n#### Protocol:GRpc\n![image](docs/images/benchmark-4-0-0.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoy160%2Fspear","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoy160%2Fspear","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoy160%2Fspear/lists"}