为了提高 Url 访问的统一和友好性,一般访问的 Url 和服务定义的 Url 有所不同;为了解决这一问题 Bumblebee 提供 Url 重写功能;通过 Url 重写功能可以在转发前进行一个重写后再转发到后台服务。
Bumblebee 中使用 Url 重写需要引用两个插件,分别是 Bumblebee.Configuration 和 BeetleX.Bumblebee.UrlRewrite 。加载启动后就可以通过管理工具进行插件配置.
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.UrlRewrite.RewriteLoader).Assembly
);
如果不想自己编写代码可以下载编译的运行包 https://github.com/IKende/Bumblebee/blob/master/bin/ 下载 1.1.8 或更高版本
运行程序后进行配置管理工具的插件管理页面,可以看到 Url 重写插件,组件默认是启用
Url 重写需要根据自己的情况进行配置重写规则,配置也比较简单
{
"Rewrite": [
{
"Url": "/home/{action}",
"Rewrite": "/api/{action}"
},
{
"Url": "/__system/bumblebee/config/{0}.html",
"Rewrite": "/__system/bumblebee/pluginsconfig.html"
},
{
"Url": "/api/customers/{count}",
"Rewrite": "/customers/{count}"
}
]
}
可以根据实际情况配置多组重写规则,规则配置保存后会即时生效无须重启服务。配置的规则是否生效可以通过日志查看,把日志配置成 info 即可在管理插件查看转发的日志
其他涉及的到 Url 配置处理的插件都是依据重写前的 Url 规则.
关注公众号
https://github.com/IKende/
高性能的服务通讯框架 Beetlex(http,rpc,gateway的详细实现 )