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.

ValuesController.cs 1.3 KiB

7 年之前
7 年之前
7 年之前
7 年之前
7 年之前
7 年之前
7 年之前
7 年之前
7 年之前
1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Cap.Consistency.Consumer;
  6. using Cap.Consistency.Kafka;
  7. using Cap.Consistency.Producer;
  8. using Microsoft.AspNetCore.Mvc;
  9. namespace Sample.Kafka.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. public class ValuesController : Controller, IConsumerService
  13. {
  14. private readonly IProducerClient _producer;
  15. public ValuesController(IProducerClient producer) {
  16. _producer = producer;
  17. }
  18. [Route("/")]
  19. public IActionResult Index() {
  20. return Ok();
  21. }
  22. [KafkaTopic("zzwl.topic.finace.callBack", IsOneWay = true, GroupOrExchange = "test")]
  23. [NonAction]
  24. public void KafkaTest() {
  25. Console.WriteLine("kafka test invoked");
  26. }
  27. [Route("~/send")]
  28. public async Task<IActionResult> SendTopic() {
  29. await _producer.SendAsync("zzwl.topic.finace.callBack", "{\"msgBody\":\"{\\\"dealno\\\":null,\\\"businesstype\\\":\\\"1\\\",\\\"serialno\\\":\\\"435ldfhj345\\\",\\\"bankno\\\":\\\"650001\\\",\\\"amt\\\":20.0,\\\"virtualstatus\\\":1,\\\"paystatus\\\":1}\",\"callbackTopicName\":\"zzwl.topic.finace.callBack\",\"createId\":null,\"retryLimit\":0}");
  30. return Ok();
  31. }
  32. }
  33. }