Anno 是一个分布式开发框架,同时支持 .net core3.0 、.net frameworker4.6.1。
第一步:启动注册中心
进入项目文件夹 AnnoDemo\YY.AppCenter\bin\Debug\netcoreapp3.0 ,运行命令 dotnet AppCenter.dll
看到下图 说明运行成功
![第一步](https://camo.githubusercontent.com/f55e6744b460d5d3b7f9601f2da6bf10487ceac5952f7b8b2b0bea494504c15c/68747470733a2f2f73312e617831782e636f6d2f323032302f30372f33312f614d766b64672e706e67)
第二步:启动Server
Server可以和 AppCenter 不在同一台电脑,也可以运行多个server 也可以负载均衡,高级用法随后介绍
进入项目文件夹 AnnoDemo\YY.Server\bin\Debug\netcoreapp3.0 ,运行命令 dotnet YY.Server.dll
看到下图 说明 Server 成功运行 并且已经注册到 注册中心(APPCenter)运行成功
![第二步](https://camo.githubusercontent.com/2710cb6a7af0ed0c96ae65e8fc6d6b189ca88395d150e58f22db40a10b18a26e/68747470733a2f2f73312e617831782e636f6d2f323032302f30372f33312f614d76416f512e706e67)
第三步:启动Client
启动Client 测试 Client调用 Server是否成功
进入项目文件夹 AnnoDemo\YY.Client\bin\Debug\netcoreapp3.0 ,运行命令 dotnet YY.Client.dll
看到下图 说明 Client 成功运行
![第三步](https://camo.githubusercontent.com/3ca153091112ce5143025de0c96f8e6d809120580fe075c93978f2f71739d36a/68747470733a2f2f73312e617831782e636f6d2f323032302f30372f33312f614d764665532e706e67)
![第四步](https://camo.githubusercontent.com/9e38b48cd10d83d2cf93f249a377a0fe9bcee4ffc01b87f7ef55ec32e337a097/68747470733a2f2f73312e617831782e636f6d2f323032302f30372f33312f614d76504c382e706e67)
Eventbus Support InMemory and Rabbitmq
//指定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);
using Anno.EventBus;
namespace Events
{
public class FirstMessageEvent:EventData
{
public string Message { get; set; }
}
}
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!");
}
}
}
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);
}
}
}
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);
}
}
}