Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

49 rindas
1.3 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP;
  4. using Microsoft.AspNetCore.Authorization;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.Extensions.Logging;
  7. namespace Sample.Dashboard.Auth.Controllers
  8. {
  9. [Authorize]
  10. [Route("api/[controller]")]
  11. public class ValuesController : Controller
  12. {
  13. private readonly ICapPublisher _capBus;
  14. private readonly ILogger<ValuesController> _logger;
  15. private const string MyTopic = "sample.dashboard.auth";
  16. public ValuesController(ICapPublisher capPublisher, ILogger<ValuesController> logger)
  17. {
  18. _capBus = capPublisher;
  19. _logger = logger;
  20. }
  21. [Route("publish")]
  22. public async Task<IActionResult> Publish()
  23. {
  24. await _capBus.PublishAsync(MyTopic, new Person()
  25. {
  26. Id = new Random().Next(1, 100),
  27. Name = "Bar"
  28. });
  29. return Ok();
  30. }
  31. [NonAction]
  32. [CapSubscribe(MyTopic)]
  33. public void Subscribe(Person p, [FromCap] CapHeader header)
  34. {
  35. _logger.LogInformation("Subscribe Invoked: " + MyTopic + p);
  36. }
  37. public class Person
  38. {
  39. public int Id { get; set; }
  40. public string Name { get; set; }
  41. }
  42. }
  43. }