{"id":7218,"date":"2024-04-11T09:01:01","date_gmt":"2024-04-11T01:01:01","guid":{"rendered":""},"modified":"2024-04-11T09:01:01","modified_gmt":"2024-04-11T01:01:01","slug":"\u4ece\u6a2a\u5207\u5230\u7eb5\u5207\uff0c\u67b6\u6784\u6a21\u5f0fCQRS\uff0c\u63d0\u9ad8\u7cfb\u7edf\u8fdb\u5316\u80fd\u529b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7218.html","title":{"rendered":"\u4ece\u6a2a\u5207\u5230\u7eb5\u5207\uff0c\u67b6\u6784\u6a21\u5f0fCQRS\uff0c\u63d0\u9ad8\u7cfb\u7edf\u8fdb\u5316\u80fd\u529b"},"content":{"rendered":"
\u66fe\u51e0\u4f55\u65f6\uff0c\u4f60\u662f\u5426\u7591\u60d1\u4e8eVO\u3001PO\u3001DTO\u3001BO\u3001POJO\u3001Entity\u3001MODEL\u7684\u533a\u522b\uff1f<\/p>\n
\u4f60\u662f\u5426\u6709\u8fc7\u7591\u95ee\uff0c\u4e3a\u4ec0\u4e48Java\u91cc\u6709\u8fd9\u4e48\u591a\u7684\u4ee5O\u4e3a\u540d\u79f0\u7ed3\u5c3e\u7684\u5bf9\u8c61\uff1f\uff01<\/p>\n
\u4f60\u662f\u5426\u4e5f\u538c\u5026\u4e86\u7f16\u5199\u4ece\u8fd9\u4e2aO\u5bf9\u8c61\u5230\u90a3\u4e2aO\u5bf9\u8c61\u4e4b\u95f4\u7684\u8f6c\u6362\u4ee3\u7801\uff1f\uff01<\/p>\n
\u4f60\u6709\u6ca1\u6709\u60f3\u8fc7\uff0c\u8fd9\u4e00\u5207\u7684\u6839\u6e90\u5728\u54ea\u91cc\u5462\uff1f\u6709\u6ca1\u6709\u529e\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f<\/p>\n
\u672c\u6587\u8bd5\u56fe\u7ed9\u4f60\u7b54\u6848\uff01<\/p>\n
\u5728\u67b6\u6784\u98ce\u683c\uff1a\u4e07\u91d1\u6cb9CS\u4e0e\u5206\u5c42\u4e00\u6587\u4e2d\u63d0\u5230\uff0c\u5206\u5c42\u67b6\u6784\u662f\u4e2a\u4e07\u91d1\u6cb9\u67b6\u6784\uff0c\u5f53\u4f60\u65e0\u6cd5\u786e\u5b9a\u8be5\u4f7f\u7528\u54ea\u79cd\u67b6\u6784\u98ce\u683c\u7684\u65f6\u5019\uff0c\u90a3\u4e48\u53ef\u4ee5\u5148\u4f7f\u7528\u5206\u5c42\u67b6\u6784\u3002\u800c\u5b9e\u9645\u4e0a\u786e\u5b9e\u662f\u8fd9\u6837\uff0c\u5927\u90e8\u5206\u7684\u5e94\u7528\u90fd\u91c7\u7528\u4e86\u5206\u5c42\u67b6\u6784\uff0c\u7279\u522b\u662fweb\u5e94\u7528\u3002<\/p>\n
\u4ee5\u6700\u7b80\u5355\u7684\u4e09\u5c42\u67b6\u6784\u6765\u8bf4\uff1a<\/p>\n
\u5c55\u793a\u5c42\uff1a\u5c55\u793a\u6570\u636e\u7ed9\u7528\u6237<\/p>\n<\/li>\n
\u903b\u8f91\u5c42\uff1a\u5904\u7406\u4e1a\u52a1\u903b\u8f91<\/p>\n<\/li>\n
\u6301\u4e45\u5c42\uff1a\u6301\u4e45\u5316\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n
\u6bcf\u4e00\u5c42\u90fd\u8d1f\u8d23\u5404\u81ea\u7684\u4efb\u52a1\u3001\u804c\u8d23\u5355\u4e00\uff0c\u5f00\u53d1\u4e5f\u5c31\u76f8\u5bf9\u7b80\u5355\u3002\u6bcf\u4e00\u5c42\u76f8\u5bf9\u72ec\u7acb\uff0c\u6240\u4ee5\u90fd\u80fd\u591f\u72ec\u7acb\u8fdb\u5316\uff0c\u8fd9\u662f\u5206\u5c42\u67b6\u6784\u6240\u5ba3\u79f0\u7684\u4f18\u52bf\uff01\u4e5f\u662f\u5176\u300c\u539f\u7f6a\u300d\uff01<\/p>\n
\u5206\u5c42\u67b6\u6784\u867d\u7136\u5c06\u7cfb\u7edf\u6309\u5c42\u8fdb\u884c\u5212\u5206\uff0c\u4f46\u662f\u5c42\u4e0e\u5c42\u4e4b\u95f4\u8fd8\u662f\u9700\u8981\u8fdb\u884c\u4ea4\u4e92\u7684\u3002\u4ea4\u4e92\u5c31\u9700\u8981\u6709\u63a5\u53e3\u6216\u534f\u8bae\u4ee5\u53ca\u4f20\u8f93\u7684\u6570\u636e\u3002<\/p>\n
\u5bf9\u4e8e\u5916\u90e8\u8c03\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528TCP\u3001HTTP\u3001RPC\u3001WebService\u7b49\u65b9\u5f0f\u6765\u8fdb\u884c\u901a\u4fe1\uff1b\u800c\u5bf9\u4e8e\u5185\u90e8\u4ea4\u4e92\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u65b9\u6cd5\u8c03\u7528\uff0c\u4f7f\u7528\u63a5\u53e3\u6765\u8fdb\u884c\u89e3\u8026\u3002<\/p>\n
\u4f46\u662f\u4f20\u8f93\u7684\u6570\u636e\u7ed3\u6784\u8be5\u5982\u4f55\u5b9a\u5462\uff1f<\/p>\n
\u7b2c\u4e00\u79cd\u65b9\u5f0f\u662f\u76f4\u63a5\u4f7f\u7528\u57fa\u7840\u6570\u636e\u7ed3\u6784\uff0c\u6bd4\u5982Map\uff1f\u8fd9\u6709\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n<\/li>\n
\u6ca1\u6709\u4ee3\u7801\u63d0\u793a\uff0c\u5305\u62ecIDE\u5c42\u9762\u7684\u63d0\u793a\u4ee5\u53ca\u4e1a\u52a1\u5c42\u9762\u7684\u5b57\u6bb5\u63d0\u793a\uff0c\u624b\u8bef\u7684\u51e0\u7387\u8f83\u5927\u3002\u5c06\u7f16\u8bd1\u671f\u7684\u9519\u8bef\u5ef6\u540e\u5230\u4e86\u8fd0\u884c\u671f\uff0c\u964d\u4f4e\u4e86\u5f00\u53d1\u6548\u7387<\/p>\n<\/li>\n
\u6ca1\u6709\u8f83\u5b8c\u5907\u7684\u57fa\u7840\u8bbe\u65bd\uff0c\u4f8b\u5982\u57fa\u4e8e\u6ce8\u89e3\u7684\u5b57\u6bb5\u6821\u9a8c<\/p>\n<\/li>\n
\u6027\u80fd\u76f8\u5bf9\u5bf9\u8c61\u4f1a\u5dee\u4e00\u70b9<\/p>\n<\/li>\n
\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u662f\u4f7f\u7528\u4e00\u4e2a\u5bf9\u8c61\u8fdb\u884c\u4f20\u9012\uff0c\u4f8b\u5982ActiveRecord\u6216\u8005\u76f4\u63a5\u4f7f\u7528Model\u3002\u4f46\u662f\u8fd9\u4f1a\u4f7f\u5404\u5c42\u5f3a\u8026\u5408\uff0c\u4f7f\u5f97\u5206\u5c42\u67b6\u6784\u7684\u4f18\u52bf\u6d88\u5931\u3002\u7531\u4e8e\u6bcf\u5c42\u7684\u8fdb\u5316\u901f\u5ea6\u4e0d\u540c\uff1a\u6301\u4e45\u5c42\u76f8\u5bf9\u6bd4\u8f83\u7a33\u5b9a\uff1b\u903b\u8f91\u5c42\u53ef\u80fd\u9700\u8981\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u7684\u4e0d\u540c\u800c\u8fdb\u884c\u8c03\u6574\uff0c\u4f8b\u5982\u6253\u6298\u7b56\u7565\uff1b\u800c\u5c55\u793a\u5c42\u53ef\u80fd\u9700\u8981\u8fc7\u4e00\u6bb5\u65f6\u95f4\u8c03\u6574\uff0c\u907f\u514d\u5ba1\u7f8e\u75b2\u52b3\u3002\u5176\u4e2d\u4e00\u5c42\u5bf9\u4f20\u8f93\u5bf9\u8c61\u7684\u8c03\u6574\u90fd\u53ef\u80fd\u5bfc\u81f4\u5176\u5b83\u5c42\u8ddf\u7740\u4e00\u8d77\u4fee\u6539\u3002<\/p>\n<\/li>\n
\u7b2c\u4e09\u79cd\u65b9\u5f0f\u5c31\u662f\u4e0a\u9762\u8bf4\u7684\u4f7f\u7528\u5404\u79cd\u4f20\u8f93\u5bf9\u8c61\uff1a\u5404\u5c42\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u8f93\u4f7f\u7528\u72ec\u7acb\u7684\u4f20\u8f93\u5bf9\u8c61\uff0c\u4f7f\u5f97\u5404\u5c42\u677e\u8026\u5408\u3002\u4f46\u662f\u589e\u52a0\u4e86\u5404\u79cd\u4f20\u8f93\u5bf9\u8c61\u4ee5\u53ca\u8f6c\u6362\u4ee3\u7801\u3002\u540c\u65f6\u8f6c\u6362\u4e5f\u6d88\u8017\u4e86\u90e8\u5206\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n
\u5404\u5c42\u7684\u72ec\u7acb\u8fdb\u5316\uff0c\u5bfc\u81f4\u4e86\u4ea4\u4e92\u7684\u989d\u5916\u64cd\u4f5c\uff01\u8fd9\u5c31\u662f\u5206\u5c42\u67b6\u6784\u7684\u300c\u539f\u7f6a\u300d\uff01\u4e5f\u662f\u9700\u8981\u8fd9\u4e48\u591a\u4f20\u8f93\u5bf9\u8c61\u7684\u5176\u4e2d\u4e00\u4e2a\u539f\u56e0\uff01<\/p>\n
\u800c\u53e6\u5916\u4e00\u4e2a\u539f\u56e0\u662f\u8868\u73b0\u529b\u5dee\u5f02\uff01<\/p>\n
\u5728\u9886\u57df\u8bbe\u8ba1\uff1a\u805a\u5408\u4e0e\u805a\u5408\u6839\u804a\u5230\u4e86\u8868\u73b0\u529b\u95ee\u9898\uff0c\u300c\u6570\u636e\u8bbe\u8ba1\u300d\u7684\u8868\u73b0\u529b\u8981\u5f31\u4e8e\u300c\u5bf9\u8c61\u8bbe\u8ba1\u300d\uff01\u76f8\u5bf9\u5e94\u7684\uff0c\u5176\u5b9e\u300c\u6570\u636e\u5c55\u73b0\u300d\u7684\u8868\u73b0\u529b\u4e5f\u662f\u5f31\u4e8e\u300c\u5bf9\u8c61\u8bbe\u8ba1\u300d\u7684\uff01<\/p>\n
\u6211\u4eec\u8fd8\u662f\u4ee5\u8ba2\u5355\u6765\u4e3e\u4f8b\uff01\u5047\u8bbe\u6211\u4e0b\u5355\u8d2d\u4e70\u4e86\u591a\u4e2a\u5546\u54c1\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a\u8ba2\u5355\u5305\u542b\u4e86\u591a\u4e2a\u660e\u7ec6\u3002\u90a3\u4e48\u8ba2\u5355\u4e0e\u8ba2\u5355\u660e\u7ec6\u7684\u8fd9\u5c42\u5173\u7cfb\u5728\u300c\u6301\u4e45\u5c42\u300d\u662f\u901a\u8fc7\u4e3b\u952e\u6765\u8868\u73b0\u7684\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u8ba2\u5355\u660e\u7ec6\u5305\u542b\u4e86\u8ba2\u5355\u7684\u4e3b\u952e\uff0c\u8868\u793a\u54ea\u4e9b\u8ba2\u5355\u660e\u7ec6\u662f\u5c5e\u4e8e\u54ea\u4e2a\u8ba2\u5355\u7684\u3002<\/p>\n
\u800c\u8fd9\u5c42\u5173\u7cfb\u5728\u300c\u903b\u8f91\u5c42\u300d\u662f\u901a\u8fc7\u5bf9\u8c61\u5f15\u7528\u6765\u8868\u73b0\u7684\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u8ba2\u5355\u5bf9\u8c61\u4e2d\u6301\u6709\u4e86\u6307\u5411\u8ba2\u5355\u660e\u7ec6\u5217\u8868\u7684\u5f15\u7528\u3002<\/p>\n
\u800c\u5230\u4e86\u300c\u5c55\u793a\u5c42\u300d\uff0c\u8ba2\u5355\u548c\u8ba2\u5355\u8be6\u60c5\u4e4b\u95f4\u7684\u5173\u7cfb\u5c31\u5b8c\u5168\u9760\u5c55\u793a\u65b9\u5f0f\u6765\u8868\u73b0\u4e86\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u5982\u679c\u4f60\u4e0d\u4e86\u89e3\u4e1a\u52a1\uff0c\u5149\u770b\u4ee3\u7801\uff0c\u662f\u770b\u4e0d\u51fa\u8ba2\u5355\u4e0e\u8ba2\u5355\u660e\u7ec6\u4e4b\u95f4\u7684\u5173\u7cfb\u7684\u3002\u4e0a\u9762\u53ea\u662f\u7eaf\u7cb9\u7684\u5c55\u793a\u4e86\u8ba2\u5355\u660e\u7ec6\u5728\u8ba2\u5355\u4fe1\u606f\u7684\u4e0b\u9762\u3002<\/p>\n
\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6211\u4eec\u8bbf\u95ee\u9875\u9762\u7684\u65f6\u5019\uff0c\u8bf7\u6c42\u4ece\u300c\u6301\u4e45\u5c42\u300d\u5c06\u6241\u5e73\u7684\u6570\u636e\u67e5\u8be2\u5230\u4e86\u300c\u903b\u8f91\u5c42\u300d\uff0c\u7ec4\u88c5\u6210\u4e86\u7ed3\u6784\u5316\u7684\u5bf9\u8c61\uff0c\u6700\u540e\u88ab\u4f20\u9012\u5230\u4e86\u300c\u5c55\u73b0\u5c42\u300d\uff0c\u53c8\u88ab\u62cd\u6241\u4e86\u5c55\u793a\u5728\u6211\u4eec\u9762\u524d\u3002<\/p>\n
\u7531\u4e8e\u6bcf\u5c42\u8868\u73b0\u5f62\u5f0f\u7684\u4e0d\u540c\uff0c\u4ea6\u5bfc\u81f4\u4e86\u9700\u8981\u6570\u636e\u4f20\u8f93\u5bf9\u8c61\u3002<\/p>\n
\u65e2\u7136\u6a2a\u5411\u5c01\u5c42\u4e0d\u53ef\u907f\u514d\u7684\u9700\u8981\u6570\u636e\u4f20\u8f93\u5bf9\u8c61\u6765\u89e3\u8026\u5404\u5c42\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u90a3\u6211\u4eec\u662f\u5426\u4e0d\u4f7f\u7528\u6a2a\u5411\u5c01\u5c42\uff0c\u800c\u4f7f\u7528\u7eb5\u5411\u5207\u5206\u5462\uff1f\u8fd9\u5c31\u662fCQRS\u67b6\u6784\u6a21\u5f0f\uff01<\/p>\n
CQRS\u901a\u8fc7\u5bf9\u7cfb\u7edf\u8fdb\u884c\u7eb5\u5411\u5207\u5206\uff1a\u5c06\u300c\u6570\u636e\u8bfb\u300d\u548c\u300c\u6570\u636e\u5199\u300d\u5206\u79bb\u5f00\uff0c\u4f7f\u5f97\u6570\u636e\u8bfb\u5199\u72ec\u7acb\u8fdb\u5316\uff0c\u6765\u89e3\u51b3\u6570\u636e\u663e\u793a\u590d\u6742\u6027\u95ee\u9898\u3002<\/p>\n
CQRS\u67b6\u6784\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n
\u5ba2\u6237\u7aef\u6784\u5efa\u547d\u4ee4\u5bf9\u8c61CommandModel\u53d1\u9001\u7ed9\u670d\u52a1\u7aef<\/p>\n<\/li>\n
\u670d\u52a1\u7aef\u901a\u8fc7\u547d\u4ee4\u603b\u7ebfCommandBus\u63a5\u6536\u5230\u547d\u4ee4\uff0c\u59d4\u6258\u7ed9\u5bf9\u5e94\u7684CommandHandler\u53bb\u5904\u7406<\/p>\n<\/li>\n
CommandHandler\u5904\u7406\u5b8c\u4e1a\u52a1\uff0c\u5c06\u6b64\u547d\u4ee4\u901a\u8fc7Repository\u8fdb\u884c\u6301\u4e45\u5316\uff08\u4e0d\u4e00\u5b9a\u662fDB\uff0c\u4e0b\u9762\u4f1a\u5177\u4f53\u8bf4\uff09<\/p>\n<\/li>\n
\u540c\u65f6\u4f1a\u6784\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7684\u4e8b\u4ef6Event\uff0c\u6dfb\u52a0\u5230\u4e8b\u4ef6\u603b\u7ebfEventBus\u4e2d\uff08\u8be5\u4e8b\u4ef6\u53ef\u4ee5\u662f\u540c\u6b65\u4e8b\u4ef6\u3001\u4e5f\u53ef\u4ee5\u662f\u5f02\u6b65\u4e8b\u4ef6\uff09<\/p>\n<\/li>\n
\u5bf9\u5e94\u7684EventHandler\u4f1a\u5bf9\u8be5\u4e8b\u4ef6\u8fdb\u884c\u5904\u7406\uff0c\u6bd4\u5982\u5904\u7406\u6210\u4fbf\u4e8e\u5c55\u793a\u7684\u6a21\u578b\uff0c\u5b58\u50a8\u5230ReadDB\u4e2d<\/p>\n<\/li>\n
\u5ba2\u6237\u7aef\u53ef\u4ee5\u5bf9\u670d\u52a1\u7aef\u53d1\u9001\u67e5\u8be2\uff0c\u670d\u52a1\u7aef\u76f4\u63a5\u4eceReadDB\u4e2d\u83b7\u53d6\u6570\u636e\uff0c\u6784\u5efaQueryModel\u8fd4\u56de<\/p>\n<\/li>\n<\/ul>\n
\u8fd9\u53c8\u4ec0\u4e48\u4f18\u52bf\u5462\uff1f<\/p>\n
\u9996\u5148\uff0c\u73b0\u5728\u53ea\u9700\u8981CommandModel\u548cQueryModel\u4e24\u4e2a\u6570\u636e\u4f20\u8f93\u5bf9\u8c61\uff0c\u4e0d\u518d\u9700\u8981\u90a3\u4e48\u591a\u7684\u4e2d\u95f4\u4f20\u8f93\u5bf9\u8c61\u4e86\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u7701\u7565\u4e86\u8fd9\u90e8\u5206\u7684\u4ee3\u7801\u548c\u6027\u80fd\u635f\u8017\u3002<\/p>\n<\/li>\n
\u5176\u6b21\uff0c\u8bfb\u5199\u5206\u79bb\uff0c\u53ef\u4ee5\u5bf9\u8bfb\u5199\u8fdb\u884c\u4e13\u95e8\u7684\u4f18\u5316\u3002<\/p>\n<\/li>\n
\u6700\u540e\uff0c\u5c31\u662f\u53ef\u4ee5\u4e8b\u4ef6\u6eaf\u6e90EventSourcing\u3002\u8fd9\u4e2a\u6211\u4eec\u6765\u8be6\u7ec6\u8bf4\u4e00\u4e0b\u3002<\/p>\n<\/li>\n<\/ul>\n
\u6211\u4eec\u4ee5\u8ba2\u5355\u4fdd\u5b58\u548c\u5c55\u793a\u6d41\u7a0b\u6765\u8be6\u7ec6\u7684\u770b\u4e00\u4e0bCQRS\u7684\u4f18\u52bf\uff01<\/p>\n
\u5bf9\u4e8e\u666e\u901a\u5206\u5c42\u67b6\u6784\u6765\u8bf4\uff0c\u5728\u4fdd\u5b58\u8ba2\u5355\u65f6\u9700\u8981\u4e00\u4e2aDTO\u7528\u4e8e\u5b58\u50a8\u76f8\u5173\u4fe1\u606f\uff0c\u7136\u540e\u8f6c\u6210\u591a\u4e2a\u5bf9\u5e94\u7684Model\u6765\u8fdb\u884c\u6301\u4e45\u5316\uff1b\u800c\u67e5\u8be2\u8ba2\u5355\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u67e5\u8be2\u51fa\u591a\u4e2aModel\uff0c\u7136\u540e\u7ec4\u88c5\u6210\u53e6\u4e00\u4e2aDTO\u6765\u5b58\u50a8\u67e5\u8be2\u7684\u4fe1\u606f\uff0c\u56e0\u4e3a\u5c55\u793a\u7684\u65f6\u5019\u53ef\u80fd\u8981\u5c55\u793a\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u4e70\u5bb6\u548c\u5356\u5bb6\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n
\u540c\u65f6\u7531\u4e8e\u6570\u636e\u90fd\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u4e14\u8868\u7ed3\u6784\u4e0eModel\u662f\u5bf9\u5e94\u7684\uff0c\u4f60\u80fd\u505a\u7684\u4f18\u5316\u5c31\u662f\u6570\u636e\u5e93\u76f8\u5173\u7684\u4f18\u5316\u624b\u6bb5\u3002<\/p>\n
\u800c\u5728CQRS\u4e2d\uff0c\u6570\u636e\u5e93\u88ab\u5206\u6210\u4e86\u8bfb\u5e93\u548c\u5199\u5e93\u3002\u90a3\u5b58\u5728\u8bfb\u5e93\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u5c31\u53ef\u4ee5\u5b8c\u5168\u6309\u7167\u5c55\u793a\u903b\u8f91\u6765\u4f18\u5316\uff0c\u6bd4\u5982\uff1a\u6211\u53ef\u4ee5\u6709\u4e00\u5f20\u8ba2\u5355\u5c55\u793a\u8868\uff0c\u8868\u4e2d\u5305\u542b\u4e86\u4e70\u5bb6\u4fe1\u606f\u548c\u5356\u5bb6\u4fe1\u606f\u3002\u5728\u5c55\u793a\u65f6\uff0c\u76f4\u63a5\u67e5\u8be2\u8fd9\u5f20\u8868\u5c31\u53ef\u4ee5\u4e86\uff0c\u4e0d\u9700\u8981\u548c\u7528\u6237\u8868\u8fdb\u884c\u5173\u8054\u67e5\u8be2\uff0c\u63d0\u9ad8\u4e86\u6570\u636e\u8bfb\u6027\u80fd\u3002<\/p>\n
\u800c\u5bf9\u4e8e\u6570\u636e\u6301\u4e45\u5316\u6765\u8bf4\uff0c\u5c31\u4e0d\u9700\u8981\u8003\u8651\u6570\u636e\u5c55\u793a\u4e86\uff0c\u53ea\u8981\u63d0\u9ad8\u6301\u4e45\u5316\u6027\u80fd\u5c31\u53ef\u4ee5\u4e86\u3002\u4f8b\u5982\u4e0d\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u800c\u4f7f\u7528\u987a\u5e8f\u5199\u5165\u7684\u6587\u4ef6\u65b9\u5f0f\u3002\u540c\u65f6\u4e5f\u4e0d\u4e00\u5b9a\u8981\u5b58\u50a8\u6570\u636e\u672c\u8eab\uff0c\u8f6c\u800c\u5b58\u50a8\u4e8b\u4ef6\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u4ef6\u91cd\u6f14\uff0c\u8fd9\u5c31\u662f\u4e8b\u4ef6\u6eaf\u6e90\u3002<\/p>\n
\u5728\u9886\u57df\u8bbe\u8ba1\uff1aEntity\u4e0eVO\u4e00\u6587\u4e2d\uff0c\u63d0\u5230\u4e86\u300c\u72b6\u6001\u300d\uff01<\/p>\n
\u4e00\u822c\u6211\u4eec\u5904\u7406\u72b6\u6001\u90fd\u662f\u76f4\u63a5\u53bb\u4fee\u6539\u5b83\uff0c\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u90a3\u4e48\u8bf7\u95ee\uff0c\u8fd9\u4e2a\u5f00\u5173\u521a\u624d\u7ecf\u5386\u4e86\u4ec0\u4e48\uff1f\uff01\u8fd9\u662f\u5178\u578b\u7684ABA\u95ee\u9898\uff0c\u5373\u4f60\u53ea\u77e5\u9053\u8fd9\u4e2a\u5f00\u5173\u76ee\u524d\u7684\u72b6\u6001\uff0c\u4f46\u662f\u5b83\u66fe\u7ecf\u6709\u6ca1\u6709\u5f00\u8fc7\u6216\u5173\u8fc7\uff0c\u4f60\u5c31\u65e0\u4ece\u5f97\u77e5\u4e86\u3002<\/p>\n
\u6211\u4eec\u5bf9\u6570\u636e\u7684\u5904\u7406\u4e5f\u662f\u8fd9\u6837\uff0c\u4f60\u53ea\u77e5\u9053\u5f53\u524d\u5b58\u5728\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u662f\u4ec0\u4e48\uff0c\u800c\u5b83\u66fe\u7ecf\u88ab\u4fee\u6539\u8fc7\u6ca1\u6709\uff1f\u88ab\u4fee\u6539\u6210\u8fc7\u4ec0\u4e48\uff0c\u4f60\u65e0\u4ece\u77e5\u6653\u3002<\/p>\n
\u56e0\u4e3a\u6211\u4eec\u5b58\u7684\u53ea\u662f\u300c\u5373\u65f6\u72b6\u6001\u300d\uff0c\u5373\u300c\u5feb\u7167\u300d\uff01<\/p>\n
\u4e8b\u4ef6\u6eaf\u6e90\u5b58\u50a8\u7684\u4e0d\u662f\u6570\u636e\u300c\u5feb\u7167\u300d\uff0c\u800c\u662f\u300c\u4e8b\u4ef6\u672c\u8eab\u300d\uff01\u5373\u5b83\u8bb0\u5f55\u4e86\u6240\u6709\u5bf9\u8be5\u6570\u636e\u7684\u4e8b\u4ef6\u3002<\/p>\n
\u5982\u679c\u4f60\u4e86\u89e3Redis\u7684\u6301\u4e45\u5316\u65b9\u6848\uff0c\u4f60\u5bf9\u4e8b\u4ef6\u6eaf\u6e90\u5c31\u4e00\u5b9a\u4e0d\u4f1a\u611f\u5230\u964c\u751f\u3002Redis\u6709\u4e24\u79cd\u6301\u4e45\u5316\u65b9\u5f0fRDB\u65b9\u5f0f\u548cAOF\u65b9\u5f0f\uff1a<\/p>\n
RDB\uff1a\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5185\uff0c\u6267\u884c\u6307\u5b9a\u6b21\u6570\u7684\u5199\u64cd\u4f5c\uff0c\u5219\u4f1a\u5c06\u5185\u5b58\u4e2d\u7684\u6570\u636e\u5199\u5165\u5230\u78c1\u76d8\u4e2d\u3002\u5bf9\u5f53\u524d\u6570\u636e\u5feb\u7167\u8fdb\u884c\u6301\u4e45\u5316<\/p>\n<\/li>\n
AOF\uff1a\u5c06\u6307\u4ee4\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e\u3002\u901a\u8fc7\u6307\u4ee4\u91cd\u6f14\u6765\u6062\u590d\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n
\u6211\u4eec\u4e00\u822c\u7684\u6301\u4e45\u5316\u65b9\u5f0f\u5b9e\u9645\u5bf9\u5e94\u7684\u5c31\u662fRedis\u7684RDB\u65b9\u5f0f\uff0c\u800c\u4e8b\u4ef6\u6eaf\u6e90\u5c31\u662fAOF\u65b9\u5f0f\u3002<\/p>\n
\u56de\u5230\u4e0a\u56fe\uff0c\u5728CQRS\u4e2d\uff0cWriteDB\u53ef\u4ee5\u901a\u8fc7\u7c7bAOF\u7684\u65b9\u5f0f\u6765\u5b58\u50a8\u547d\u4ee4\uff0c\u4e5f\u5c31\u662f\u4e8b\u4ef6\u6eaf\u6e90\u3002\u5f53\u9700\u8981\u5bf9ReadDB\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u6062\u590d\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u91cd\u6f14\u7684\u65b9\u5f0f\u6765\u6062\u590d\u3002<\/p>\n
\u4e0d\u8fc7\u4f60\u5e94\u8be5\u53d1\u73b0\u95ee\u9898\u4e86\uff0c\u547d\u4ee4\u91cd\u6f14\u7684\u65b9\u5f0f\u6027\u80fd\u4e0a\u6709\u95ee\u9898\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u53c2\u8003Redis\uff0c\u4f7f\u7528\u5feb\u7167+\u4e8b\u4ef6\u6eaf\u6e90\u7684\u65b9\u5f0f\u6765\u5b58\u50a8\u3002\u5373WriteDB\u4e2d\u5b58\u50a8\u4e8b\u4ef6\uff0c\u989d\u5916\u518d\u5b9a\u65f6\u5bf9\u6570\u636e\u8fdb\u884c\u5feb\u7167\u5907\u4efd\u3002\u6062\u590d\u6570\u636e\u65f6\u5148\u901a\u8fc7\u5feb\u7167\u5907\u4efd\u6062\u590d\uff0c\u518d\u4ece\u6307\u5b9a\u4f4d\u7f6e\u8fdb\u884c\u547d\u4ee4\u91cd\u6f14\uff0c\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n
\u8bfb\u5199\u5206\u79bb\u540e\uff0c\u5bfc\u81f4\u7684\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u8bfb\u5199\u4e00\u81f4\u6027\u3002\u5728\u539f\u6765\u7684\u5206\u5c42\u67b6\u6784\u4e2d\uff0c\u6570\u636e\u5199\u5165\u540e\u518d\u8bfb\u53d6\uff0c\u662f\u53ef\u4ee5\u7acb\u5373\u8bfb\u53d6\u5230\u5199\u5165\u7684\u6570\u636e\u7684\uff08\u4e8b\u52a1\u4fdd\u969c\uff09\u3002<\/p>\n
\u4f46\u662f\u8bfb\u5199\u5206\u79bb\u540e\uff0c\u8bfb\u5230\u7684\u6570\u636e\u4e0d\u4e00\u5b9a\u662f\u5199\u5165\u7684\u6700\u65b0\u6570\u636e\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u95ee\u9898\u5e76\u4e0d\u5927\u3002\u56e0\u4e3a\u5b9e\u9645\u4e0a\u4f60\u8bfb\u7684\u57fa\u672c\u4e0a\u90fd\u662f\u5386\u53f2\u6570\u636e\uff01\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8bf4\u5462\uff1f\u56e0\u4e3a\u4f60\u6ca1\u6cd5\u4fdd\u8bc1\u6570\u636e\u5728\u5c55\u73b0\u5230\u4f60\u9762\u524d\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6ca1\u6709\u65b0\u7684\u5199\u5165\u3002\u9664\u975e\u5c55\u793a\u662f\u57fa\u4e8e\u63a8\u9001\u673a\u5236\u7684\u3002<\/p>\n
\u4f46\u662f\u5bf9\u4e8e\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u4e0d\u80fd\u5bb9\u5fcd\u8fd9\u6837\u7684\u60c5\u51b5\u3002\u6709\u51e0\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n
\u4e34\u65f6\u6027\u7684\u663e\u793a\u5148\u524d\u63d0\u4ea4\u7ed9\u547d\u4ee4\u6a21\u578b\u7684\u53c2\u6570<\/p>\n<\/li>\n
\u5728\u9875\u9762\u5c55\u793a\u67e5\u8be2\u6a21\u578b\u7684\u65f6\u95f4<\/p>\n<\/li>\n
\u4f7f\u7528\u7c7b\u4f3cComet\u8fd9\u6837\u7684\u957f\u94fe\u63a5\u7684\u65b9\u5f0f\u6216\u8005\u4e8b\u4ef6\u6a21\u5f0f\u6765\u76d1\u542c\u6570\u636e<\/p>\n
<\/p>\n
\u53c2\u8003\u8d44\u6599<\/p>\n<\/li>\n
CQRS\uff1ahttps:\/\/martinfowler.com\/bliki\/CQRS.html<\/p>\n<\/li>\n
\u300a\u5b9e\u73b0\u9886\u57df\u9a71\u52a8\u8bbe\u8ba1\u300b<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u4ece\u6a2a\u5207\u5230\u7eb5\u5207\uff0c\u67b6\u6784\u6a21\u5f0fCQRS\uff0c\u63d0\u9ad8\u7cfb\u7edf\u8fdb\u5316\u80fd\u529b\u66fe\u51e0\u4f55\u65f6\uff0c\u4f60\u662f\u5426\u7591\u60d1\u4e8eVO\u3001PO\u3001DTO\u3001BO\u3001POJO\u3001Entity\u3001MODEL\u7684\u533a\u522b\uff1f\u4f60\u662f\u5426...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7218"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7218"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7218\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}