Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active June 17, 2020 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/199af44b00a82fb4e6f89c6ed0417d78 to your computer and use it in GitHub Desktop.
Save dcomartin/199af44b00a82fb4e6f89c6ed0417d78 to your computer and use it in GitHub Desktop.
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