{"id":97459,"date":"2026-08-29T15:08:46","date_gmt":"2026-08-29T07:08:46","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97459.html"},"modified":"2026-08-29T15:08:46","modified_gmt":"2026-08-29T07:08:46","slug":"%e6%8a%98%e6%97%a7%e5%90%8c%e6%ad%a5%e6%b6%88%e8%b4%b9%e4%be%a7%e6%94%b9%e9%80%a0%ef%bc%9a%e6%a8%a1%e6%9d%bf%e6%96%b9%e6%b3%95%e6%8a%bd%e8%b1%a1%e4%b8%8e-upsert-%e5%b9%82%e7%ad%89%e7%9a%84%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97459.html","title":{"rendered":"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730"},"content":{"rendered":"<h3>\u4ece\u4e94\u79cd Handler \u590d\u5236\u7c98\u8d34\u8bf4\u8d77<\/h3>\n<p>\u8d22\u52a1\u670d\u52a1\u8981\u6d88\u8d39\u7684\u540c\u6b65\u4e8b\u4ef6\u4e0d\u6b62\u4e00\u79cd&#xff1a;\u6298\u65e7\u8ba1\u63d0\u660e\u7ec6\u7684 UPSERT\u3001\u6298\u65e7\u51b2\u9500\u7684 DELETE\u3001\u8d44\u4ea7\u5361\u7247\u4e3b\u6570\u636e\u53d8\u66f4\u3001\u5355\u636e\u72b6\u6001\u6d41\u8f6c\u3001\u671f\u672b\u7ed3\u8f6c\u6807\u5fd7\u3002\u7b2c\u4e00\u7248\u7684\u5b9e\u73b0\u662f\u4e94\u79cd\u4e8b\u4ef6\u4e94\u4e2a Handler&#xff0c;\u6bcf\u4e2a\u90fd\u81ea\u5df1\u5199\u4e00\u904d\u5b8c\u6574\u7684\u6d88\u8d39\u6d41\u7a0b\u3002<\/p>\n<p>\u5199\u5b8c\u56de\u5934\u770b&#xff0c;\u4e94\u4e2a\u7c7b\u51e0\u4e4e\u662f\u4e00\u4e2a\u6a21\u5b50\u523b\u51fa\u6765\u7684&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u4e94\u4e2a Handler \u91cc\u91cd\u590d\u51fa\u73b0\u4e94\u6b21\u7684\u6bb5\u843d<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">onMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">MessageExt<\/span> message<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">SyncEvent<\/span> event <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">parse<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">doBiz<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                       <span class=\"token comment\">\/\/ \u552f\u4e00\u4e0d\u540c\u7684\u5730\u65b9<\/span><br \/>\n        <span class=\"token function\">logProcessed<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">.<\/span><span class=\"token function\">getMsgId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">BizException<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">saveRetry<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">,<\/span> e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                <span class=\"token comment\">\/\/ \u843d\u91cd\u8bd5\u8868<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Exception<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        log<span class=\"token punctuation\">.<\/span><span class=\"token function\">error<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;unknown error&#034;<\/span><span class=\"token punctuation\">,<\/span> e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">RuntimeException<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u8ba9 MQ \u91cd\u8bd5<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u771f\u6b63\u7684\u4e1a\u52a1\u5dee\u5f02\u53ea\u6709 doBiz \u90a3\u5341\u51e0\u884c&#xff0c;\u5305\u88f9\u5b83\u7684\u5374\u662f\u4e94\u4efd\u5b8c\u5168\u76f8\u540c\u7684\u89e3\u6790\u3001\u5f02\u5e38\u5206\u6d41\u3001\u91cd\u8bd5\u767b\u8bb0\u4ee3\u7801\u3002\u8fd9\u79cd\u91cd\u590d\u7684\u4ee3\u4ef7\u4e0d\u662f\u884c\u6570\u2014\u2014\u662f\u53d1\u6563\u3002\u6539\u4e00\u6b21\u5e42\u7b49\u903b\u8f91\u8981\u6539\u4e94\u4e2a\u5730\u65b9&#xff0c;\u6709\u4e00\u6b21\u6539\u6f0f\u4e86\u4e00\u4e2a Handler&#xff0c;\u90a3\u4e2a\u7c7b\u578b\u7684\u4e8b\u4ef6\u5c31\u5728\u6ca1\u6709\u5e42\u7b49\u4fdd\u62a4\u7684\u72b6\u6001\u4e0b\u88f8\u5954\u4e86\u5c0f\u534a\u4e2a\u6708&#xff0c;\u76f4\u5230\u538b\u6d4b\u91cd\u653e\u624d\u66b4\u9732\u3002<\/p>\n<p>\u95ee\u9898\u4e0d\u662f\u4ee3\u7801\u5199\u5f97\u7cd9&#xff0c;\u662f\u6d41\u7a0b\u672c\u8eab\u6709&#034;\u9aa8\u67b6&#043;\u7ec6\u8282&#034;\u7684\u7ed3\u6784&#xff0c;\u800c\u4ee3\u7801\u6ca1\u6709\u8868\u8fbe\u8fd9\u4e2a\u7ed3\u6784\u3002\u8fd9\u6b63\u662f\u6a21\u677f\u65b9\u6cd5\u6a21\u5f0f\u7684\u7528\u6b66\u4e4b\u5730\u2014\u2014\u8bf4\u6765\u60ed\u6127&#xff0c;\u4e4b\u524d\u6574\u7406\u6a21\u677f\u65b9\u6cd5\u7684\u5b66\u4e60\u7b14\u8bb0\u65f6&#xff0c;\u6211\u5bf9\u5b83\u7684\u5370\u8c61\u4e00\u76f4\u505c\u7559\u5728&#034;abstract class \u7684\u6559\u79d1\u4e66\u7528\u6cd5&#034;&#xff0c;\u89c9\u5f97\u5e73\u6de1\u65e0\u5947\u3002\u771f\u5230\u4e94\u4e2a Handler \u5806\u5728\u773c\u524d\u7684\u65f6\u5019\u624d\u4f53\u4f1a\u5230&#xff0c;final \u9501\u4f4f\u7684\u4e0d\u662f\u4ee3\u7801&#xff0c;\u662f\u6d41\u7a0b\u7684\u8bed\u4e49\u3002<\/p>\n<h3>\u9aa8\u67b6&#xff1a;\u628a\u6d41\u7a0b\u8bed\u4e49\u9489\u8fdb\u7236\u7c7b<\/h3>\n<p>\u91cd\u6784\u540e\u7684\u62bd\u8c61\u957f\u8fd9\u6837&#xff08;\u7b80\u5316\u793a\u610f&#xff0c;\u7ec6\u8282\u6309\u771f\u5b9e\u5b9e\u73b0\u6838\u5bf9&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">abstract<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">AbstractDepreciationHandler<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">T<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">SyncHandler<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token comment\">\/** \u6a21\u677f\u65b9\u6cd5:\u9501\u6b7b\u6d88\u8d39\u9aa8\u67b6,\u5b50\u7c7b\u4e0d\u8bb8\u8986\u5199 *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">SyncResult<\/span> <span class=\"token function\">handle<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">SyncEvent<\/span> event<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">T<\/span> payload <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">parse<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ 1. \u89e3\u6790:\u5b50\u7c7b\u5404\u81ea\u7684\u53cd\u5e8f\u5217\u5316<\/span><br \/>\n        <span class=\"token function\">validate<\/span><span class=\"token punctuation\">(<\/span>payload<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                 <span class=\"token comment\">\/\/ 2. \u4e1a\u52a1\u6821\u9a8c:\u5b50\u7c7b\u5404\u81ea\u7684\u89c4\u5219<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> affected <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">doUpsert<\/span><span class=\"token punctuation\">(<\/span>payload<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ 3. \u5e42\u7b49\u843d\u5e93:\u5b50\u7c7b\u5dee\u5f02\u70b9<\/span><br \/>\n        <span class=\"token function\">postProcess<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">,<\/span> payload<span class=\"token punctuation\">,<\/span> affected<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ 4. \u5584\u540e:\u65e5\u5fd7\/\u76d1\u63a7\u57cb\u70b9<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token class-name\">SyncResult<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">ok<\/span><span class=\"token punctuation\">(<\/span>event<span class=\"token punctuation\">.<\/span><span class=\"token function\">getMsgId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> affected<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">abstract<\/span> <span class=\"token class-name\">T<\/span> <span class=\"token function\">parse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">SyncEvent<\/span> event<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">abstract<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">validate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">T<\/span> payload<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">abstract<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">doUpsert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">T<\/span> payload<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/** \u94a9\u5b50:\u9ed8\u8ba4\u7a7a\u5b9e\u73b0,\u786e\u6709\u5584\u540e\u9700\u6c42\u7684\u5b50\u7c7b\u518d\u8986\u5199 *\/<\/span><br \/>\n    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">postProcess<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">SyncEvent<\/span> event<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">T<\/span> payload<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> affected<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e94\u79cd\u4e8b\u4ef6\u6536\u655b\u6210\u4e94\u4e2a\u53ea\u5b9e\u73b0 parse \/ validate \/ doUpsert \u7684\u5b50\u7c7b\u3002\u89e3\u6790\u3001\u5f02\u5e38\u5206\u6d41\u3001\u91cd\u8bd5\u767b\u8bb0\u3001\u76d1\u63a7\u57cb\u70b9\u5168\u90e8\u4e0a\u6536\u5230\u7236\u7c7b\u2014\u2014\u4e0b\u4e00\u6b21\u6d41\u7a0b\u8c03\u6574\u53ea\u6539\u4e00\u5904&#xff0c;\u56e0\u4e3a\u6d41\u7a0b\u53ea\u5b58\u5728\u4e00\u4efd\u3002<\/p>\n<p>\u6709\u4e00\u4e2a\u8bbe\u8ba1\u51b3\u7b56\u503c\u5f97\u5355\u72ec\u8bf4&#xff1a;handle() \u4e3a\u4ec0\u4e48\u662f final&#xff1f;\u56e0\u4e3a\u9aa8\u67b6\u4e00\u65e6\u5141\u8bb8\u5b50\u7c7b\u8986\u5199&#xff0c;&#034;\u4e94\u4efd\u76f8\u540c\u4ee3\u7801&#034;\u5c31\u4f1a\u4ee5&#034;\u4e94\u4efd\u5fae\u5999\u4e0d\u540c\u4ee3\u7801&#034;\u7684\u5f62\u5f0f\u5377\u571f\u91cd\u6765\u2014\u2014\u8986\u5199\u6b63\u662f\u53d1\u6563\u7684\u5f00\u59cb\u3002\u9ed8\u8ba4\u7a7a\u7684 postProcess \u94a9\u5b50\u662f\u7ed9\u786e\u6709\u5584\u540e\u9700\u6c42\u7684\u5b50\u7c7b\u7559\u7684\u53e3\u5b50&#xff0c;\u4f46\u94a9\u5b50\u6211\u4eec\u63a7\u5236\u5728\u4e24\u4e2a\u4ee5\u5185&#xff0c;\u518d\u591a\u5c31\u8bf4\u660e\u8fd9\u4e2a\u5b50\u7c7b\u7684\u6d41\u7a0b\u672c\u8d28\u4e0d\u540c&#xff0c;\u8be5\u62c6\u51fa\u53bb\u800c\u4e0d\u662f\u7ee7\u7eed\u6253\u6d1e\u3002<\/p>\n<p>\u987a\u5e26\u628a\u548c\u7b56\u7565\u6a21\u5f0f\u7684\u8fa8\u6790\u5199\u4e0b\u6765&#xff0c;\u56e0\u4e3a\u63a8\u9001\u5c42\u5f53\u521d\u7528\u7684\u5c31\u662f\u7b56\u7565\u6a21\u5f0f&#xff0c;\u4e24\u5144\u5f1f\u592a\u5bb9\u6613\u6df7\u3002\u8fa8\u6790\u7684\u6807\u51c6\u5f88\u7b80\u5355&#xff1a;\u53d8\u5316\u53d1\u751f\u5728&#034;\u6574\u4e2a\u7b97\u6cd5\u53ef\u66ff\u6362&#034;\u65f6\u7528\u7b56\u7565&#xff08;Email\/IM\/SMS \u6bcf\u4e2a\u90fd\u662f\u4ece\u5934\u5230\u5c3e\u4e0d\u540c\u7684\u63a8\u9001\u7b97\u6cd5&#xff09;&#xff1b;\u53d8\u5316\u53d1\u751f\u5728&#034;\u6d41\u7a0b\u56fa\u5b9a\u3001\u6b65\u9aa4\u5404\u5f02&#034;\u65f6\u7528\u6a21\u677f\u65b9\u6cd5&#xff08;\u6bcf\u79cd\u4e8b\u4ef6\u7684\u6d88\u8d39\u6d41\u7a0b\u90fd\u662f\u89e3\u6790\u2192\u6821\u9a8c\u2192\u843d\u5e93&#xff0c;\u53ea\u662f\u6bcf\u6b65\u5185\u5bb9\u4e0d\u540c&#xff09;\u3002\u6d88\u8d39\u4fa7\u9009\u6a21\u677f\u65b9\u6cd5\u8fd8\u6709\u4e2a\u5b9e\u9645\u8003\u91cf&#xff1a;\u5f02\u5e38\u5206\u6d41\u548c\u91cd\u8bd5\u767b\u8bb0\u4f9d\u8d56\u6267\u884c\u987a\u5e8f&#xff0c;\u6d41\u7a0b\u8bed\u4e49\u5fc5\u987b\u7edf\u4e00&#xff0c;\u4ea4\u7ed9\u5b69\u5b50\u7c7b\u81ea\u7531\u53d1\u6325\u53cd\u800c\u662f\u98ce\u9669\u3002<\/p>\n<h3>\u5e42\u7b49&#xff1a;\u7ed9\u4e1a\u52a1\u6570\u636e\u627e\u81ea\u7136\u8eab\u4efd<\/h3>\n<p>MQ \u7684 at-least-once \u8bed\u4e49\u51b3\u5b9a\u4e86\u91cd\u590d\u6295\u9012\u662f\u5e38\u6001&#xff0c;\u6d88\u8d39\u7aef\u5fc5\u987b\u628a&#034;\u540c\u4e00\u6761\u6d88\u606f\u5904\u7406\u4e24\u904d&#034;\u53d8\u6210\u65e0\u5bb3\u64cd\u4f5c\u3002\u6211\u4eec\u7684\u65b9\u6848\u6ca1\u6709\u5f15\u5165\u72ec\u7acb\u7684\u5e42\u7b49\u8868&#xff0c;\u800c\u662f\u76f4\u63a5\u7ed9\u4e1a\u52a1\u8868\u52a0\u552f\u4e00\u952e&#xff1a;\u5355\u636e\u53f7 &#043; \u8d44\u4ea7\u7f16\u7801\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u662f\u8fd9\u4e2a\u7ec4\u5408&#xff1f;\u56de\u5230\u4e1a\u52a1\u4e8b\u5b9e&#xff1a;\u4e00\u884c\u6298\u65e7\u660e\u7ec6\u7684\u81ea\u7136\u8eab\u4efd\u5c31\u662f&#034;\u54ea\u5f20\u8ba1\u63d0\u5355\u636e\u3001\u5bf9\u54ea\u4e2a\u8d44\u4ea7&#034;\u3002\u540c\u4e00\u5f20\u5355\u636e\u5bf9\u540c\u4e00\u8d44\u4ea7\u53ea\u53ef\u80fd\u6709\u4e00\u6761\u6298\u65e7\u660e\u7ec6\u2014\u2014\u8fd9\u4e0d\u662f\u6280\u672f\u8bbe\u8ba1&#xff0c;\u662f\u8d22\u52a1\u53e3\u5f84\u672c\u8eab\u3002\u5e42\u7b49\u952e\u9009\u4e1a\u52a1\u81ea\u7136\u952e\u800c\u4e0d\u662f\u81ea\u5df1\u53d1\u660e\u4e00\u4e2a\u53bb\u91cd\u952e&#xff0c;\u597d\u5904\u662f\u5c11\u7ef4\u62a4\u4e00\u5f20\u8868&#xff0c;\u4e14\u5e42\u7b49\u51ed\u636e\u548c\u4e1a\u52a1\u6570\u636e\u540c\u751f\u5171\u6b7b&#xff1a;\u4e0d\u5b58\u5728&#034;\u5e42\u7b49\u8868\u8bb0\u5f55\u5728\u3001\u4e1a\u52a1\u6570\u636e\u8fd8\u6ca1\u843d&#034;\u6216\u53cd\u8fc7\u6765\u7684\u4e2d\u95f4\u6001\u3002<\/p>\n<p>\u843d\u5e93\u7528 upsert&#xff08;MySQL \u8bed\u6cd5&#xff0c;\u7b80\u5316\u793a\u610f&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">INSERT<\/span> <span class=\"token keyword\">INTO<\/span> depreciation_detail<br \/>\n  <span class=\"token punctuation\">(<\/span>bill_no<span class=\"token punctuation\">,<\/span> asset_code<span class=\"token punctuation\">,<\/span> period<span class=\"token punctuation\">,<\/span> dep_amount<span class=\"token punctuation\">,<\/span> state_version<span class=\"token punctuation\">,<\/span> updated_at<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">VALUES<\/span><br \/>\n  <span class=\"token punctuation\">(<\/span><span class=\"token comment\">#{billNo}, #{assetCode}, #{period}, #{depAmount}, #{stateVersion}, now())<\/span><br \/>\n<span class=\"token keyword\">ON<\/span> <span class=\"token keyword\">DUPLICATE<\/span> <span class=\"token keyword\">KEY<\/span> <span class=\"token keyword\">UPDATE<\/span><br \/>\n  dep_amount    <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">IF<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">VALUES<\/span><span class=\"token punctuation\">(<\/span>state_version<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> state_version<span class=\"token punctuation\">,<\/span><br \/>\n                     <span class=\"token keyword\">VALUES<\/span><span class=\"token punctuation\">(<\/span>dep_amount<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> dep_amount<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  state_version <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">IF<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">VALUES<\/span><span class=\"token punctuation\">(<\/span>state_version<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> state_version<span class=\"token punctuation\">,<\/span><br \/>\n                     <span class=\"token keyword\">VALUES<\/span><span class=\"token punctuation\">(<\/span>state_version<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> state_version<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  updated_at    <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">IF<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">VALUES<\/span><span class=\"token punctuation\">(<\/span>state_version<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> state_version<span class=\"token punctuation\">,<\/span> <span class=\"token function\">now<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> updated_at<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u6761 SQL \u91cc\u5176\u5b9e\u53e0\u7740\u4e24\u5c42\u9632\u7ebf&#xff0c;\u5206\u5f00\u8bf4\u6e05\u695a&#xff1a;<\/p>\n<p>\u552f\u4e00\u952e\u9632\u91cd\u590d\u3002 \u540c\u4e00\u6761\u6d88\u606f\u91cd\u653e\u4e00\u767e\u6b21&#xff0c;\u552f\u4e00\u952e\u547d\u4e2d\u540c\u4e00\u884c&#xff0c;INSERT \u53d8 UPDATE&#xff0c;\u6700\u7ec8\u6570\u636e\u4e00\u6a21\u4e00\u6837\u2014\u2014\u8fd9\u662f Upsert \u5e42\u7b49\u7684\u672c\u4f53\u3002<\/p>\n<p>\u6761\u4ef6\u66f4\u65b0\u9632\u65e7\u76d6\u65b0\u3002 \u4f46 upsert \u5e42\u7b49\u6709\u4e2a\u8fb9\u754c\u5fc5\u987b\u8ba4\u6e05&#xff1a;\u5b83\u53ea\u5bf9&#034;\u5185\u5bb9\u76f8\u540c\u7684\u91cd\u590d&#034;\u65e0\u5bb3\u3002\u5982\u679c\u4e71\u5e8f\u8ba9\u65e7\u72b6\u6001\u7684\u4e8b\u4ef6\u540e\u5230&#xff0c;\u88f8\u7684 upsert \u4f1a\u62ff\u7740\u65e7\u503c\u628a\u65b0\u503c\u8986\u76d6\u6389\u3002IF(VALUES(state_version) &gt; state_version, &#8230;) \u5c31\u662f\u8865\u8fd9\u4e2a\u7f3a\u53e3\u7684&#xff1a;\u7248\u672c\u4e0d\u6bd4\u5f53\u524d\u9ad8\u7684\u66f4\u65b0\u4e00\u5f8b\u7a7a\u8f6c\u3002\u552f\u4e00\u952e\u89e3\u51b3&#034;\u91cd\u590d&#034;&#xff0c;\u6761\u4ef6\u66f4\u65b0\u89e3\u51b3&#034;\u4e71\u5e8f&#034;&#xff0c;\u4e24\u9053\u9501\u7f3a\u4e00\u4e0d\u53ef\u2014\u2014\u53ea\u52a0\u524d\u8005&#xff0c;\u94fe\u8def\u5728\u4e71\u5e8f\u9762\u524d\u7167\u6837\u4e22\u6570\u636e\u3002<\/p>\n<p>\u538b\u6d4b\u65f6\u4e13\u95e8\u9a8c\u8bc1\u8fc7\u8fd9\u4e00\u70b9&#xff1a;\u628a\u4e00\u5929\u7684\u771f\u5b9e\u4e8b\u4ef6\u6d41\u6253\u4e71\u987a\u5e8f\u91cd\u653e\u4e24\u904d&#xff0c;\u5e93\u91cc\u7684\u6570\u636e\u4e0e\u6b63\u5e38\u987a\u5e8f\u5355\u904d\u6d88\u8d39\u7684\u7ed3\u679c\u9010\u5b57\u6bb5\u4e00\u81f4\u3002\u5e42\u7b49\u505a\u5f97\u5bf9\u4e0d\u5bf9&#xff0c;\u4e0d\u80fd\u9760&#034;\u5e94\u8be5\u6ca1\u95ee\u9898&#034;&#xff0c;\u8981\u9760\u91cd\u653e\u6765\u8bc1\u3002<\/p>\n<h3>\u9ad8\u53ef\u7528&#xff1a;\u751f\u4ea7\u4fa7\u4e0d\u4e22&#xff0c;\u6d88\u8d39\u4fa7\u5fc5\u8fbe<\/h3>\n<p>&#034;\u672c\u5730\u6d88\u606f\u8868\u4e0e\u6307\u6570\u9000\u907f\u91cd\u8bd5\u4fdd\u969c\u9ad8\u53ef\u7528&#034;\u8fd9\u53e5\u8bdd\u62c6\u5f00\u662f\u4e24\u7aef\u7684\u4e24\u4e2a\u627f\u8bfa\u3002<\/p>\n<p>\u751f\u4ea7\u4fa7&#xff1a;\u4e0d\u4e22\u3002 \u8d44\u4ea7\u4fa7 outbox \u8868\u5728\u4e0a\u4e00\u7bc7\u8be6\u5199\u8fc7&#xff0c;\u8fd9\u91cc\u53ea\u56de\u6536\u4e00\u53e5\u2014\u2014\u8ba1\u63d0\u4e8b\u52a1\u5185\u5199\u4e1a\u52a1\u8868\u7684\u540c\u65f6\u5199 outbox&#xff0c;\u53d1\u9001\u5931\u8d25\u7531 relay \u4efb\u52a1\u515c\u5e95\u8865\u53d1\u3002&#034;\u4e8b\u4ef6\u4e00\u5b9a\u53d1\u5f97\u51fa\u53bb&#034;\u4e0d\u8d4c\u5728 try-catch \u4e0a\u3002<\/p>\n<p>\u6d88\u8d39\u4fa7&#xff1a;\u5fc5\u8fbe\u3002 \u5931\u8d25\u7684\u6d88\u606f\u8981\u6709\u53bb\u5904&#xff0c;\u4e14\u8981\u6309\u6b63\u786e\u7684\u8282\u594f\u91cd\u8bd5\u3002\u5b8c\u6574\u7684\u4e09\u5c42\u91cd\u8bd5\u91d1\u5b57\u5854&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u5c42\u662f MQ \u5185\u5efa\u91cd\u8bd5\u3002\u6d88\u8d39\u629b\u51fa\u5f02\u5e38&#xff0c;\u6d88\u606f\u8fdb\u91cd\u8bd5\u961f\u5217&#xff0c;RocketMQ \u7684\u91cd\u8bd5\u95f4\u9694\u968f\u6b21\u6570\u9636\u68af\u9012\u589e&#xff0c;\u9ed8\u8ba4\u5341\u516d\u6b21\u540e\u843d\u5165\u6b7b\u4fe1\u961f\u5217\u3002\u8fd9\u4e00\u5c42\u6321\u7684\u662f\u77ac\u65f6\u6296\u52a8\u2014\u2014\u4e0b\u6e38\u6570\u636e\u5e93\u4e3b\u4ece\u5207\u6362\u3001\u8fde\u63a5\u6c60\u77ac\u95f4\u6253\u6ee1\u8fd9\u7c7b\u79d2\u7ea7\u6062\u590d\u7684\u6545\u969c&#xff0c;\u901a\u5e38\u5728\u91cd\u8bd5\u961f\u5217\u91cc\u5c31\u81ea\u6108\u4e86\u3002<\/p>\n<p>\u7b2c\u4e8c\u5c42\u662f\u6d88\u8d39\u4fa7\u7684\u91cd\u8bd5\u8bb0\u5f55\u8868 &#043; \u6307\u6570\u9000\u907f\u635e\u5355&#xff0c;\u6321\u7684\u662f\u6301\u7eed\u6545\u969c\u2014\u2014\u8d22\u52a1\u670d\u52a1\u5347\u7ea7\u3001\u8d44\u4ea7\u4fa7\u63a5\u53e3\u4e0d\u53ef\u7528\u8fd9\u7c7b\u5206\u949f\u5230\u5c0f\u65f6\u7ea7\u7684\u6545\u969c&#xff0c;\u5341\u516d\u6b21 MQ \u91cd\u8bd5\u8fdc\u8fdc\u71ac\u4e0d\u8fc7\u53bb\u3002\u6b7b\u4fe1\u6216\u663e\u5f0f\u5931\u8d25\u7684\u4e8b\u4ef6\u767b\u8bb0\u5165\u8868&#xff0c;\u5b9a\u65f6\u4efb\u52a1\u6309\u6307\u6570\u9000\u907f\u635e\u5355&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u6307\u6570\u9000\u907f:2^n \u589e\u957f,\u5c01\u9876 &#043; \u6296\u52a8(\u7b80\u5316\u793a\u610f)<\/span><br \/>\n<span class=\"token keyword\">long<\/span> backoff <span class=\"token operator\">&#061;<\/span> baseMillis <span class=\"token operator\">*<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1L<\/span> <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">min<\/span><span class=\"token punctuation\">(<\/span>retryCount<span class=\"token punctuation\">,<\/span> capExp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nbackoff <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">min<\/span><span class=\"token punctuation\">(<\/span>backoff<span class=\"token punctuation\">,<\/span> maxBackoffMillis<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u5c01\u9876 24h<\/span><br \/>\nbackoff <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token class-name\">ThreadLocalRandom<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">current<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">nextLong<\/span><span class=\"token punctuation\">(<\/span>jitterMillis<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nrecord<span class=\"token punctuation\">.<\/span><span class=\"token function\">setNextRetryAt<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Instant<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">now<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">plusMillis<\/span><span class=\"token punctuation\">(<\/span>backoff<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u5fc5\u987b\u662f\u6307\u6570\u9000\u907f\u800c\u4e0d\u662f\u56fa\u5b9a\u95f4\u9694&#xff1f;\u5047\u8bbe\u4e0b\u6e38\u6545\u969c\u6062\u590d\u7684\u77ac\u95f4&#xff0c;\u4e00\u4e07\u6761\u5931\u8d25\u6d88\u606f\u90fd\u6309\u56fa\u5b9a\u5341\u5206\u949f\u95f4\u9694\u91cd\u8bd5\u2014\u2014\u5b83\u4eec\u4f1a\u5728\u540c\u4e00\u4e2a\u5bf9\u9f50\u7684\u8282\u62cd\u4e0a\u7838\u56de\u53bb&#xff0c;\u6062\u590d\u4e2d\u7684\u4e0b\u6e38\u88ab\u7b2c\u4e8c\u6ce2\u6253\u8db4\u4e0b&#xff0c;\u6545\u969c\u65f6\u95f4\u548c\u5f71\u54cd\u9762\u53cc\u53cc\u653e\u5927\u3002\u6307\u6570\u9000\u907f\u628a\u91cd\u8bd5\u65f6\u95f4\u70b9\u5728\u65f6\u95f4\u8f74\u4e0a\u6307\u6570\u7ea7\u5730\u62c9\u5f00&#xff0c;\u518d\u53e0\u4e00\u5c42\u968f\u673a\u6296\u52a8&#xff08;jitter&#xff09;\u628a\u540c\u6279\u6d88\u606f\u7684\u53bb\u91cd\u8282\u62cd\u5f7b\u5e95\u6253\u6563\u3002\u91cd\u8bd5\u7b56\u7565\u7684\u672c\u8d28\u4e0d\u662f&#034;\u591a\u8bd5\u51e0\u6b21&#034;&#xff0c;\u662f\u63a7\u5236\u5931\u8d25\u6062\u590d\u65f6\u523b\u7684\u6d41\u91cf\u5f62\u72b6\u3002<\/p>\n<p>\u7b2c\u4e09\u5c42\u662f\u4eba&#xff1a;\u91cd\u8bd5\u6b21\u6570\u8d85\u4e0a\u9650\u7684\u8bb0\u5f55\u89e6\u53d1\u544a\u8b66\u5de5\u5355&#xff0c;\u6b7b\u4fe1\u961f\u5217\u6302\u76d1\u63a7\u3002\u5230\u8fd9\u91cc&#xff0c;\u6bcf\u4e00\u6761\u5931\u8d25\u7684\u6d88\u606f\u90fd\u6709\u660e\u786e\u53bb\u5411\u2014\u2014\u8981\u4e48\u6b63\u5728\u9000\u907f\u7b49\u5f85&#xff0c;\u8981\u4e48\u5df2\u7ecf\u8eba\u5728\u544a\u8b66\u91cc\u7b49\u4eba\u3002\u9ad8\u53ef\u7528\u7684\u53cd\u9762\u4e0d\u662f\u6545\u969c&#xff0c;\u662f\u5931\u8d25\u5f97\u65e0\u58f0\u65e0\u606f\u3002<\/p>\n<h3>\u6548\u679c\u4e0e\u8fd8\u6ca1\u505a\u7684<\/h3>\n<p>\u5b9a\u6027\u5730\u8bf4\u6539\u9020\u524d\u540e\u7684\u5dee\u522b&#xff1a;<\/p>\n<p>\u65b0\u589e\u4e00\u7c7b\u540c\u6b65\u4e8b\u4ef6&#xff0c;\u4ece&#034;\u590d\u5236\u4e00\u4e2a Handler \u6539\u4e1a\u52a1\u6bb5&#034;\u53d8\u6210&#034;\u5b9e\u73b0\u4e09\u4e2a\u65b9\u6cd5&#034;&#xff0c;\u9aa8\u67b6\u4ee3\u7801\u96f6\u63a5\u89e6&#xff0c;\u5e42\u7b49\u548c\u91cd\u8bd5\u5929\u7136\u7ee7\u627f&#xff1b;\u91cd\u590d\u6d88\u8d39\u5728\u538b\u6d4b\u91cd\u653e\u4e0b\u96f6\u75d5\u8ff9&#xff1b;\u6bcf\u6761\u5931\u8d25\u6d88\u606f\u5728\u91cd\u8bd5\u8868\u91cc\u6709\u72b6\u6001\u3001\u6709\u4e0b\u4e00\u6b21\u91cd\u8bd5\u65f6\u523b&#xff0c;\u6392\u969c\u65f6\u4e0d\u7528\u7ffb\u65e5\u5fd7\u8003\u53e4\u3002<\/p>\n<p>\u8fd8\u6ca1\u505a\u7684\u4e5f\u5982\u5b9e\u8bb0\u7740&#xff1a;postProcess \u4e4b\u5916\u6682\u65f6\u6ca1\u5f00\u66f4\u591a\u94a9\u5b50&#xff0c;\u4f46\u5df2\u7ecf\u80fd\u9884\u611f\u5230&#034;\u67d0\u79cd\u4e8b\u4ef6\u60f3\u8df3\u8fc7\u6821\u9a8c\u6b65\u9aa4&#034;\u7684\u9700\u6c42\u6b63\u5728\u9760\u8fd1&#xff0c;\u5230\u65f6\u5019\u662f\u7ee7\u7eed\u5f00\u94a9\u5b50\u8fd8\u662f\u62c6\u51fa\u65b0\u7684\u9aa8\u67b6\u5206\u652f&#xff0c;\u9700\u8981\u91cd\u65b0\u6743\u8861&#xff1b;\u91cd\u8bd5\u8868\u7684\u6e05\u7406\u7b56\u7565\u8fd8\u6ca1\u505a&#xff08;\u548c\u4e0a\u6b21 outbox \u81a8\u80c0\u7684\u5751\u540c\u6b3e\u9690\u60a3&#xff0c;\u5df2\u7ecf\u6302\u5728\u5f85\u529e\u4e0a&#xff09;&#xff1b;\u6a21\u677f\u65b9\u6cd5\u7236\u7c7b\u76ee\u524d\u9760 code review \u4fdd\u8bc1\u5b50\u7c7b\u4e0d\u7ed5\u8fc7\u9aa8\u67b6&#xff0c;\u6ca1\u6709\u7f16\u8bd1\u671f\u6216\u8fd0\u884c\u671f\u7684\u5f3a\u5236\u624b\u6bb5\u3002<\/p>\n<h3>\u51e0\u70b9\u4f53\u4f1a<\/h3>\n<p>\u8bbe\u8ba1\u6a21\u5f0f\u7684\u4ef7\u503c\u5728\u5b66\u4e60\u7b14\u8bb0\u91cc\u662f\u62bd\u8c61\u7684&#xff0c;\u5728\u771f\u5b9e\u4ee3\u7801\u91cc\u662f\u5177\u4f53\u7684\u3002 \u7b14\u8bb0\u9636\u6bb5\u89c9\u5f97\u6a21\u677f\u65b9\u6cd5\u4e0d\u8fc7\u5982\u6b64&#xff0c;\u76f4\u5230\u4e94\u4e2a Handler \u7684\u91cd\u590d\u4ee3\u7801\u644a\u5728\u9762\u524d\u624d\u660e\u767d&#xff1a;\u5b83\u89e3\u51b3\u7684\u4e0d\u662f&#034;\u4ee3\u7801\u4f18\u96c5&#034;&#xff0c;\u662f&#034;\u6d41\u7a0b\u8bed\u4e49\u53ea\u80fd\u5b58\u5728\u4e00\u4efd&#034;\u8fd9\u79cd\u4e00\u81f4\u6027\u5de5\u7a0b\u95ee\u9898\u3002\u5b66\u5230\u7684\u4e1c\u897f\u8981\u7b49\u4e00\u4e2a\u771f\u5b9e\u573a\u666f\u6765\u5151\u73b0\u3002<\/p>\n<p>\u5e42\u7b49\u952e\u7684\u8bbe\u8ba1\u662f\u4e1a\u52a1\u95ee\u9898&#xff0c;\u4e0d\u662f\u6280\u672f\u95ee\u9898\u3002 &#034;\u5355\u636e\u53f7 &#043; \u8d44\u4ea7\u7f16\u7801&#034;\u4e4b\u6240\u4ee5\u6210\u7acb&#xff0c;\u662f\u56e0\u4e3a\u8d22\u52a1\u53e3\u5f84\u91cc\u6298\u65e7\u660e\u7ec6\u5c31\u662f\u8fd9\u4e48\u5b9a\u4e49\u552f\u4e00\u6027\u7684\u3002\u6280\u672f\u4e0a\u7684 upsert \u53ea\u662f\u628a\u8fd9\u4e2a\u4e1a\u52a1\u4e8b\u5b9e\u7ffb\u8bd1\u6210\u4e86\u552f\u4e00\u7d22\u5f15\u3002\u53cd\u8fc7\u6765&#xff0c;\u54ea\u5929\u4e1a\u52a1\u53e3\u5f84\u53d8\u4e86&#xff08;\u6bd4\u5982\u5355\u636e\u7c92\u5ea6\u8c03\u6574&#xff09;&#xff0c;\u552f\u4e00\u952e\u5fc5\u987b\u8ddf\u7740\u52a8\u2014\u2014\u5e42\u7b49\u952e\u8ddf\u7740\u4e1a\u52a1\u8bed\u4e49\u8d70&#xff0c;\u800c\u4e0d\u662f\u8ddf\u7740\u6d88\u606f\u7ed3\u6784\u8d70\u3002<\/p>\n<p>\u6bcf\u5c42\u9632\u7ebf\u53ea\u89e3\u51b3\u4e00\u79cd\u5931\u8d25\u6a21\u5f0f\u3002 \u552f\u4e00\u952e\u9632\u91cd\u590d\u3001\u6761\u4ef6\u66f4\u65b0\u9632\u4e71\u5e8f\u3001MQ \u91cd\u8bd5\u9632\u6296\u52a8\u3001\u6307\u6570\u9000\u907f\u9632\u6301\u7eed\u6545\u969c\u3001\u544a\u8b66\u9632\u65e0\u58f0\u5931\u8d25\u2014\u2014\u6ca1\u6709\u54ea\u4e00\u5c42\u662f\u591a\u4f59\u7684&#xff0c;\u4e5f\u6ca1\u6709\u54ea\u4e00\u5c42\u80fd\u5305\u6253\u5929\u4e0b\u3002\u505a\u6570\u636e\u540c\u6b65\u505a\u4e45\u4e86&#xff0c;\u4f1a\u8d8a\u6765\u8d8a\u4e60\u60ef&#034;\u5148\u628a\u5931\u8d25\u6a21\u5f0f\u5217\u5168&#xff0c;\u518d\u7ed9\u6bcf\u4e00\u79cd\u914d\u4e00\u6761\u4e13\u5c5e\u9632\u7ebf&#034;\u7684\u601d\u8def\u3002<\/p>\n<p>\u6700\u540e\u7559\u4e00\u4e2a\u81ea\u6211\u63d0\u9192&#xff1a;\u6a21\u677f\u65b9\u6cd5\u628a\u6d41\u7a0b\u9501\u8fdb\u7236\u7c7b\u7684\u540c\u65f6&#xff0c;\u4e5f\u628a\u4fee\u6539\u6743\u9501\u4e86\u8fdb\u53bb\u2014\u2014\u54ea\u5929\u51fa\u73b0\u4e00\u4e2a\u6d41\u7a0b\u771f\u4e0d\u4e00\u6837\u7684\u5b50\u7c7b&#xff0c;\u6700\u5148\u5d29\u6389\u7684\u4f1a\u662f\u5f53\u521d\u90a3\u4e2a final\u3002\u5230\u65f6\u5019\u8981\u6562\u4e8e\u63a8\u7ffb\u81ea\u5df1&#xff0c;\u628a\u9aa8\u67b6\u6539\u6210\u7ec4\u5408\u5f0f\u7684\u3002\u6a21\u5f0f\u662f\u4e3a\u573a\u666f\u670d\u52a1\u7684&#xff0c;\u53cd\u8fc7\u6765\u4e0d\u6210\u7acb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u4e94\u79cd Handler \u590d\u5236\u7c98\u8d34\u8bf4\u8d77<br \/>\n\u8d22\u52a1\u670d\u52a1\u8981\u6d88\u8d39\u7684\u540c\u6b65\u4e8b\u4ef6\u4e0d\u6b62\u4e00\u79cd&#xff1a;\u6298\u65e7\u8ba1\u63d0\u660e\u7ec6\u7684 UPSERT\u3001\u6298\u65e7\u51b2\u9500\u7684 DELETE\u3001\u8d44\u4ea7\u5361\u7247\u4e3b\u6570\u636e\u53d8\u66f4\u3001\u5355\u636e\u72b6\u6001\u6d41\u8f6c\u3001\u671f\u672b\u7ed3\u8f6c\u6807\u5fd7\u3002\u7b2c\u4e00\u7248\u7684\u5b9e\u73b0\u662f\u4e94\u79cd\u4e8b\u4ef6\u4e94\u4e2a Handler&#xff0c;\u6bcf\u4e2a\u90fd\u81ea\u5df1\u5199\u4e00\u904d\u5b8c\u6574\u7684\u6d88\u8d39\u6d41\u7a0b\u3002<br \/>\n\u5199\u5b8c\u56de\u5934\u770b&#xff0c;\u4e94\u4e2a\u7c7b\u51e0\u4e4e\u662f\u4e00\u4e2a\u6a21\u5b50\u523b\u51fa\u6765\u7684&#xff1a;<br \/>\n\/\/ \u4e94\u4e2a Handler \u91cc\u91cd\u590d\u51fa\u73b0\u4e94\u6b21\u7684\u6bb5\u843d<br \/>\npublic void onMessage(MessageExt messa<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-97459","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/97459.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4ece\u4e94\u79cd Handler \u590d\u5236\u7c98\u8d34\u8bf4\u8d77 \u8d22\u52a1\u670d\u52a1\u8981\u6d88\u8d39\u7684\u540c\u6b65\u4e8b\u4ef6\u4e0d\u6b62\u4e00\u79cd&#xff1a;\u6298\u65e7\u8ba1\u63d0\u660e\u7ec6\u7684 UPSERT\u3001\u6298\u65e7\u51b2\u9500\u7684 DELETE\u3001\u8d44\u4ea7\u5361\u7247\u4e3b\u6570\u636e\u53d8\u66f4\u3001\u5355\u636e\u72b6\u6001\u6d41\u8f6c\u3001\u671f\u672b\u7ed3\u8f6c\u6807\u5fd7\u3002\u7b2c\u4e00\u7248\u7684\u5b9e\u73b0\u662f\u4e94\u79cd\u4e8b\u4ef6\u4e94\u4e2a Handler&#xff0c;\u6bcf\u4e2a\u90fd\u81ea\u5df1\u5199\u4e00\u904d\u5b8c\u6574\u7684\u6d88\u8d39\u6d41\u7a0b\u3002 \u5199\u5b8c\u56de\u5934\u770b&#xff0c;\u4e94\u4e2a\u7c7b\u51e0\u4e4e\u662f\u4e00\u4e2a\u6a21\u5b50\u523b\u51fa\u6765\u7684&#xff1a; \/\/ \u4e94\u4e2a Handler \u91cc\u91cd\u590d\u51fa\u73b0\u4e94\u6b21\u7684\u6bb5\u843d public void onMessage(MessageExt messa\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97459.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-29T07:08:46+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97459.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97459.html\",\"name\":\"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-29T07:08:46+00:00\",\"dateModified\":\"2026-08-29T07:08:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97459.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97459.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97459.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/97459.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4ece\u4e94\u79cd Handler \u590d\u5236\u7c98\u8d34\u8bf4\u8d77 \u8d22\u52a1\u670d\u52a1\u8981\u6d88\u8d39\u7684\u540c\u6b65\u4e8b\u4ef6\u4e0d\u6b62\u4e00\u79cd&#xff1a;\u6298\u65e7\u8ba1\u63d0\u660e\u7ec6\u7684 UPSERT\u3001\u6298\u65e7\u51b2\u9500\u7684 DELETE\u3001\u8d44\u4ea7\u5361\u7247\u4e3b\u6570\u636e\u53d8\u66f4\u3001\u5355\u636e\u72b6\u6001\u6d41\u8f6c\u3001\u671f\u672b\u7ed3\u8f6c\u6807\u5fd7\u3002\u7b2c\u4e00\u7248\u7684\u5b9e\u73b0\u662f\u4e94\u79cd\u4e8b\u4ef6\u4e94\u4e2a Handler&#xff0c;\u6bcf\u4e2a\u90fd\u81ea\u5df1\u5199\u4e00\u904d\u5b8c\u6574\u7684\u6d88\u8d39\u6d41\u7a0b\u3002 \u5199\u5b8c\u56de\u5934\u770b&#xff0c;\u4e94\u4e2a\u7c7b\u51e0\u4e4e\u662f\u4e00\u4e2a\u6a21\u5b50\u523b\u51fa\u6765\u7684&#xff1a; \/\/ \u4e94\u4e2a Handler \u91cc\u91cd\u590d\u51fa\u73b0\u4e94\u6b21\u7684\u6bb5\u843d public void onMessage(MessageExt messa","og_url":"https:\/\/www.wsisp.com\/helps\/97459.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-29T07:08:46+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/97459.html","url":"https:\/\/www.wsisp.com\/helps\/97459.html","name":"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-29T07:08:46+00:00","dateModified":"2026-08-29T07:08:46+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97459.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97459.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97459.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6298\u65e7\u540c\u6b65\u6d88\u8d39\u4fa7\u6539\u9020\uff1a\u6a21\u677f\u65b9\u6cd5\u62bd\u8c61\u4e0e Upsert \u5e42\u7b49\u7684\u5b9e\u6218\u843d\u5730"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=97459"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97459\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97459"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}