Menu
🌜
🌞
- 1. 框架介绍
- 2. 注册中心
- 3. 服务Provider
- 4. 网关&监控
- 5. 服务资源监控
- 6. 集群接口文档
- 7. Hello World
- 8. 集成Java
- 9. 进阶指南
- 10. 领域驱动设计
- 11. 事件总线
- 12. 更多
- 13.1 好文章集合
## Viper http://49.232.112.70# http://49.232.112.70 账号:anno 密码:123456Viper 是.NET6.0平台下基于Anno开发的Dashboard面板项目,包括集群看板、服务调用分析、服务接口文档、服务在线安装部署等功能。 也可以作为Anno入门的模板项目。

<appSettings> <!— 数据库连接字符串 Mysql—> <add key="ConnStr" value="server=127.0.0.1;database=viper;uid=bif;pwd=123456;SslMode=None;"/> </appSettings> ### 第一步:启动注册中心#配置文件:
Viper\ViperService\bin\Debug\net6.0\Anno.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <!—ViperCenter 端口—> <Port>7010</Port> <!—ViperCenter 超时时间—> <TimeOut>120000</TimeOut> <Servers> <!—dc 注册到注册中心的 服务节点 (下面的内容是ViperService 启动后自动写入的内容)—> <dc name="Anno.Plugs.LogicService,Anno.Plugs.TraceService,Anno.Plugs.ViperService" nickname="ViperService-01" ip="100.100.100.9" port="7011" timeout="20000" weight="1" /> </Servers> </configuration> - 进入项目文件夹配置文件:
Viper\ViperCenter\bin\Debug\net6.0\Anno.config
Viper\ViperCenter\bin\Debug\net6.0
- 运行命令 dotnet ViperCenter.dll
- 看到下图 说明运行成功

<?xml version="1.0" encoding="utf-8" ?> <configuration> <!—0,0 第一位是 工作站,第二位数据中心 (所有的 AnnoService 的 两位数不能重复例如不能存在【1,2】【1,2】) 可以存在【1,2】【2,1】 —> <IdWorker>0,0</IdWorker> <!—App名称—> <AppName>ViperService-01</AppName> <!—监听端口—> <Port>7011</Port> <!—权重—> <Weight>1</Weight> <!—功能 非Anno.Plugs 加入方式—> <FuncName></FuncName> <!—忽略的功能 Trace,Logic—> <IgnoreFuncName></IgnoreFuncName> <!—超时时间毫秒—> <TimeOut>20000</TimeOut> <!—注册到的目标—> <Ts Ip="127.0.0.1" Port="7010"/> <IocDll> <!— IOC 仓储—><!— <Assembly>Anno.Repository</Assembly> —><!— 领域—><!— <Assembly>Anno.Domain</Assembly> —><!— 查询服务—><!— <Assembly>Anno.QueryServices</Assembly> —><!—事件Handler—><!— <Assembly>Anno.Command.Handler</Assembly>—> </IocDll> <appSettings> <!— 数据库连接字符串 Mysql—> <add key="ConnStr" value="server=127.0.0.1;database=viper;uid=bif;pwd=123456;SslMode=None;"/> </appSettings> </configuration> ##### 说明 一般情况下只用修改 下面两行配置 <!—注册到的目标—> <Ts Ip="127.0.0.1" Port="7010"/> <!— 数据库连接字符串 Mysql—> <add key="ConnStr" value="server=xxxx;"/>配置文件:
Viper\ViperService\bin\Debug\net6.0\Anno.config
ViperService
和 ViperCenter
可以不在同一台电脑,ViperService
也可以采用不同端口运行多个Service
。ViperCenter
可以根据客户端请求自动负载均衡。高级用法随后介绍。
- 进入项目文件夹 Viper\ViperService\bin\Debug\net6.0
- 运行命令 dotnet ViperService.dll
- 看到下图 说明 ViperService
成功运行 并且已经注册到 注册中心(ViperCenter)运行成功

