From a1fc03320016b293baa7db52c277931027280af6 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 29 Oct 2020 13:52:58 +0800 Subject: [PATCH] Fix sample code error. #701 --- .../Sample.RabbitMQ.SqlServer/AppDbContext.cs | 14 +---------- .../Controllers/ValuesController.cs | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs b/samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs index e24e04d..e8835c6 100644 --- a/samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs +++ b/samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs @@ -12,19 +12,7 @@ namespace Sample.RabbitMQ.SqlServer { return $"Name:{Name}, Id:{Id}"; } - } - - public class Person2 - { - public int Id { get; set; } - - public string Name { get; set; } - - public override string ToString() - { - return $"Name:{Name}, Id:{Id}"; - } - } + } public class AppDbContext : DbContext { diff --git a/samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs index 24d1848..c7e32dc 100644 --- a/samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs @@ -1,5 +1,4 @@ using System; -using System.Data; using System.Threading.Tasks; using Dapper; using DotNetCore.CAP; @@ -21,7 +20,7 @@ namespace Sample.RabbitMQ.SqlServer.Controllers [Route("~/without/transaction")] public async Task WithoutTransaction() { - await _capBus.PublishAsync("sample.rabbitmq.mysql", new Person() + await _capBus.PublishAsync("sample.rabbitmq.sqlserver", new Person() { Id = 123, Name = "Bar" @@ -40,7 +39,11 @@ namespace Sample.RabbitMQ.SqlServer.Controllers //your business code connection.Execute("insert into test(name) values('test')", transaction: transaction); - _capBus.Publish("sample.rabbitmq.mysql", DateTime.Now); + _capBus.Publish("sample.rabbitmq.sqlserver", new Person() + { + Id = 123, + Name = "Bar" + }); } } @@ -54,21 +57,25 @@ namespace Sample.RabbitMQ.SqlServer.Controllers { dbContext.Persons.Add(new Person() { Name = "ef.transaction" }); - _capBus.Publish("sample.rabbitmq.mysql", DateTime.Now); + _capBus.Publish("sample.rabbitmq.sqlserver", new Person() + { + Id = 123, + Name = "Bar" + }); } return Ok(); } [NonAction] - [CapSubscribe("sample.rabbitmq.mysql")] - public void Subscriber(DateTime p) + [CapSubscribe("sample.rabbitmq.sqlserver")] + public void Subscriber(Person p) { Console.WriteLine($@"{DateTime.Now} Subscriber invoked, Info: {p}"); } [NonAction] - [CapSubscribe("sample.rabbitmq.mysql", Group = "group.test2")] - public void Subscriber2(DateTime p, [FromCap]CapHeader header) + [CapSubscribe("sample.rabbitmq.sqlserver", Group = "group.test2")] + public void Subscriber2(Person p, [FromCap]CapHeader header) { Console.WriteLine($@"{DateTime.Now} Subscriber invoked, Info: {p}"); }