Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace Sample.Kafka.Controllers
  7. {
  8. [Route("api/[controller]")]
  9. public class ValuesController : Controller, ICapSubscribe
  10. {
  11. private readonly ICapPublisher _producer;
  12. private readonly AppDbContext _dbContext ;
  13. public ValuesController(ICapPublisher producer, AppDbContext dbContext)
  14. {
  15. _producer = producer;
  16. _dbContext = dbContext;
  17. }
  18. [Route("/")]
  19. public IActionResult Index()
  20. {
  21. return Ok();
  22. }
  23. public string ServerPath => ((IHostingEnvironment)HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath;
  24. [CapSubscribe("zzwl.topic.finace.callBack", Group = "test")]
  25. public void KafkaTest(Person person)
  26. {
  27. Console.WriteLine(DateTime.Now);
  28. }
  29. [Route("~/send")]
  30. public async Task<IActionResult> SendTopic()
  31. {
  32. using (var trans = _dbContext.Database.BeginTransaction())
  33. {
  34. await _producer.PublishAsync("zzwl.topic.finace.callBack","");
  35. trans.Commit();
  36. }
  37. return Ok();
  38. }
  39. public class Person
  40. {
  41. public string Name { get; set; }
  42. public int Age { get; set; }
  43. }
  44. }
  45. }