Last active
June 17, 2020 23:31
-
-
Save dcomartin/199af44b00a82fb4e6f89c6ed0417d78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using DotNetCore.CAP; | |
using MySql.Data.MySqlClient; | |
namespace CAPDemo.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
private readonly ICapPublisher _capPublisher; | |
public HomeController(ICapPublisher capPublisher) | |
{ | |
_capPublisher = capPublisher; | |
} | |
public async Task<IActionResult> Index() | |
{ | |
using (var connection = new MySqlConnection("Server=localhost;Uid=root;Pwd=root;Database=Demo")) | |
{ | |
using (var transaction = connection.BeginTransaction(_capPublisher)) | |
{ | |
// This is where you would do other work that is going to persist data to your database | |
await _capPublisher.PublishAsync("helloWorld", "CodeOpinion"); | |
await transaction.CommitAsync(); | |
} | |
} | |
return View(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment