{"id":4803,"date":"2020-02-18T14:51:49","date_gmt":"2020-02-18T06:51:49","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4803"},"modified":"2020-02-18T14:51:49","modified_gmt":"2020-02-18T06:51:49","slug":"webflux-%e4%b9%8b-flux-%e5%92%8c-mono-%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4803","title":{"rendered":"WebFlux \u4e4b Flux \u548c Mono \u5e38\u7528\u65b9\u6cd5\u603b\u7ed3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u53d1\u73b0\u8d8a\u6765\u8d8a\u591a\u7684\u7f51\u53cb\u518d\u4f7f\u7528 WebFlux\uff0c\u672c\u6587\u4ecb\u7ecd\u51e0\u4e2a Flux \u548c Mono \u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Reactor \u4e2d\uff0c\u6570\u636e\u6d41\u53d1\u5e03\u8005\uff08Publisher\uff09\u7531 Flux \u548c Mono \u4e24\u4e2a\u7c7b\u8868\u793a\uff0c\u5b83\u4eec\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u64cd\u4f5c\u7b26\uff08operator\uff09\u3002\u4e00\u4e2a Flux \u5bf9\u8c61\u4ee3\u8868\u4e00\u4e2a\u5305\u542b0\u4e2a\u6216\u591a\u4e2a\uff080..N\uff09\u5143\u7d20\u7684\u54cd\u5e94\u5f0f\u5e8f\u5217\uff0c\u800c\u4e00\u4e2a Mono \u5bf9\u8c61\u4ee3\u8868\u4e00\u4e2a\u5305\u542b0\u6216\u4e00\u4e2a\uff080..1\uff09\u5143\u7d20\u7684\u7ed3\u679c\u3002\u8fd9\u662f\u5b83\u4eec\u4e24\u8005\u4e4b\u95f4\u6700\u5927\u7684\u533a\u522b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u4eec\u4e5f\u6709\u4e00\u4e9b\u76f8\u540c\u7684\u65b9\u6cd5\u7528\u4e8e\u6784\u5efa\u6570\u636e\u6d41\uff0c\u4e0b\u9762\u7b80\u5355\u5217\u4e3e\u51e0\u4f8b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528 just \u521b\u5efa\u6570\u636e\u6d41<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Flux.just(520, 996, 997, 1024, 250, 888);\nMono.just(996);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u4e8e\u6570\u7ec4\u521b\u5efa\u6570\u636e\u6d41<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer[] array = new Integer[]{520, 996, 997, 1024, 250, 888};\nFlux.fromArray(array);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u4e8e\u96c6\u5408\u521b\u5efa\u6570\u636e\u6d41<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer[] array = new Integer[]{520, 996, 997, 1024, 250, 888};\nList&lt;Integer&gt; list = Arrays.asList(array);\nFlux.fromIterable(list);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u4e8e Stream \u521b\u5efa\u6570\u636e\u6d41<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer[] array = new Integer[]{1, 2, 3, 4, 5, 6};\nList&lt;Integer&gt; list = Arrays.asList(array);\nStream&lt;Integer&gt; stream = list.stream();\nFlux.fromStream(stream);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Flux \u548c Mono \u7684\u6570\u636e\u4fe1\u53f7<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Flux \u548c Mono \u90fd\u53ef\u4ee5\u53d1\u51fa\u4e09\u79cd\u6570\u636e\u4fe1\u53f7\uff0c\u4e0a\u6587\u4e2d\u63d0\u5230\u5143\u7d20\u503c\u3001\u9519\u8bef\u4fe1\u53f7\u548c\u5b8c\u6210\u4fe1\u53f7\u4e09\u8005\u5e76\u4e0d\u662f\u8981\u5b8c\u5168\u5177\u5907\u7684\uff0c\u4e0b\u9762\u5c31\u7ed9\u51fa\u51e0\u79cd\u60c5\u51b5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u53ea\u6709\u5b8c\u6210\u4fe1\u53f7\u7684\u7a7a\u6570\u636e\u6d41\nFlux.just();\nFlux.empty();\nMono.empty();\nMono.justOrEmpty(Optional.empty());\n\n\/\/ \u53ea\u6709\u9519\u8bef\u4fe1\u53f7\u7684\u6570\u636e\u6d41\nFlux.error(new Exception(\"some error\"));\nMono.error(new Exception(\"some error\")); <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Flux \u7684\u4e00\u4e9b\u7279\u6027\u5bfc\u81f4\u5b83\u5728\u5c01\u88c5\u4e00\u4e9b\u81ea\u5b9a\u4e49\u6d88\u606f\u4f53\u7684\u65f6\u5019\u6bd4\u8f83\u56f0\u96be\uff01<\/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=4803\">WebFlux \u4e4b Flux \u548c Mono \u5e38\u7528\u65b9\u6cd5\u603b\u7ed3<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u53d1\u73b0\u8d8a\u6765\u8d8a\u591a\u7684\u7f51\u53cb\u518d\u4f7f\u7528 WebFlux\uff0c\u672c\u6587\u4ecb\u7ecd\u51e0\u4e2a Flux \u548c Mono \u5e38\u7528\u7684\u65b9\u6cd5\u3002 \u5728 Reac [&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":[1710,1709,1711,1708,1701],"class_list":["post-4803","post","type-post","status-publish","format-standard","hentry","category-java","tag-flux","tag-mono","tag-reactor","tag-webfilter","tag-webflux"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4803","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=4803"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4803\/revisions"}],"predecessor-version":[{"id":4804,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4803\/revisions\/4804"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}