You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
1.4 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP;
  4. using DotNetCore.CAP.Messages;
  5. using Microsoft.AspNetCore.Authorization;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. namespace Sample.RabbitMQ.Postgres.DashboardAuth.Controllers
  9. {
  10. [Authorize]
  11. [Route("api/[controller]")]
  12. public class ValuesController : Controller
  13. {
  14. private readonly ICapPublisher _capBus;
  15. private readonly ILogger<ValuesController> _logger;
  16. private const string CapGroup = "sample.rabbitmq.postgres.dashboard";
  17. public ValuesController(ICapPublisher capPublisher, ILogger<ValuesController> logger)
  18. {
  19. _capBus = capPublisher;
  20. _logger = logger;
  21. }
  22. [Route("publish")]
  23. public async Task<IActionResult> Publish()
  24. {
  25. await _capBus.PublishAsync(CapGroup, new Person()
  26. {
  27. Id = 123,
  28. Name = "Bar"
  29. });
  30. return Ok();
  31. }
  32. [NonAction]
  33. [CapSubscribe(CapGroup)]
  34. public void Subscribe(Person p, [FromCap] CapHeader header)
  35. {
  36. var id = header[Headers.MessageId];
  37. _logger.LogInformation($@"{DateTime.Now} Subscriber invoked for message {id}, Info: {p}");
  38. }
  39. public class Person
  40. {
  41. public int Id { get; set; }
  42. public string Name { get; set; }
  43. }
  44. }
  45. }