diff --git a/README.md b/README.md index 692bdf1..000ba1c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@   中文

-# CAP - +# CAP                        [![Travis branch](https://img.shields.io/travis/dotnetcore/CAP/develop.svg?label=travis-ci)](https://travis-ci.org/dotnetcore/CAP) [![AppVeyor](https://ci.appveyor.com/api/projects/status/4mpe0tbu7n126vyw?svg=true)](https://ci.appveyor.com/project/yuleyule66/cap) [![NuGet](https://img.shields.io/nuget/v/DotNetCore.CAP.svg)](https://www.nuget.org/packages/DotNetCore.CAP/) @@ -29,26 +28,30 @@ This is a diagram of the CAP working in the ASP.NET Core MicroService architectu ## Getting Started -### NuGet (Coming soon) +### NuGet You can run the following command to install the CAP in your project. +``` +PM> Install-Package DotNetCore.CAP -Pre +``` + If your Message Queue is using Kafka, you can: ``` PM> Install-Package DotNetCore.CAP.Kafka -Pre ``` -or RabbitMQ: +If your Message Queue is using RabbitMQ, you can: ``` PM> Install-Package DotNetCore.CAP.RabbitMQ -Pre ``` -CAP provides EntityFramework as default database store extension : +CAP provides EntityFramework as default database store extension (The MySQL version is under development): ``` -PM> Install-Package DotNetCore.CAP.EntityFrameworkCore -Pre +PM> Install-Package DotNetCore.CAP.SqlServer -Pre ``` ### Configuration @@ -60,11 +63,23 @@ public void ConfigureServices(IServiceCollection services) { ...... - services.AddDbContext(); + services.AddDbContext(); - services.AddCap() - .AddEntityFrameworkStores() - .AddKafka(x => x.Servers = "localhost:9092"); + services.AddCap(x => + { + // If your SqlServer is using EF for data operations, you need to add the following configuration: + // Notice: You don't need to config x.UseSqlServer(""") again! + x.UseEntityFramework(); + + // If you are using Dapper,you need to add the config: + x.UseSqlServer("Your ConnectionStrings"); + + // If your Message Queue is using RabbitMQ you need to add the config: + x.UseRabbitMQ("localhost"); + + // If your Message Queue is using Kafka you need to add the config: + x.UseKafka("localhost"); + }); } public void Configure(IApplicationBuilder app) @@ -94,11 +109,23 @@ public class PublishController : Controller [Route("~/checkAccount")] public async Task PublishMessage() { - //Specifies the message header and content to be sent + // Specifies the message header and content to be sent await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); return Ok(); } + + [Route("~/checkAccountWithTrans")] + public async Task PublishMessageWithTransaction([FromServices]AppDbContext dbContext) + { + using (var trans = dbContext.Database.BeginTransaction()) + { + await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); + + trans.Commit(); + } + return Ok(); + } } ``` @@ -148,7 +175,7 @@ namespace xxx.Service public class SubscriberService: ISubscriberService, ICapSubscribe { - [CapSubscribe("xxx.services.account.check")] + [KafkaTopic("xxx.services.account.check")] public void CheckReceivedMessage(Person person) {