{ "Target": { "AppName": "ApiGateway", //网关名称 "IpAddress": "127.0.0.1", //注册中心地址 "Port": 7010, //注册中心监听端口 "TraceOnOff": true //true 开启链路追踪,false 关闭 }, "Limit": { //网关限流 (每个服务也可以设定自己的限流策略) "Enable": true, //启用限流 "TagLimits": [ // 根据Tag标签限流 【channel】【router】 { "channel": "", //匹配所有 "router": "", //匹配所有 "timeSpan": "1", //时间片单位秒 "rps": 100, "limitSize": 100 //桶默认大小 } ], "DefaultIpLimit": { // 默认客户端IP限流 "timeSpan": 1, "rps": 100, "limitSize": 100 }, "IpLimits": [ //针对不同IP设置不同的IP限流策略 { "ipMatch": "0.0.0.1", //ipMatch参考IPAddressRange "timeSpan": 1, "rps": 100, "limitSize": 100 }, { "ipMatch": "192.168.0.10 - 192.168.10.20", "timeSpan": 1, "rps": 100, "limitSize": 100 } ], "White": [ //白名单 "0.0.0.1", "192.168.1.2", "192.168.2.18" ], "Black": [ //黑名单 "0.0.0.2", "192.168.3.18" ] } } 链路追踪列表:配置文件:
Viper\Viper\appsettings.json
调用链详情:
### 第四步:集群路由信息# 集群路由列表:
集群路由详情:
调试一个邮件接口
看到下面消息说明调用成功 { "msg":null, "status":true, "output":{}, "outputData":null } ### 第五步:服务性能监控# 监控
DashBoard
点击最近7日追踪柱状图可切换对每个服务Provider
或者网关
进行监控 
InMemory
and Rabbitmq
### 2.1 Server配置#
//指定EventHandler的 所在程序集
var funcs = Anno.Const.Assemblys.Dic.Values.ToList();
#region RabbitMQEventBus
//消费失败通知
RabbitMQEventBus.Instance.ErrorNotice +=
(string exchange, string routingKey, Exception exception, string body) =>
{
Log.Fatal(new { exchange, routingKey, exception, body }
, typeof(RabbitMQEventBus));
};
EventBusSetting.Default.RabbitConfiguration = new RabbitConfiguration()
{
HostName = "192.168.100.173",
VirtualHost = "dev",
UserName = "dev",
Password = "dev",
Port = 5672
};
RabbitMQEventBus.Instance.SubscribeAll(funcs);
#endregion
#region InMemory EventBus
EventBus.Instance.ErrorNotice +=
(string exchange, string routingKey, Exception exception, string body) =>
{
Log.Fatal(new { exchange, routingKey, exception, body }, typeof(EventBus));
};
EventBus.Instance.SubscribeAll(funcs);
### 2.2 EventData配置#
using Anno.EventBus;
namespace Events
{
public class FirstMessageEvent:EventData
{
public string Message { get; set; }
}
}
### 2.3 EventHandler配置#
namespace Anno.Plugs.SamsundotService.EventHandler
{
using Anno.EventBus;
using Events;
class FirstMessageEventHandler : IEventHandler<FirstMessageEvent>
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs= "Samsundot",Entity=entity }
,typeof(FirstMessageEventHandler));
}
}
}
namespace Anno.Plugs.YYTestService.EventHandler
{
using Anno.EventBus;
using Events;
class FirstMessageEventHandler : IEventHandler<FirstMessageEvent>
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs = "YYTest", Entity = entity }
, typeof(FirstMessageEventHandler));
}
}
/// <summary>
/// 异常消费演示,测试 消费失败通知
/// </summary>
class FirstMessageExceptionEventHandler : IEventHandler<FirstMessageEvent>
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs = "YYTest",Handle= "FirstMessageExceptionEventHandler"
, Entity = entity }, typeof(FirstMessageEventHandler));
throw new Exception(
"异常消费演示,测试 消费失败通知 From FirstMessageExceptionEventHandler!");
}
}
}
### 2.4 缓存中间件#
#### Install-Package Anno.EngineData.Cache#
Install-Package Anno.EngineData.Cache
using System;
using System.Collections.Generic;
using System.Text;
using Anno.EngineData;
using Anno.EngineData.Cache;
namespace Anno.Plugs.CacheRateLimitService
{
public class CacheModule : BaseModule
{
/
参数1:缓存长度
参数2:缓存存活时间
参数3:缓存存活时间是否滑动
/
[CacheLRU(5,6,true)]
public ActionResult Cache(string msg)
{
Console.WriteLine(msg);
return new ActionResult(true, null,null,msg);
}
}
}
### 2.5 限流中间件#
#### Install-Package Anno.EngineData.RateLimit#
Install-Package Anno.EngineData.RateLimit
using System;
using System.Collections.Generic;
using System.Text;
using Anno.EngineData;
using Anno.RateLimit;
namespace Anno.Plugs.CacheRateLimitService
{
public class LimitModule : BaseModule
{
/
参数1:限流算法是令牌桶还是漏桶
参数2:限流时间片段单位秒
参数3:单位时间可以通过的请求个数
参数4:桶容量
/
[EngineData.Limit.RateLimit(LimitingType.TokenBucket,1,5,5)]
public ActionResult Limit(string msg)
{
Console.WriteLine(msg);
return new ActionResult(true, null, null, msg);
}
}
}
Edit this page
Previous
« 1.1 Anno 分布式微服务开发框架
Next
1.3 项目源码结构 »
- Viper http://49.232.112.70
- Java 实现
- 1、运行Viper
- 第一步:启动注册中心
- 第二步:启动 ViperService
- 第三步:调用链追踪
- 第四步:集群路由信息
- 第五步:服务性能监控
- 2、Anno EventBus
- 2.1 Server配置
- 2.2 EventData配置
- 2.3 EventHandler配置
- 2.4 缓存中间件
- 2.5 限流中间件
文档
社区
更多
Copyright © 2022 Anno.