From 43ee6268ed3569dd941cb83ccc74b624d79c9be1 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 27 Oct 2017 16:38:25 +0800 Subject: [PATCH] update readme --- README.md | 9 ++++----- README.zh-cn.md | 29 +++++++++++------------------ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c27185a..d974b4e 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ public void Configure(IApplicationBuilder app) Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send message -```cs +```c# public class PublishController : Controller { private readonly AppDbContext _dbContext; @@ -109,9 +109,9 @@ public class PublishController : Controller { using (var trans = dbContext.Database.BeginTransaction()) { - // your business code + // your business code - //Achieving atomicity between original database operation and the publish event log thanks to a local transaction + //Achieving atomicity between original database operation and the publish event log thanks to a local transaction await publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); trans.Commit(); @@ -128,10 +128,9 @@ public class PublishController : Controller Add the Attribute `[CapSubscribe()]` on Action to subscribe message: -```cs +```c# public class PublishController : Controller { - [NoAction] [CapSubscribe("xxx.services.account.check")] public async Task CheckReceivedMessage(Person person) { diff --git a/README.zh-cn.md b/README.zh-cn.md index e2b86e6..95de0d9 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -97,32 +97,25 @@ public void Configure(IApplicationBuilder app) ```c# public class PublishController : Controller { - private readonly ICapPublisher _publisher; - - public PublishController(ICapPublisher publisher) - { - _publisher = publisher; - } + private readonly AppDbContext _dbContext; - - [Route("~/checkAccount")] - public async Task PublishMessage() + public PublishController(AppDbContext dbContext) { - //指定发送的消息头和内容 - await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); - - return Ok(); + _dbContext = dbContext; } [Route("~/checkAccountWithTrans")] - public async Task PublishMessageWithTransaction([FromServices]AppDbContext dbContext) + public async Task PublishMessageWithTransaction([FromServices]ICapPublisher publisher) { - using (var trans = dbContext.Database.BeginTransaction()) - { - await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); + using (var trans = dbContext.Database.BeginTransaction()) + { + // your business code + + //Achieving atomicity between original database operation and the publish event log thanks to a local transaction + await publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 }); trans.Commit(); - } + } return Ok(); } }