瀏覽代碼

Fix sample code error. #701

master
Savorboard 4 年之前
父節點
當前提交
a1fc033200
共有 2 個檔案被更改,包括 16 行新增21 行删除
  1. +1
    -13
      samples/Sample.RabbitMQ.SqlServer/AppDbContext.cs
  2. +15
    -8
      samples/Sample.RabbitMQ.SqlServer/Controllers/ValuesController.cs

+ 1
- 13
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
{


+ 15
- 8
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<IActionResult> 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}");
}


Loading…
取消
儲存