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

5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
5 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Quick Start
  2. Learn how to build a microservices event bus architecture using CAP, which offers advantages over direct integration of message queues, and what out-of-the-box features it provides.
  3. ## Installation
  4. ```powershell
  5. PM> Install-Package DotNetCore.CAP
  6. ```
  7. ## Integrated in Asp.Net Core
  8. For quick start, we use memory-based event storage and message transport.
  9. ```powershell
  10. PM> Install-Package DotNetCore.CAP.InMemoryStorage
  11. PM> Install-Package Savorboard.CAP.InMemoryMessageQueue
  12. ```
  13. In `Startup.cs` ,add the following configuration:
  14. ```c#
  15. public void ConfigureServices(IServiceCollection services)
  16. {
  17. services.AddCap(x =>
  18. {
  19. x.UseInMemoryStorage();
  20. x.UseInMemoryMessageQueue();
  21. });
  22. }
  23. ```
  24. ## Publish Message
  25. ```c#
  26. public class PublishController : Controller
  27. {
  28. [Route("~/send")]
  29. public IActionResult SendMessage([FromService]ICapPublisher capBus)
  30. {
  31. capBus.Publish("test.show.time", DateTime.Now);
  32. return Ok();
  33. }
  34. }
  35. ```
  36. ## Process Message
  37. ```C#
  38. public class ConsumerController : Controller
  39. {
  40. [NonAction]
  41. [CapSubscribe("test.show.time")]
  42. public void ReceiveMessage(DateTime time)
  43. {
  44. Console.WriteLine("message time is:" + time);
  45. }
  46. }
  47. ```
  48. ## Summary
  49. One of the most powerful advantages of asynchronous messaging over direct integrated message queues is reliability, where failures in one part of the system do not propagate or cause the entire system to crash. Messages are stored inside the CAP to ensure the reliability of the message, and strategies such as retry are used to achieve the final consistency of data between services.