Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/duyanming/annodemo
Anno 是一个微服务快速开发框架,底层通讯可以随意切换 grpc、thrift。自带服务发现、调用链追踪、Cron 调度、限流、事件总线、CQRS 、DDD、类似MVC的开发体验,插件化开发。. Anno is a microservices rapid development framework, the underlying communication can be arbitrary switch GRPC, thrift.Built-in service discovery, call chain tracking, Cron scheduling, current limiting, event bus, CQRS, DDD, similar MVC development experience, plug-in development.
https://github.com/duyanming/annodemo
anno eventbus grpc ioc microservice netcore ratelimit thrift
Last synced: 2 months ago
JSON representation
Anno 是一个微服务快速开发框架,底层通讯可以随意切换 grpc、thrift。自带服务发现、调用链追踪、Cron 调度、限流、事件总线、CQRS 、DDD、类似MVC的开发体验,插件化开发。. Anno is a microservices rapid development framework, the underlying communication can be arbitrary switch GRPC, thrift.Built-in service discovery, call chain tracking, Cron scheduling, current limiting, event bus, CQRS, DDD, similar MVC development experience, plug-in development.
- Host: GitHub
- URL: https://github.com/duyanming/annodemo
- Owner: duyanming
- Created: 2019-11-04T09:20:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T09:26:51.000Z (about 2 years ago)
- Last Synced: 2023-03-03T08:26:55.163Z (almost 2 years ago)
- Topics: anno, eventbus, grpc, ioc, microservice, netcore, ratelimit, thrift
- Language: C#
- Homepage: https://duyanming.github.io/
- Size: 1.66 MB
- Stars: 15
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AnnoDemo
Anno 分布式开发框架 Demo## [Java 实现 ](https://github.com/duyanming/anno.thrift-parent) : https://github.com/duyanming/anno.thrift-parent
## [Demo 在线演示地址](http://140.143.207.244) :http://140.143.207.244
账号:anno
密码:123456
# Anno 分布式开发框架Anno 是一个分布式开发框架,同时支持 .net core3.1 、.net frameworker4.6.1
## 1、运行Demo
```
第一步:启动注册中心
```进入项目文件夹 AnnoDemo\registryCenter\bin\Debug\netcoreapp3.1
运行命令 dotnet registryCenter.dll
看到下图 说明运行成功
![第一步](https://s1.ax1x.com/2020/07/30/anl5P1.png)```
第二步:启动Server
```Server可以和 AppCenter 不在同一台电脑,也可以运行多个server 也可以负载均衡,高级用法随后介绍
进入项目文件夹 AAnnoDemo\hostingService\bin\Debug\netcoreapp3.1
运行命令 dotnet hostingService.dll
看到下图 说明 Server 成功运行 并且已经注册到 注册中心(APPCenter)运行成功
![第二步](https://s1.ax1x.com/2020/07/30/anlh5R.png)启动AnnoWeb
第三步:调用链追踪
![第三步](https://s1.ax1x.com/2020/07/30/anlo26.png)
```
调用链详情
```![第三步](https://s1.ax1x.com/2020/07/30/anlI8x.png)
第四步:集群路由信息
![第三步](https://s1.ax1x.com/2020/07/30/anGPsK.png)
![第三步](https://s1.ax1x.com/2020/07/30/anGNzq.png)
```
调试邮件接口成功
```![第三步](https://s1.ax1x.com/2020/07/30/anJipn.png)
第五步:服务性能监控
![第四步](https://s1.ax1x.com/2020/07/30/anlHKO.png)# Anno EventBus
Eventbus Support InMemory and Rabbitmq
## 1、Server配置```c#
//指定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、EventData配置
```c#
using Anno.EventBus;
namespace Events
{
public class FirstMessageEvent:EventData
{
public string Message { get; set; }
}
}```
## 3、EventHandler配置
```c#
namespace Anno.Plugs.SamsundotService.EventHandler
{
using Anno.EventBus;
using Events;
class FirstMessageEventHandler : IEventHandler
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs= "Samsundot",Entity=entity },typeof(FirstMessageEventHandler));
}
}
}```
```c#
namespace Anno.Plugs.YYTestService.EventHandler
{
using Anno.EventBus;
using Events;
class FirstMessageEventHandler : IEventHandler
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs = "YYTest", Entity = entity }, typeof(FirstMessageEventHandler));
}
}
///
/// 异常消费演示,测试 消费失败通知
///
class FirstMessageExceptionEventHandler : IEventHandler
{
public void Handler(FirstMessageEvent entity)
{
Log.Log.Info(new { Plugs = "YYTest",Handle= "FirstMessageExceptionEventHandler", Entity = entity }, typeof(FirstMessageEventHandler));
throw new Exception("异常消费演示,测试 消费失败通知 From FirstMessageExceptionEventHandler!");
}
}
}```
## 4、中间件
### 4.1 缓存中间件
#### nuget install```shell
Install-Package Anno.EngineData.Cache
```
```c#
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);
}
}
}```
### 4.2 限流中间件
#### nuget install```shell
Install-Package Anno.EngineData.RateLimit
```
```c#
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);
}
}
}```
#dotnet
dotnet publish "E:\gitProject\Anno\DCS\AppCenter\AppCenter.csproj" -c Release -r linux-x64 -o "E:\gitProject\Anno\DCS\AppCenter\bin"#配置文件说明
```json
{
"Target": {
"AppName": "traceWeb",--服务名称
"IpAddress": "127.0.0.1",--注册中心地址
"Port": 6660,--注册中心端口
"TraceOnOff": true--启用调用链追踪
},
"Limit": {--限流
"Enable": true,--是否启用限流
"TagLimits": [--标签限流
{
"channel": "*",--管道
"router": "*",--路由
"timeSpan": "10",--时间片单位秒
"rps": 1,--时间片内的 有效请求个数
"limitSize": 2--漏桶容量大小 做缓冲用
}
],
"IpLimit": {--IP限流
"timeSpan": 1,
"rps": 20,
"limitSize": 200
},
"WhiteList": [--白名单
"192.168.1.1",
"192.168.2.18"
]
}
}```