Coder Social home page Coder Social logo

lwp001 / spear Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shoy160/spear

0.0 2.0 0.0 14.98 MB

Spear轻量级微服务框架,高扩展性,目前已支持TCP、HTTP协议,采用Consul作为服务注册与发现组件,TCP协议采用DotNetty底层实现,HTTP协议采用ASP.NET CORE MVC实现。

License: Apache License 2.0

C# 100.00%

spear's Introduction

spear

Spear轻量级微服务框架,高扩展性,目前已支持TCP、HTTP协议,采用Consul作为服务注册与发现组件,TCP协议采用DotNetty底层实现,HTTP协议采用ASP.NET CORE MVC实现。

Contracts

[ServiceRoute("test")] //自定义路由键
public interface ITestContract : ISpearService
{
    Task Notice(string name);
    Task<string> Get(string name);
}

Server

var services = new ServiceCollection();
//服务协议
var protocol = ServiceProtocol.Tcp;
services.AddMicroService(builder =>
{
    builder
        .AddJsonCoder() //json编解码
        .AddConsul("http://127.0.0.1:8500"); //Consul服务注册与发现
    switch (protocol)
    {
        case ServiceProtocol.Tcp:
            //TCP协议,基于DotNetty
            builder.AddTcpProtocol();
            break;
        case ServiceProtocol.Http:
            //HTTP协议基于aspnetcore MVC
            builder.AddHttpProtocol();
            break;
    }
});

services.AddTransient<ITestContract, TestService>();

var provider = services.BuildServiceProvider();

provider.UseMicroService(address =>
{
    address.Service = "192.168.1.xx";//服务注册地址,需要保持与客户端的网络访问
    address.Host = "localhost";  //主机地址
    address.Port = 5001; //端口地址
});

Client

var services = new ServiceCollection()
    .AddMicroClient(opt =>
    {
        opt.AddJsonCoder() //json编解码
            .AddHttpProtocol()
            .AddTcpProtocol() //客户端允许支持多种协议
            .AddConsul("http://127.0.0.1:8500");
    });
var provider = services.BuildServiceProvider();
var proxy = provider.GetService<IProxyFactory>();
var service = proxy.Create<ITestContract>();

BenchMark

image

spear's People

Contributors

shoy160 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.