Browse Source

Fix sample code error. #701

master
Savorboard 4 years ago
parent
commit
a1fc033200
2 changed files with 16 additions and 21 deletions
  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 View File

@@ -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 View File

@@ -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…
Cancel
Save