GithubHelp home page GithubHelp logo

followmetech / fm.consulinterop Goto Github PK

View Code? Open in Web Editor NEW
32.0 8.0 6.0 212 KB

a lib for build micro-service

License: MIT License

PowerShell 0.53% C# 99.47%
consul grpc dotnet dotnet-core microservice consul-kv docker

fm.consulinterop's Introduction

FM.ConsulInterop -a lib for simple build micro service

解决了什么问题

依赖的技术栈

组件交互图

功能

  • 简化grpc-srv注册到consul的交互方式 (简单的配置文件/一个扩展方法)
  • 简化grpc-client 消费grpc-srv的交互方式 (简单的配置文件/proxy模式)
  • 客户端定时自动发现srv,并自动负载请求到srv
  • 客户端中间件(认证/log/timeout..)

let's getting start

如何启动:

simples代码

  1. 下载consul, 启动consul命令 (consul agent -dev)
  2. 修改samples/下面的appsettings配置文件设置相关的consul地址,和srv-监听地址
  3. 启动srv ,启动client
客户端和服务端的配置文件详解
{
  "consul": {
    "service": {  ##给srv用的节点
      "ServiceName": "followme.srv.demo.x",  ##注册到consul中的srv-name
      "ConsulAddress": "http://localhost:8500", ##consul服务地址
      "ServiceAddress": "192.168.*.*:0",  ## 服务启动的IP/Port ,可以填写网段信息,端口为0表示auto-choose
      "ConsulIntegration": "true", ##是否需要把服务信息注册到consul中
      "ConsulTags": "v-1.0.0.1", ##tag ,和go-micro通讯必须要注册tag值
      "TCPInterval": 10  ##consul health check ,这里使用的是TTL模式
    },
    "remotes": {
      "demo": {  #####这里是给客户端使用的节点
        "name": "demo.x",  ####准备遗弃的配置!
        "ServiceName": "followme.srv.demo.x", ####客户端需要消费的服务名(通过这个名字来找到相应的服务提供的地址)
        "FreshInterval": 10000,  #### 客户端需要定时的刷新服务列表,时间毫秒
        "ConsulAddress": "http://localhost:8500", ### consul的地址
        "ConsulIntegration": "true", ### 客户端是否需要从consul获取服务地址
        "ServiceAddress": "" ### 当ConsulIntegration=false的时候, 这里的地址可以配置服务的具体ip:port方式
      }
    }
	}
}

srv启动代码解析

var srvConfig = conf. GetSection("consul").GetSection("service").
Get<ConsulLocalServiceConfig>();
new Server
{
     Services = { FM.Demo.HelloSrv.BindService(new HelloSrvImp()) },
}.StartAndRegisterService(srvConfig).Wait();

//获取配置文件中配置的service节点
//通过使用扩展方法[StartAndRegisterService]来启动grpc-服务
//服务启动之后,查看consulUI中的相关界面信息,发现服务已经注册成功!

client消费srv代码解析

//通过配置文件获取client需要消费的那个srv组(因为srv可以同时启动多个)
var clientConfig = conf.GetSection("consul").GetSection("remotes").GetSection("demo").
                Get<ConsulRemoteServiceConfig>();

//FM.Demo.HelloSrv.HelloSrvClient 是grpc subclass(通过protoc工具生成)
//ClientAgent是封装了所有客户端调用的类
//负责做负载, 自动发现新的服务, 踢掉不能用的服务..
//通过ClientAgent来初始化clientProxy
var client =new ClientAgent<FM.Demo.HelloSrv.HelloSrvClient>(clientConfig);
//Hi是FM.Demo.HelloSrv.HelloSrvClient提供的元方法
client.Proxy.Hi(new FM.Demo.HiRequest());

了解内部log

可以通过如下的代码来查看内部的log细节

FM.ConsulInterop.InnerLogger.ConsulLog += (s, c) =>Console.WriteLine(c.Content);

如何贡献

  • issue
  • merge request

license

MIT

fm.consulinterop's People

Contributors

larymao avatar lincuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fm.consulinterop's Issues

nuget package

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
发布到nuget.org

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

疑问。

image
刚刚做了一个高可用测试,发现只要有服务挂掉就一定会出错

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.