在新版本的服务网关中提供了服务发现和泛域名路由解决功能,服务发现能够在无须配置的状况下实现服务自动注册到网关中解脱对服务配置的繁琐工做;而泛域名路由则能够针对不一样的域名制定不一样的负载规则。git
网关须要维护相关负载的服务器,手动添加相对来讲是一件比较麻烦的工做;为了解决这一问题组件扩展了一个基于consul
服务发现插件,经过配置这个插件和启用后网关会自动从consul
服务中获取服务并添加到网关对应的路由负载规则中。github
Bumblebee
中使用服务发现须要引用两个插件,分别是BeetleX.Bumblebee.Configuration
和BeetleX.Bumblebee.BeetleX.Bumblebee.Consul
。加载启动后就能够经过管理工具进行插件配置.web
g = new Gateway(); g.HttpOptions( o => { o.Port = 80; o.LogToConsole = true; o.LogLevel = BeetleX.EventArgs.LogType.Error; }); g.Open(); g.LoadPlugin( typeof(Bumblebee.Configuration.Management).Assembly, typeof(Bumblebee.Consul.ConsulPlugin).Assembly );
若是不想本身编写代码能够下载编译的运行包 https://github.com/IKende/Bumblebee/blob/master/bin/ 下载1.1.9
或更高版本;运行后 访问 http://host/__system/bumblebee/json
运行程序后进行配置管理工具的插件管理页面,能够看到Consul插件,组件默认是关闭须要进行一些配置。api
{ "ConsulAddress": "http://192.168.2.19:8500", "Services": [ "bumblebee_services" ], "Token": null, "DataCenter": "dc1" }
Consul
的服务地址Consul
相应的Token信息配置完成后只须要启用插件便可服务器
Dictionary<string, string> meta = new Dictionary<string, string>(); meta.Add("path", "^/home.*"); client.Agent.ServiceDeregister("api_test1").Wait(); client.Agent.ServiceDeregister("api_test2").Wait(); client.Agent.ServiceRegister(new AgentServiceRegistration { Tags = new string[] { "Bumblebee" }, Address = "192.168.2.18", Port = 8080, Name = "bumblebee_services", Meta = meta, ID = "api_test1" }).Wait();
以上是一个简单的注册代码,若是想服务须要注册到相应路由规则下的负载须要指定path
,在不指写的状况bumblebee
获取后会注册到默认路由规则上。工具
bumblebee
内部有一套服务监控和故障处理机制无须依据consul相关状态注册信息;bumblebee
会根据自身的检测机制对应用进行一个负载迁移和恢复处理。flex
泛域名解释在web
服务代理中比较经常使用的功能,主要由代理服务器根据不一样请求的域名来作不需同服务的转发。Bumblebee一样也支持泛域名路由解释,就是针对不一样请求的域名来制定不一样的转发规则。Bumblebee
对泛域名的转发配置很是简单只须要加载BeetleX.Bumblebee.Configuration
新版本插件在路由管理配置便可(因为组件支持标准的http1.1协议,Bumblebee
不只能够作webapi网关,还能作网站代理)。网站
Bumblebee配置路由解释,只须要加载BeetleX.Bumblebee.Configuration
插件启动后在Routes
中配置便可.spa
g = new Gateway(); g.HttpOptions( o => { o.Port = 80; o.LogToConsole = true; o.LogLevel = BeetleX.EventArgs.LogType.Error; }); g.Open(); g.LoadPlugin( typeof(Bumblebee.Configuration.Management).Assembly );
若是不想本身编写代码能够下载编译的运行包 https://github.com/IKende/Bumblebee/blob/master/bin/ 下载1.2或更高版本;运行后 访问 http://host/__system/bumblebee/
在Routes
添加路由规则,若是转发规则须要对域名进行一个匹配那规则是域名|路径
beetlexjs.ikende.com|.*
以上规则是配置通过beetlexjs.ikende.com
域访问的全部请求都到这个规则里。
以上官网的路由配置规则 beetlexjs.ikende.com|.*
路由到http://localhost:8081/
,而其它则路由http://localhost:8080/
。因为服务打开了处理服务地址输出因此访问这两个域的头信息能够看到:
更多资料可查看组件开源网站 https://github.com/IKende/Bumblebee/wiki