diff --git a/README.md b/README.md index 05ed9bf..9ffc9d2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a diagram of the CAP working in the ASP.NET Core MicroService architectu ![cap.png](http://oowr92l0m.bkt.clouddn.com/cap.png) -> CAP implements the Outbox Pattern described in the [eShop ebook](https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/subscribe-events#designing-atomicity-and-resiliency-when-publishing-to-the-event-bus) +> CAP implements the Outbox Pattern described in the [eShop ebook](https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/subscribe-events#designing-atomicity-and-resiliency-when-publishing-to-the-event-bus). ## Getting Started @@ -65,7 +65,7 @@ public void ConfigureServices(IServiceCollection services) // If you are using EF, you need to add the configuration: x.UseEntityFramework(); //Options, Notice: You don't need to config x.UseSqlServer(""") again! CAP can autodiscovery. - // If you are using Ado.Net, you need to add the configuration: + // If you are using Dapper, you need to add the configuration: x.UseSqlServer("Your ConnectionStrings"); x.UseMySql("Your ConnectionStrings"); x.UsePostgreSql("Your ConnectionStrings"); @@ -131,7 +131,7 @@ public class PublishController : Controller ### Subscribe -**Action Method** +**In Action Method** Add the Attribute `[CapSubscribe()]` on Action to subscribe message: @@ -147,17 +147,17 @@ public class PublishController : Controller ``` -**Service Method** +**In Service Method** If your subscribe method is not in the Controller,then your subscribe class need to Inheritance `ICapSubscribe`: ```c# -namespace xxx.Service +namespace BusinessCode.Service { public interface ISubscriberService { - public void CheckReceivedMessage(Person person); + public void CheckReceivedMessage(DateTime person); } public class SubscriberService: ISubscriberService, ICapSubscribe @@ -183,6 +183,40 @@ public void ConfigureServices(IServiceCollection services) } ``` +#### Subscribe Group + +The concept of a subscription group is similar to that of a consumer group in Kafka. it is the same as the broadcast mode in the message queue, which is used to process the same message between multiple different microservice instances. + +When CAP startup, it will use the current assembly name as the default group name, if multiple same group subscribers subscribe the same topic name, there is only one subscriber can receive the message. +Conversely, if subscribers are in different groups, they will all receive messages. + +In the same application, you can specify the `Group` property to keep they are in different consumer groups: + +```C# + +[CapSubscribe("xxx.services.show.time", Group = "group1" )] +public void ShowTime1(DateTime datetime) +{ +} + +[CapSubscribe("xxx.services.show.time", Group = "group2")] +public void ShowTime2(DateTime datetime) +{ +} + +``` +`ShowTime1` and `ShowTime2` will be called at the same time. + +BTW, You can specify the default group name in the configuration : + +```C# +services.AddCap(x => +{ + x.DefaultGroup = "default-group-name"; +}); + +``` + ### Dashboard CAP v2.1+ provides the dashboard pages, you can easily view the sent and received messages. In addition, you can also view the message status in real time on the dashboard. diff --git a/README.zh-cn.md b/README.zh-cn.md index 2713cee..2b8624f 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -192,6 +192,42 @@ public void ConfigureServices(IServiceCollection services) } ``` + +#### 订阅者组 + +订阅者组的概念类似于 Kafka 中的消费者组,它和消息队列中的广播模式相同,用来处理不同微服务实例之间同时消费相同的消息。 + +当CAP启动的时候,她将创建一个默认的消费者组,如果多个相同消费者组的消费者消费同一个Topic消息的时候,只会有一个消费者被执行。 +相反,如果消费者都位于不同的消费者组,则所有的消费者都会被执行。 + +相同的实例中,你可以通过下面的方式来指定他们位于不同的消费者组。 + +```C# + +[CapSubscribe("xxx.services.show.time", Group = "group1" )] +public void ShowTime1(DateTime datetime) +{ +} + +[CapSubscribe("xxx.services.show.time", Group = "group2")] +public void ShowTime2(DateTime datetime) +{ +} + +``` +`ShowTime1` and `ShowTime2` are In different groups, they will be called at the same time. + +BTW, You can specify the default group name in the configuration : + +```C# +services.AddCap(x => +{ + x.DefaultGroup = "default-group-name"; +}); + +``` + + ### Dashboard CAP 2.1+ 以上版本中提供了仪表盘(Dashboard)功能,你可以很方便的查看发出和接收到的消息。除此之外,你还可以在仪表盘中实时查看发送或者接收到的消息。