|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Diagnostics;
- using System.Threading.Tasks;
- using DotNetCore.CAP;
- using Microsoft.AspNetCore.Mvc;
-
- namespace Sample.RabbitMQ.SqlServer.Controllers
- {
- [Route("api/[controller]")]
- public class ValuesController : Controller, ICapSubscribe
- {
- private readonly ICapPublisher _capBus;
- private readonly AppDbContext _dbContext;
-
- public ValuesController(ICapPublisher producer, AppDbContext dbContext)
- {
- _capBus = producer;
- _dbContext = dbContext;
- }
-
- [Route("~/publish")]
- public IActionResult PublishMessage()
- {
- _capBus.Publish("sample.rabbitmq.mysql", "");
-
- return Ok();
- }
-
- [Route("~/publishWithTrans")]
- public async Task<IActionResult> PublishMessageWithTransaction()
- {
- using (var trans = await _dbContext.Database.BeginTransactionAsync())
- {
- await _capBus.PublishAsync("sample.rabbitmq.mysql", "");
-
- trans.Commit();
- }
- return Ok();
- }
-
- [NonAction]
- [CapSubscribe("sample.kafka.sqlserver3")]
- [CapSubscribe("sample.kafka.sqlserver4")]
- public void KafkaTest()
- {
- Console.WriteLine("[sample.kafka.sqlserver] message received");
- Debug.WriteLine("[sample.kafka.sqlserver] message received");
- }
- }
- }
|