{"id":5271,"date":"2021-08-30T21:40:56","date_gmt":"2021-08-30T13:40:56","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=5271"},"modified":"2021-08-30T21:40:56","modified_gmt":"2021-08-30T13:40:56","slug":"%e7%94%b5%e5%95%86%e7%b3%bb%e7%bb%9f%e8%ae%a2%e5%8d%95%e8%b6%85%e6%97%b6%e5%8f%96%e6%b6%88%e8%ae%a2%e5%8d%95%e7%9a%845%e7%a7%8d%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%a1%88%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=5271","title":{"rendered":"\u7535\u5546\u7cfb\u7edf\u8ba2\u5355\u8d85\u65f6\u53d6\u6d88\u8ba2\u5355\u76845\u79cd\u5b9e\u73b0\u65b9\u6848\uff01"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6211\u4eca\u5e74\u9762\u8bd5\u8fc7\u4e0d\u5c11 Java \u7a0b\u5e8f\u5458\uff0c\u521d\u7ea7\u7684\u3001\u4e2d\u7ea7\u7684\u3001\u9ad8\u7ea7\u7684\u90fd\u6709\u3002\u5f88\u591a\u5019\u9009\u8005\u7b80\u5386\u4e0a\u5199\u7740\u7cbe\u901a Redis\uff0cRabbitMQ \u7b49\u4e2d\u95f4\u4ef6\uff0c\u4e8e\u662f\u6211\u5c31\u968f\u624b\u51fa\u4e00\u9898\uff1a<code>\u7c7b\u4f3c\u8ba2\u5355\u8d85\u65f6\uff0c\u53d6\u6d88\u8ba2\u5355\u5982\u4f55\u5b9e\u73b0\uff0c\u8bf4\u8bf4\u4f60\u7684\u5b9e\u73b0\u601d\u8def<\/code>\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u300c\u5f15\u8a00\u300d<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5f00\u53d1\u4e2d\uff0c\u5f80\u5f80\u4f1a\u9047\u5230\u4e00\u4e9b\u5173\u4e8e\u5ef6\u65f6\u4efb\u52a1\u7684\u9700\u6c42\u3002\u4f8b\u5982<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u751f\u6210\u8ba2\u5355 30 \u5206\u949f\u672a\u652f\u4ed8\uff0c\u5219\u81ea\u52a8\u53d6\u6d88<\/li><li>\u751f\u6210\u8ba2\u5355 60 \u79d2\u540e\uff0c\u7ed9\u7528\u6237\u53d1\u77ed\u4fe1<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e0a\u8ff0\u7684\u4efb\u52a1\uff0c\u6211\u4eec\u7ed9\u4e00\u4e2a\u4e13\u4e1a\u7684\u540d\u5b57\u6765\u5f62\u5bb9\uff0c\u90a3\u5c31\u662f\u5ef6\u65f6\u4efb\u52a1\u3002\u90a3\u4e48\u8fd9\u91cc\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u95ee\u9898\uff0c\u8fd9\u4e2a\u5ef6\u65f6\u4efb\u52a1\u548c\u5b9a\u65f6\u4efb\u52a1\u7684\u533a\u522b\u7a76\u7adf\u5728\u54ea\u91cc\u5462\uff1f\u4e00\u5171\u6709\u5982\u4e0b\u51e0\u70b9\u533a\u522b<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5b9a\u65f6\u4efb\u52a1\u6709\u660e\u786e\u7684\u89e6\u53d1\u65f6\u95f4\uff0c\u5ef6\u65f6\u4efb\u52a1\u6ca1\u6709<\/li><li>\u5b9a\u65f6\u4efb\u52a1\u6709\u6267\u884c\u5468\u671f\uff0c\u800c\u5ef6\u65f6\u4efb\u52a1\u5728\u67d0\u4e8b\u4ef6\u89e6\u53d1\u540e\u4e00\u6bb5\u65f6\u95f4\u5185\u6267\u884c\uff0c\u6ca1\u6709\u6267\u884c\u5468\u671f<\/li><li>\u5b9a\u65f6\u4efb\u52a1\u4e00\u822c\u6267\u884c\u7684\u662f\u6279\u5904\u7406\u64cd\u4f5c\u662f\u591a\u4e2a\u4efb\u52a1\uff0c\u800c\u5ef6\u65f6\u4efb\u52a1\u4e00\u822c\u662f\u5355\u4e2a\u4efb\u52a1<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\uff0c\u6211\u4eec\u4ee5\u5224\u65ad\u8ba2\u5355\u662f\u5426\u8d85\u65f6\u4e3a\u4f8b\uff0c\u8fdb\u884c\u65b9\u6848\u5206\u6790\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u300c\u65b9\u6848\u5206\u6790\u300d<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u300c\u6570\u636e\u5e93\u8f6e\u8be2\u300d<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u601d\u8def<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u65b9\u6848\u901a\u5e38\u662f\u5728\u5c0f\u578b\u9879\u76ee\u4e2d\u4f7f\u7528\uff0c\u5373\u901a\u8fc7\u4e00\u4e2a\u7ebf\u7a0b\u5b9a\u65f6\u7684\u53bb\u626b\u63cf\u6570\u636e\u5e93\uff0c\u901a\u8fc7\u8ba2\u5355\u65f6\u95f4\u6765\u5224\u65ad\u662f\u5426\u6709\u8d85\u65f6\u7684\u8ba2\u5355\uff0c\u7136\u540e\u8fdb\u884c update \u6216 delete \u7b49\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9e\u73b0<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u535a\u4e3b\u5f53\u5e74\u65e9\u671f\u662f\u7528 quartz \u6765\u5b9e\u73b0\u7684(\u5b9e\u4e60\u90a3\u4f1a\u7684\u4e8b)\uff0c\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">maven \u9879\u76ee\u5f15\u5165\u4e00\u4e2a\u4f9d\u8d56\u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n\t&lt;groupId&gt;org.quartz-scheduler&lt;\/groupId&gt;\n\t&lt;artifactId&gt;quartz&lt;\/artifactId&gt;\n\t&lt;version&gt;2.2.2&lt;\/version&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c03\u7528 Demo \u7c7b MyJob \u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MyJob implements Job {\n    public void execute(JobExecutionContext context)\n            throws JobExecutionException {\n        System.out.println(\"\u8981\u53bb\u6570\u636e\u5e93\u626b\u63cf\u5566\u3002\u3002\u3002\");\n    }\n\n    public static void main(String[] args) throws Exception {\n        \/\/ \u521b\u5efa\u4efb\u52a1\n        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)\n                .withIdentity(\"job1\", \"group1\").build();\n\n        \/\/ \u521b\u5efa\u89e6\u53d1\u5668 \u6bcf3\u79d2\u949f\u6267\u884c\u4e00\u6b21\n        Trigger trigger = TriggerBuilder\n                .newTrigger()\n                .withIdentity(\"trigger1\", \"group3\")\n                .withSchedule(\n                        SimpleScheduleBuilder.simpleSchedule()\n                                .withIntervalInSeconds(3).repeatForever())\n                .build();\n\n        Scheduler scheduler = new StdSchedulerFactory().getScheduler();\n        \/\/ \u5c06\u4efb\u52a1\u53ca\u5176\u89e6\u53d1\u5668\u653e\u5165\u8c03\u5ea6\u5668\n        scheduler.scheduleJob(jobDetail, trigger);\n        \/\/ \u8c03\u5ea6\u5668\u5f00\u59cb\u8c03\u5ea6\u4efb\u52a1\n        scheduler.start();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u4ee3\u7801\uff0c\u53ef\u53d1\u73b0\u6bcf\u9694 3 \u79d2\uff0c\u8f93\u51fa\u5982\u4e0b<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>\u8981\u53bb\u6570\u636e\u5e93\u626b\u63cf\u5566\u3002\u3002\u3002\u275e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u7f3a\u70b9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9\uff1a<code>\u7b80\u5355\u6613\u884c\uff0c\u652f\u6301\u96c6\u7fa4\u64cd\u4f5c<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u5bf9\u670d\u52a1\u5668\u5185\u5b58\u6d88\u8017\u5927\n<\/li><li>(2)\u5b58\u5728\u5ef6\u8fdf\uff0c\u6bd4\u5982\u4f60\u6bcf\u9694 3 \u5206\u949f\u626b\u63cf\u4e00\u6b21\uff0c\u90a3\u6700\u574f\u7684\u5ef6\u8fdf\u65f6\u95f4\u5c31\u662f 3 \u5206\u949f\n<\/li><li>(3)\u5047\u8bbe\u4f60\u7684\u8ba2\u5355\u6709\u51e0\u5343\u4e07\u6761\uff0c\u6bcf\u9694\u51e0\u5206\u949f\u8fd9\u6837\u626b\u63cf\u4e00\u6b21\uff0c\u6570\u636e\u5e93\u635f\u8017\u6781\u5927\n<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">JDK \u7684\u5ef6\u8fdf\u961f\u5217<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u601d\u8def<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u65b9\u6848\u662f\u5229\u7528 JDK \u81ea\u5e26\u7684 DelayQueue \u6765\u5b9e\u73b0\uff0c\u8fd9\u662f\u4e00\u4e2a\u65e0\u754c\u963b\u585e\u961f\u5217\uff0c\u8be5\u961f\u5217\u53ea\u6709\u5728\u5ef6\u8fdf\u671f\u6ee1\u7684\u65f6\u5019\u624d\u80fd\u4ece\u4e2d\u83b7\u53d6\u5143\u7d20\uff0c\u653e\u5165 DelayQueue \u4e2d\u7684\u5bf9\u8c61\uff0c\u662f\u5fc5\u987b\u5b9e\u73b0 Delayed \u63a5\u53e3\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DelayedQueue \u5b9e\u73b0\u5de5\u4f5c\u6d41\u7a0b\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd0.png\" alt=\"DelayedQueue \u5b9e\u73b0\u5de5\u4f5c\u6d41\u7a0b\" \/><figcaption>DelayedQueue \u5b9e\u73b0\u5de5\u4f5c\u6d41\u7a0b<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2d<code>Poll()<\/code>\uff1a\u83b7\u53d6\u5e76\u79fb\u9664\u961f\u5217\u7684\u8d85\u65f6\u5143\u7d20\uff0c\u6ca1\u6709\u5219\u8fd4\u56de\u7a7a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>take()<\/code>\uff1a\u83b7\u53d6\u5e76\u79fb\u9664\u961f\u5217\u7684\u8d85\u65f6\u5143\u7d20\uff0c\u5982\u679c\u6ca1\u6709\u5219 wait \u5f53\u524d\u7ebf\u7a0b\uff0c\u76f4\u5230\u6709\u5143\u7d20\u6ee1\u8db3\u8d85\u65f6\u6761\u4ef6\uff0c\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9e\u73b0<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u4e00\u4e2a\u7c7b OrderDelay \u5b9e\u73b0 Delayed\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.concurrent.Delayed;\nimport java.util.concurrent.TimeUnit;\n\npublic class OrderDelay implements Delayed {\n\n    private String orderId;\n    private long timeout;\n\n    OrderDelay(String orderId, long timeout) {\n        this.orderId = orderId;\n        this.timeout = timeout + System.nanoTime();\n    }\n\n    public int compareTo(Delayed other) {\n        if (other == this)\n            return 0;\n\n        OrderDelay t = (OrderDelay) other;\n        long d = (getDelay(TimeUnit.NANOSECONDS) - t\n                .getDelay(TimeUnit.NANOSECONDS));\n\n        return (d == 0) ? 0 : ((d &lt; 0) ? -1 : 1);\n\n    }\n\n    \/\/ \u8fd4\u56de\u8ddd\u79bb\u4f60\u81ea\u5b9a\u4e49\u7684\u8d85\u65f6\u65f6\u95f4\u8fd8\u6709\u591a\u5c11\n    public long getDelay(TimeUnit unit) {\n        return unit.convert(timeout - System.nanoTime(),TimeUnit.NANOSECONDS);\n    }\n\n    void print() {\n        System.out.println(orderId + \"\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002\");\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7684\u6d4b\u8bd5 Demo \u4e3a\uff0c\u6211\u4eec\u8bbe\u5b9a\u5ef6\u8fdf\u65f6\u95f4\u4e3a 3 \u79d2\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.ArrayList;\nimport java.util.List;\nimport java.util.concurrent.DelayQueue;\nimport java.util.concurrent.TimeUnit;\n\npublic class DelayQueueDemo {\n\n     public static void main(String[] args) {  \n\n        \/\/ TODO Auto-generated method stub  \n\n        List&lt;String&gt; list = new ArrayList&lt;String&gt;();  \n        list.add(\"00000001\");  \n        list.add(\"00000002\");  \n        list.add(\"00000003\");  \n        list.add(\"00000004\");  \n        list.add(\"00000005\");  \n\n        DelayQueue&lt;OrderDelay&gt; queue = newDelayQueue&lt;OrderDelay&gt;();  \n        long start = System.currentTimeMillis();  \n        for(int i = 0;i&lt;5;i++){  \n            \/\/\u5ef6\u8fdf\u4e09\u79d2\u53d6\u51fa\n            queue.put(new OrderDelay(list.get(i),  \n                    TimeUnit.NANOSECONDS.convert(3,TimeUnit.SECONDS)));  \n                try {  \n                     queue.take().print();  \n                     System.out.println(\"After \" +  \n                             (System.currentTimeMillis()-start) + \" MilliSeconds\");  \n\n            } catch (InterruptedException e) {  \n                \/\/ TODO Auto-generated catch block  \n                e.printStackTrace();  \n            }  \n        }  \n    }   \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u5982\u4e0b<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>00000001\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002 <\/p><p>After\u00a03003\u00a0MilliSeconds <\/p><p>00000002\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002<\/p><p> After\u00a06006\u00a0MilliSeconds <\/p><p>00000003\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002 <\/p><p>After\u00a09006\u00a0MilliSeconds <\/p><p>00000004\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002 <\/p><p>After\u00a012008\u00a0MilliSeconds <\/p><p>00000005\u7f16\u53f7\u7684\u8ba2\u5355\u8981\u5220\u9664\u5566\u3002\u3002\u3002\u3002 <\/p><p>After\u00a015009\u00a0MilliSeconds\u275e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\u90fd\u662f\u5ef6\u8fdf 3 \u79d2\uff0c\u8ba2\u5355\u88ab\u5220\u9664\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f18\u7f3a\u70b9<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9\uff1a\u6548\u7387\u9ad8\uff0c\u4efb\u52a1\u89e6\u53d1\u65f6\u95f4\u5ef6\u8fdf\u4f4e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u670d\u52a1\u5668\u91cd\u542f\u540e\uff0c\u6570\u636e\u5168\u90e8\u6d88\u5931\uff0c\u6015\u5b95\u673a<\/li><li>(2)\u96c6\u7fa4\u6269\u5c55\u76f8\u5f53\u9ebb\u70e6<\/li><li>(3)\u56e0\u4e3a\u5185\u5b58\u6761\u4ef6\u9650\u5236\u7684\u539f\u56e0\uff0c\u6bd4\u5982\u4e0b\u5355\u672a\u4ed8\u6b3e\u7684\u8ba2\u5355\u6570\u592a\u591a\uff0c\u90a3\u4e48\u5f88\u5bb9\u6613\u5c31\u51fa\u73b0 OOM \u5f02\u5e38<\/li><li>(4)\u4ee3\u7801\u590d\u6742\u5ea6\u8f83\u9ad8<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u300c\u65f6\u95f4\u8f6e\u7b97\u6cd5\u300d<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u601d\u8def<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u4e0a\u4e00\u5f20\u65f6\u95f4\u8f6e\u7684\u56fe(\u8fd9\u56fe\u5230\u5904\u90fd\u662f\u5566)\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd1.png\" alt=\"\u65f6\u95f4\u8f6e\u7b97\u6cd5\" \/><figcaption>\u65f6\u95f4\u8f6e\u7b97\u6cd5<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u65f6\u95f4\u8f6e\u7b97\u6cd5\u53ef\u4ee5\u7c7b\u6bd4\u4e8e\u65f6\u949f\uff0c\u5982\u4e0a\u56fe\u7bad\u5934\uff08\u6307\u9488\uff09\u6309\u67d0\u4e00\u4e2a\u65b9\u5411\u6309\u56fa\u5b9a\u9891\u7387\u8f6e\u52a8\uff0c\u6bcf\u4e00\u6b21\u8df3\u52a8\u79f0\u4e3a\u4e00\u4e2a tick\u3002\u8fd9\u6837\u53ef\u4ee5\u770b\u51fa\u5b9a\u65f6\u8f6e\u7531\u4e2a 3 \u4e2a\u91cd\u8981\u7684\u5c5e\u6027\u53c2\u6570\uff0cticksPerWheel\uff08\u4e00\u8f6e\u7684tick\u6570\uff09\uff0ctickDuration\uff08\u4e00\u4e2a tick \u7684\u6301\u7eed\u65f6\u95f4\uff09\u4ee5\u53ca timeUnit\uff08\u65f6\u95f4\u5355\u4f4d\uff09\uff0c\u4f8b\u5982\u5f53ticksPerWheel=60\uff0ctickDuration=1\uff0ctimeUnit=\u79d2\uff0c\u8fd9\u5c31\u548c\u73b0\u5b9e\u4e2d\u7684\u59cb\u7ec8\u7684\u79d2\u9488\u8d70\u52a8\u5b8c\u5168\u7c7b\u4f3c\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5f53\u524d\u6307\u9488\u6307\u5728 1 \u4e0a\u9762\uff0c\u6211\u6709\u4e00\u4e2a\u4efb\u52a1\u9700\u8981 4 \u79d2\u4ee5\u540e\u6267\u884c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6267\u884c\u7684\u7ebf\u7a0b\u56de\u8c03\u6216\u8005\u6d88\u606f\u5c06\u4f1a\u88ab\u653e\u5728 5 \u4e0a\u3002\u90a3\u5982\u679c\u9700\u8981\u5728 20 \u79d2\u4e4b\u540e\u6267\u884c\u600e\u4e48\u529e\uff0c\u7531\u4e8e\u8fd9\u4e2a\u73af\u5f62\u7ed3\u6784\u69fd\u6570\u53ea\u5230 8\uff0c\u5982\u679c\u8981 20 \u79d2\uff0c\u6307\u9488\u9700\u8981\u591a\u8f6c 2 \u5708\u3002\u4f4d\u7f6e\u662f\u5728 2 \u5708\u4e4b\u540e\u7684 5 \u4e0a\u9762\uff0820 % 8 + 1\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9e\u73b0<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u7528 Netty \u7684 HashedWheelTimer \u6765\u5b9e\u73b0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed9 pom.xml \u52a0\u4e0a\u4e0b\u9762\u7684\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;io.netty&lt;\/groupId&gt;\n    &lt;artifactId&gt;netty-all&lt;\/artifactId&gt;\n    &lt;version&gt;4.1.24.Final&lt;\/version&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4b\u8bd5\u4ee3\u7801 HashedWheelTimerTest \u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import io.netty.util.HashedWheelTimer;\nimport io.netty.util.Timeout;\nimport io.netty.util.Timer;\nimport io.netty.util.TimerTask;\nimport java.util.concurrent.TimeUnit;\n\npublic class HashedWheelTimerTest {\n    static class MyTimerTask implements TimerTask{\n        boolean flag;\n        public MyTimerTask(boolean flag){\n            this.flag = flag;\n        }\n\n        public void run(Timeout timeout) throws Exception {\n            \/\/ TODO Auto-generated method stub\n             System.out.println(\"\u8981\u53bb\u6570\u636e\u5e93\u5220\u9664\u8ba2\u5355\u4e86\u3002\u3002\u3002\u3002\");\n             this.flag =false;\n        }\n    }\n\n    public static void main(String[] argv) {\n        MyTimerTask timerTask = new MyTimerTask(true);\n        Timer timer = new HashedWheelTimer();\n        timer.newTimeout(timerTask, 5, TimeUnit.SECONDS);\n        int i = 1;\n\n        while(timerTask.flag){\n            try {\n                Thread.sleep(1000);\n            } catch (InterruptedException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n\n            System.out.println(i+\"\u79d2\u8fc7\u53bb\u4e86\");\n            i++;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>1\u79d2\u8fc7\u53bb\u4e86 <\/p><p>2\u79d2\u8fc7\u53bb\u4e86 <\/p><p>3\u79d2\u8fc7\u53bb\u4e86 <\/p><p>4\u79d2\u8fc7\u53bb\u4e86 <\/p><p>5\u79d2\u8fc7\u53bb\u4e86 <\/p><p>\u8981\u53bb\u6570\u636e\u5e93\u5220\u9664\u8ba2\u5355\u4e86\u3002\u3002\u3002\u3002 <\/p><p>6\u79d2\u8fc7\u53bb\u4e86\u275e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u7f3a\u70b9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9\uff1a\u6548\u7387\u9ad8\uff0c\u4efb\u52a1\u89e6\u53d1\u65f6\u95f4\u5ef6\u8fdf\u65f6\u95f4\u6bd4 delayQueue \u4f4e\uff0c\u4ee3\u7801\u590d\u6742\u5ea6\u6bd4 delayQueue \u4f4e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u670d\u52a1\u5668\u91cd\u542f\u540e\uff0c\u6570\u636e\u5168\u90e8\u6d88\u5931\uff0c\u6015\u5b95\u673a<\/li><li>(2)\u96c6\u7fa4\u6269\u5c55\u76f8\u5f53\u9ebb\u70e6<\/li><li>(3)\u56e0\u4e3a\u5185\u5b58\u6761\u4ef6\u9650\u5236\u7684\u539f\u56e0\uff0c\u6bd4\u5982\u4e0b\u5355\u672a\u4ed8\u6b3e\u7684\u8ba2\u5355\u6570\u592a\u591a\uff0c\u90a3\u4e48\u5f88\u5bb9\u6613\u5c31\u51fa\u73b0 OOM \u5f02\u5e38<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">redis \u7f13\u5b58<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\u601d\u8def\u4e00<\/code>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5229\u7528 redis \u7684 zset\uff0czset \u662f\u4e00\u4e2a\u6709\u5e8f\u96c6\u5408\uff0c\u6bcf\u4e00\u4e2a\u5143\u7d20(member)\u90fd\u5173\u8054\u4e86\u4e00\u4e2a score\uff0c\u901a\u8fc7 score \u6392\u5e8f\u6765\u53d6\u96c6\u5408\u4e2d\u7684\u503c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6dfb\u52a0\u5143\u7d20:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZADD\u00a0key\u00a0score\u00a0member\u00a0[[score\u00a0member]\u00a0[score\u00a0member]\u00a0\u2026]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6309\u987a\u5e8f\u67e5\u8be2\u5143\u7d20\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZRANGE\u00a0key\u00a0start\u00a0stop\u00a0[WITHSCORES]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u5143\u7d20 score\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZSCORE\u00a0key\u00a0member<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u79fb\u9664\u5143\u7d20\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ZREM\u00a0key\u00a0member\u00a0[member\u00a0\u2026]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4b\u8bd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6dfb\u52a0\u5355\u4e2a\u5143\u7d20\nredis&gt; ZADD page_rank 10 google.com\n(integer) 1\n\n# \u6dfb\u52a0\u591a\u4e2a\u5143\u7d20\nredis&gt; ZADD page_rank 9 baidu.com 8 bing.com\n(integer) 2\nredis&gt; ZRANGE page_rank 0 -1 WITHSCORES\n1) \"bing.com\"\n2) \"8\"\n3) \"baidu.com\"\n4) \"9\"\n5) \"google.com\"\n6) \"10\"\n\n# \u67e5\u8be2\u5143\u7d20\u7684score\u503c\nredis&gt; ZSCORE page_rank bing.com\n\"8\"\n\n# \u79fb\u9664\u5355\u4e2a\u5143\u7d20\nredis&gt; ZREM page_rank google.com\n(integer) 1\nredis&gt; ZRANGE page_rank 0 -1 WITHSCORES\n1) \"bing.com\"\n2) \"8\"\n3) \"baidu.com\"\n4) \"9\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u4e48\u5982\u4f55\u5b9e\u73b0\u5462\uff1f\u6211\u4eec\u5c06\u8ba2\u5355\u8d85\u65f6\u65f6\u95f4\u6233\u4e0e\u8ba2\u5355\u53f7\u5206\u522b\u8bbe\u7f6e\u4e3a score \u548c member\uff0c\u7cfb\u7edf\u626b\u63cf\u7b2c\u4e00\u4e2a\u5143\u7d20\u5224\u65ad\u662f\u5426\u8d85\u65f6\uff0c\u5177\u4f53\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd2.png\" alt=\"\u8ba2\u5355\u8d85\u65f6\u65f6\u95f4\u6233\u4e0e\u8ba2\u5355\u53f7\" \/><figcaption>\u8ba2\u5355\u8d85\u65f6\u65f6\u95f4\u6233\u4e0e\u8ba2\u5355\u53f7<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9e\u73b0\u4e00<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Calendar;\nimport java.util.Set;\nimport redis.clients.jedis.Jedis;\nimport redis.clients.jedis.JedisPool;\nimport redis.clients.jedis.Tuple;\n\npublic class AppTest {\n    private static final String ADDR = \"127.0.0.1\";\n    private static final int PORT = 6379;\n    private static JedisPool jedisPool = new JedisPool(ADDR, PORT);\n    public static Jedis getJedis() {\n       return jedisPool.getResource();\n    }\n\n    \/\/\u751f\u4ea7\u8005,\u751f\u62105\u4e2a\u8ba2\u5355\u653e\u8fdb\u53bb\n    public void productionDelayMessage(){\n        for(int i=0;i&lt;5;i++){\n            \/\/\u5ef6\u8fdf3\u79d2\n            Calendar cal1 = Calendar.getInstance();\n            cal1.add(Calendar.SECOND, 3);\n            int second3later = (int) (cal1.getTimeInMillis() \/ 1000);\n            AppTest.getJedis().zadd(\"OrderId\",second3later,\"OID0000001\"+i);\n            System.out.println(System.currentTimeMillis()+\"ms:redis\u751f\u6210\u4e86\u4e00\u4e2a\u8ba2\u5355\u4efb\u52a1\uff1a\u8ba2\u5355ID\u4e3a\"+\"OID0000001\"+i);\n        }\n    }\n\n    \/\/\u6d88\u8d39\u8005\uff0c\u53d6\u8ba2\u5355\n    public void consumerDelayMessage(){\n        Jedis jedis = AppTest.getJedis();\n        while(true){\n            Set&lt;Tuple&gt; items = jedis.zrangeWithScores(\"OrderId\", 0, 1);\n            if(items == null || items.isEmpty()){\n                System.out.println(\"\u5f53\u524d\u6ca1\u6709\u7b49\u5f85\u7684\u4efb\u52a1\");\n                try {\n                    Thread.sleep(500);\n                } catch (InterruptedException e) {\n                    \/\/ TODO Auto-generated catch block\n                    e.printStackTrace();\n                }\n                continue;\n            }\n\n            int  score = (int) ((Tuple)items.toArray()[0]).getScore();\n            Calendar cal = Calendar.getInstance();\n            int nowSecond = (int) (cal.getTimeInMillis() \/ 1000);\n            if(nowSecond &gt;= score){\n                String orderId = ((Tuple)items.toArray()[0]).getElement();\n                jedis.zrem(\"OrderId\", orderId);\n                System.out.println(System.currentTimeMillis() +\"ms:redis\u6d88\u8d39\u4e86\u4e00\u4e2a\u4efb\u52a1\uff1a\u6d88\u8d39\u7684\u8ba2\u5355OrderId\u4e3a\"+orderId);\n            }\n        }\n    }\n\n    public static void main(String[] args) {\n        AppTest appTest =new AppTest();\n        appTest.productionDelayMessage();\n        appTest.consumerDelayMessage();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u65f6\u5bf9\u5e94\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd3.png\" alt=\"\u6d88\u8d39\u8ba2\u5355\" \/><figcaption>\u6d88\u8d39\u8ba2\u5355<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\uff0c\u51e0\u4e4e\u90fd\u662f 3 \u79d2\u4e4b\u540e\uff0c\u6d88\u8d39\u8ba2\u5355\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u8fd9\u4e00\u7248\u5b58\u5728\u4e00\u4e2a\u81f4\u547d\u7684\u786c\u4f24\uff0c\u5728\u9ad8\u5e76\u53d1\u6761\u4ef6\u4e0b\uff0c\u591a\u6d88\u8d39\u8005\u4f1a\u53d6\u5230\u540c\u4e00\u4e2a\u8ba2\u5355\u53f7\uff0c\u6211\u4eec\u4e0a\u6d4b\u8bd5\u4ee3\u7801 ThreadTest\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.concurrent.CountDownLatch;\npublic class ThreadTest {\n    private static final int threadNum = 10;\n    private static CountDownLatch cdl = newCountDownLatch(threadNum);\n    static class DelayMessage implements Runnable{\n        public void run() {\n            try {\n                cdl.await();\n            } catch (InterruptedException e) {\n                \/\/ TODO Auto-generated catch block\n                e.printStackTrace();\n            }\n\n            AppTest appTest =new AppTest();\n            appTest.consumerDelayMessage();\n        }\n    }\n\n    public static void main(String[] args) {\n        AppTest appTest =new AppTest();\n        appTest.productionDelayMessage();\n        for(int i=0;i&lt;threadNum;i++){\n            new Thread(new DelayMessage()).start();\n            cdl.countDown();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd4.png\" alt=\"\u591a\u4e2a\u7ebf\u7a0b\u6d88\u8d39\u540c\u4e00\u4e2a\u8d44\u6e90\" \/><figcaption>\u591a\u4e2a\u7ebf\u7a0b\u6d88\u8d39\u540c\u4e00\u4e2a\u8d44\u6e90<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u663e\u7136\uff0c\u51fa\u73b0\u4e86\u591a\u4e2a\u7ebf\u7a0b\u6d88\u8d39\u540c\u4e00\u4e2a\u8d44\u6e90\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u7528\u5206\u5e03\u5f0f\u9501\uff0c\u4f46\u662f\u7528\u5206\u5e03\u5f0f\u9501\uff0c\u6027\u80fd\u4e0b\u964d\u4e86\uff0c\u8be5\u65b9\u6848\u4e0d\u7ec6\u8bf4\u3002<\/li><li>(2)\u5bf9 ZREM \u7684\u8fd4\u56de\u503c\u8fdb\u884c\u5224\u65ad\uff0c\u53ea\u6709\u5927\u4e8e 0 \u7684\u65f6\u5019\uff0c\u624d\u6d88\u8d39\u6570\u636e\uff0c\u4e8e\u662f\u5c06<code>consumerDelayMessage()<\/code>\u65b9\u6cd5\u4e2d\u7684\u5982\u4e0b\u4ee3\u7801\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>if(nowSecond &gt;= score){\n    String orderId = ((Tuple)items.toArray()[0]).getElement();\n    jedis.zrem(\"OrderId\", orderId);\n    System.out.println(System.currentTimeMillis()+\"ms:redis\u6d88\u8d39\u4e86\u4e00\u4e2a\u4efb\u52a1\uff1a\u6d88\u8d39\u7684\u8ba2\u5355OrderId\u4e3a\"+orderId);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(nowSecond &gt;= score){\n    String orderId = ((Tuple)items.toArray()[0]).getElement();\n    Long num = jedis.zrem(\"OrderId\", orderId);\n    if( num != null &amp;&amp; num&gt;0){\n        System.out.println(System.currentTimeMillis()+\"ms:redis\u6d88\u8d39\u4e86\u4e00\u4e2a\u4efb\u52a1\uff1a\u6d88\u8d39\u7684\u8ba2\u5355OrderId\u4e3a\"+orderId);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u79cd\u4fee\u6539\u540e\uff0c\u91cd\u65b0\u8fd0\u884c ThreadTest \u7c7b\uff0c\u53d1\u73b0\u8f93\u51fa\u6b63\u5e38\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\u601d\u8def\u4e8c<\/code>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u65b9\u6848\u4f7f\u7528 redis \u7684 Keyspace Notifications\uff0c\u4e2d\u6587\u7ffb\u8bd1\u5c31\u662f\u952e\u7a7a\u95f4\u673a\u5236\uff0c\u5c31\u662f\u5229\u7528\u8be5\u673a\u5236\u53ef\u4ee5\u5728 key \u5931\u6548\u4e4b\u540e\uff0c\u63d0\u4f9b\u4e00\u4e2a\u56de\u8c03\uff0c\u5b9e\u9645\u4e0a\u662f redis \u4f1a\u7ed9\u5ba2\u6237\u7aef\u53d1\u9001\u4e00\u4e2a\u6d88\u606f\u3002\u662f\u9700\u8981 redis \u7248\u672c 2.8 \u4ee5\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\u5b9e\u73b0\u4e8c<\/code>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 redis.conf \u4e2d\uff0c\u52a0\u5165\u4e00\u6761\u914d\u7f6e\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>notify-keyspace-events Ex\u275e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import redis.clients.jedis.Jedis;\nimport redis.clients.jedis.JedisPool;\nimport redis.clients.jedis.JedisPubSub;\n\npublic class RedisTest {\n    private static final String ADDR = \"127.0.0.1\";\n    private static final int PORT = 6379;\n    private static JedisPool jedis = new JedisPool(ADDR, PORT);\n    private static RedisSub sub = new RedisSub();\n\n    public static void init() {\n        new Thread(new Runnable() {\n            public void run() {\n                jedis.getResource().subscribe(sub, \"__keyevent@0__:expired\");\n            }\n        }).start();\n    }\n\n    public static void main(String[] args) throws InterruptedException {\n        init();\n\n        for(int i =0;i&lt;10;i++){\n            String orderId = \"OID000000\"+i;\n            jedis.getResource().setex(orderId, 3, orderId);\n            System.out.println(System.currentTimeMillis()+\"ms:\"+orderId+\"\u8ba2\u5355\u751f\u6210\");\n        }\n    }\n\n    static class RedisSub extends JedisPubSub {\n        @Override\n        public void onMessage(String channel, String message) {\n            System.out.println(System.currentTimeMillis()+\"ms:\"+message+\"\u8ba2\u5355\u53d6\u6d88\");\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/xmt1139057136\/xttblog\/2021\/08\/dd4.png\" alt=\"Redis\u952e\u7a7a\u95f4\u673a\u5236\" \/><figcaption>Redis\u952e\u7a7a\u95f4\u673a\u5236<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u660e\u663e\u770b\u5230 3 \u79d2\u8fc7\u540e\uff0c\u8ba2\u5355\u53d6\u6d88\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ps\uff1aredis \u7684<code>pub\/sub<\/code>\u673a\u5236\u5b58\u5728\u4e00\u4e2a\u786c\u4f24\uff0c\u5b98\u7f51\u5185\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>\u275d<\/strong><\/p><p>\u539f:Because Redis Pub\/Sub is fire and forget currently there is no way to use this feature if your application demands reliable notification of events, that is, if your Pub\/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost.<\/p><p>\u7ffb: Redis\u7684\u53d1\u5e03\/\u8ba2\u9605\u76ee\u524d\u662f\u5373\u53d1\u5373\u5f03(fire and forget)\u6a21\u5f0f\u7684\uff0c\u56e0\u6b64\u65e0\u6cd5\u5b9e\u73b0\u4e8b\u4ef6\u7684\u53ef\u9760\u901a\u77e5\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u53d1\u5e03\/\u8ba2\u9605\u7684\u5ba2\u6237\u7aef\u65ad\u94fe\u4e4b\u540e\u53c8\u91cd\u8fde\uff0c\u5219\u5728\u5ba2\u6237\u7aef\u65ad\u94fe\u671f\u95f4\u7684\u6240\u6709\u4e8b\u4ef6\u90fd\u4e22\u5931\u4e86\u3002<br>\n\u56e0\u6b64\uff0c\u65b9\u6848\u4e8c\u4e0d\u662f\u592a\u63a8\u8350\u3002\u5f53\u7136\uff0c\u5982\u679c\u4f60\u5bf9\u53ef\u9760\u6027\u8981\u6c42\u4e0d\u9ad8\uff0c\u53ef\u4ee5\u4f7f\u7528\u3002\u275e<\/p><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f18\u7f3a\u70b9<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u7531\u4e8e\u4f7f\u7528 Redis \u4f5c\u4e3a\u6d88\u606f\u901a\u9053\uff0c\u6d88\u606f\u90fd\u5b58\u50a8\u5728 Redis \u4e2d\u3002\u5982\u679c\u53d1\u9001\u7a0b\u5e8f\u6216\u8005\u4efb\u52a1\u5904\u7406\u7a0b\u5e8f\u6302\u4e86\uff0c\u91cd\u542f\u4e4b\u540e\uff0c\u8fd8\u6709\u91cd\u65b0\u5904\u7406\u6570\u636e\u7684\u53ef\u80fd\u6027\u3002<\/li><li>(2)\u505a\u96c6\u7fa4\u6269\u5c55\u76f8\u5f53\u65b9\u4fbf<\/li><li>(3)\u65f6\u95f4\u51c6\u786e\u5ea6\u9ad8<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>(1)\u9700\u8981\u989d\u5916\u8fdb\u884c redis \u7ef4\u62a4<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u6d88\u606f\u961f\u5217<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u53ef\u4ee5\u91c7\u7528 rabbitMQ \u7684\u5ef6\u65f6\u961f\u5217\u3002RabbitMQ \u5177\u6709\u4ee5\u4e0b\u4e24\u4e2a\u7279\u6027\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5ef6\u8fdf\u961f\u5217\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>RabbitMQ \u53ef\u4ee5\u9488\u5bf9 Queue \u548c Message \u8bbe\u7f6e x-message-tt\uff0c\u6765\u63a7\u5236\u6d88\u606f\u7684\u751f\u5b58\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u65f6\uff0c\u5219\u6d88\u606f\u53d8\u4e3a dead letter\u3002\n<\/li><li>lRabbitMQ \u7684 Queue \u53ef\u4ee5\u914d\u7f6e x-dead-letter-exchange \u548c x-dead-letter-routing-key\uff08\u53ef\u9009\uff09\u4e24\u4e2a\u53c2\u6570\uff0c\u7528\u6765\u63a7\u5236\u961f\u5217\u5185\u51fa\u73b0\u4e86 deadletter\uff0c\u5219\u6309\u7167\u8fd9\u4e24\u4e2a\u53c2\u6570\u91cd\u65b0\u8def\u7531\u3002\n<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed3\u5408\u4ee5\u4e0a\u4e24\u4e2a\u7279\u6027\uff0c\u5c31\u53ef\u4ee5\u6a21\u62df\u51fa\u5ef6\u8fdf\u6d88\u606f\u7684\u529f\u80fd\uff0c\u5177\u4f53\u7684\uff0c\u6211\u6539\u5929\u518d\u5199\u4e00\u7bc7\u6587\u7ae0\uff0c\u8fd9\u91cc\u518d\u8bb2\u4e0b\u53bb\uff0c\u7bc7\u5e45\u592a\u957f\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f18\u7f3a\u70b9<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9: <code>\u9ad8\u6548\uff0c\u53ef\u4ee5\u5229\u7528 rabbitmq \u7684\u5206\u5e03\u5f0f\u7279\u6027\u8f7b\u6613\u7684\u8fdb\u884c\u6a2a\u5411\u6269\u5c55\uff0c\u6d88\u606f\u652f\u6301\u6301\u4e45\u5316\u589e\u52a0\u4e86\u53ef\u9760\u6027<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9\uff1a<code>\u672c\u8eab\u7684\u6613\u7528\u5ea6\u8981\u4f9d\u8d56\u4e8e rabbitMq \u7684\u8fd0\u7ef4\u3002\u56e0\u4e3a\u8981\u5f15\u7528 rabbitMq\uff0c\u6240\u4ee5\u590d\u6742\u5ea6\u548c\u6210\u672c\u53d8\u9ad8<\/code>\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=5271\">\u7535\u5546\u7cfb\u7edf\u8ba2\u5355\u8d85\u65f6\u53d6\u6d88\u8ba2\u5355\u76845\u79cd\u5b9e\u73b0\u65b9\u6848\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eca\u5e74\u9762\u8bd5\u8fc7\u4e0d\u5c11 Java \u7a0b\u5e8f\u5458\uff0c\u521d\u7ea7\u7684\u3001\u4e2d\u7ea7\u7684\u3001\u9ad8\u7ea7\u7684\u90fd\u6709\u3002\u5f88\u591a\u5019\u9009\u8005\u7b80\u5386\u4e0a\u5199\u7740\u7cbe\u901a Redis\uff0cRabb [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[145,826,140,1541,1346],"class_list":["post-5271","post","type-post","status-publish","format-standard","hentry","category-java","tag-linkedblockingqueue","tag-quartz","tag-queue","tag-rocketmq","tag-1346"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5271"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5271\/revisions"}],"predecessor-version":[{"id":5272,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5271\/revisions\/5272"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}