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.

general.md 3.5 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # General
  2. CAP needs to use storage media with persistence capabilities to store event messages in databases or other NoSql facilities. CAP uses this approach to deal with loss of messages in all environments or network anomalies. Reliability of messages is the cornerstone of distributed transactions, so messages cannot be lost under any circumstances.
  3. ## Persistence
  4. ### Before sent
  5. Before message enters the message queue, CAP uses the local database table to persist the message, which ensures that the message is not lost when the message queue is abnormal or a network error occurs.
  6. To ensure the reliability of this mechanism, CAP uses the same database transactions as the business code to ensure that business operations and CAP messages are consistent in the persistence process. That is to say, in the process of message persistence, the database will be rolled back when any one of the exceptions occurs.
  7. ### After sent
  8. After the message enters the message queue, CAP will start the persistence function of the message queue. We need to explain how CAP message is persisted in RabbitMQ and Kafka.
  9. For message persistence in RabbitMQ, CAP uses a consumer queue with message persistence, but there may be exceptions here.
  10. !!! info "Ready for production?"
  11. By default, queues registered by CAP in RabbitMQ are persistent. When used in a production environment, we recommend that you start all consumers once to create the queues with persistence, which ensures that all queues are created before the message is sent.
  12. Since Kafka is born with message persistence using files, Kafka will ensure that messages are properly persisted without loss after the message enters Kafka.
  13. ## Storage
  14. After CAP is started, two tables are generated in used storage, by default the name is `Cap.Published` and `Cap.Received`.
  15. ### Storage Data Structure
  16. Table structure of **Published** :
  17. NAME | DESCRIPTION | TYPE
  18. :---|:---|:---
  19. Id | Message Id | int
  20. Version | Message Version | string
  21. Name | Topic Name | string
  22. Content | Json Content | string
  23. Added | Added Time | DateTime
  24. ExpiresAt | Expire time | DateTime
  25. Retries | Retry times | int
  26. StatusName | Status Name | string
  27. Table structure of **Received** :
  28. NAME | DESCRIPTION | TYPE
  29. :---|:---|:---
  30. Id | Message Id | int
  31. Version | Message Version | string
  32. Name | Topic Name | string
  33. Group | Group Name | string
  34. Content | Json Content | string
  35. Added | Added Time | DateTime
  36. ExpiresAt | Expire time | DateTime
  37. Retries | Retry times | int
  38. StatusName | Status Name | string
  39. ### Wapper Object
  40. When CAP sends a message, it will store original message object in a second package in the `Content` field.
  41. The following is the **Wapper Object** data structure of Content field.
  42. NAME | DESCRIPTION | TYPE
  43. :---|:---|:---
  44. Id | Message Id | string
  45. Timestamp | Message created time | string
  46. Content | Message content | string
  47. CallbackName | Consumer callback topic name | string
  48. The `Id` field is generate using the mongo [objectid algorithm](https://www.mongodb.com/blog/post/generating-globally-unique-identifiers-for-use-with-mongodb).
  49. ## Community-supported extensions
  50. Thanks to the community for supporting CAP, the following is the implementation of community-supported storage
  51. * SQLite ([@colinin](https://github.com/colinin)) :https://github.com/colinin/DotNetCore.CAP.Sqlite
  52. * LiteDB ([@maikebing](https://github.com/maikebing)) :https://github.com/maikebing/CAP.Extensions
  53. * SQLite & Oracle ([@cocosip](https://github.com/cocosip)) :https://github.com/cocosip/CAP-Extensions