http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-site/blob/93c5936c/content/docs/best-practice-consumer/index.html ---------------------------------------------------------------------- diff --cc content/docs/best-practice-consumer/index.html index 94f4d0f,0000000..a27eaa7 mode 100644,000000..100644 --- a/content/docs/best-practice-consumer/index.html +++ b/content/docs/best-practice-consumer/index.html @@@ -1,641 -1,0 +1,641 @@@ +<!doctype html> +<html lang="en" class="no-js"> + <head> + <meta charset="utf-8"> + +<!-- begin SEO --> + + + + + + + + + +<title>Best Practice For Consumer - Apache RocketMQ</title> + + + + +<meta name="description" content="Some useful tips for users."> + + + + +<meta property="og:locale" content="en"> +<meta property="og:site_name" content="Apache RocketMQ"> +<meta property="og:title" content="Best Practice For Consumer"> + + + + + <meta property="og:description" content="Some useful tips for users."> + + + + <meta name="twitter:site" content="@ApacheRocketMQ"> + <meta name="twitter:title" content="Best Practice For Consumer"> + <meta name="twitter:description" content="Some useful tips for users."> + <meta name="twitter:url" content=""> + + + <meta name="twitter:card" content="summary"> + + + + + + + + + + + + + + + + <meta property="og:type" content="article"> - <meta property="article:published_time" content="2017-04-25T01:02:11+08:00"> ++ <meta property="article:published_time" content="2017-04-25T01:06:24+08:00"> + + + + + + + + + <script type="application/ld+json"> + { + "@context" : "http://schema.org", + "@type" : "Person", + "name" : "Apache RocketMQ", + "url" : null, + "sameAs" : null + } + </script> + + + + <meta name="google-site-verification" content="aand0XZkSGsziuC-UPD4ZJniFD0m0JhGx6820y2mAQY" /> + + + <meta name="baidu-site-verification" content="wD06EbDRkQ" /> + + + + +<!-- end SEO --> + + +<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="Apache RocketMQ Feed"> + +<!-- http://t.co/dKP3o1e --> +<meta name="HandheldFriendly" content="True"> +<meta name="MobileOptimized" content="320"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<script> + document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js '; +</script> + +<!-- For all browsers --> +<link rel="stylesheet" href="/assets/css/main.css"> + +<meta http-equiv="cleartype" content="on"> + <!-- start custom head snippets --> + +<!-- insert favicons. use http://realfavicongenerator.net/ --> + +<!-- end custom head snippets --> + </head> + + <body class="layout--single"> + + <!--[if lt IE 9]> +<div class="notice--danger align-center" style="margin: 0;">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</div> +<![endif]--> + <div class="masthead"> + <div class="masthead__inner-wrap"> + <div class="masthead__menu"> + <nav id="site-nav" class="greedy-nav"> + <button><div class="navicon"></div></button> + <ul class="visible-links"> + <li class="masthead__menu-item masthead__menu-item--lg"><a href="/">Apache RocketMQ</a></li> + + + <li class="masthead__menu-item"><a href="/docs/quick-start/">Documentation</a></li> + + + <li class="masthead__menu-item"><a href="/year-archive/">Blog</a></li> + + + <li class="masthead__menu-item"><a href="/community/">Community</a></li> + + + <li class="masthead__menu-item"><a href="/customer/">Customer</a></li> + + + <li class="masthead__menu-item"><a href="/about/team/">About</a></li> + + </ul> + <ul class="hidden-links hidden"></ul> + </nav> + </div> + </div> +</div> + + + + + +<div id="main" role="main"> + + <div class="sidebar sticky"> + + + + + + + + + + +<nav class="nav__list"> + + <input id="ac-toc" name="accordion-toc" type="checkbox" /> + <label for="ac-toc">Toggle Menu</label> + <ul class="nav__items"> + + <li> + + <span class="nav__sub-title">User Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/quick-start/" class="">Quick Start</a></li> + + + + + + + + <li><a href="/docs/motivation/" class="">Why RocketMQ</a></li> + + + + + + + + <li><a href="/docs/simple-example/" class="">Simple Example</a></li> + + + + + + + + <li><a href="/docs/order-example/" class="">Order Example</a></li> + + + + + + + + <li><a href="/docs/broadcast-example/" class="">Broadcasting Example</a></li> + + + + + + + + <li><a href="/docs/schedule-example/" class="">Schedule Example</a></li> + + + + + + + + <li><a href="/docs/batch-example/" class="">Batch Example</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Deployment & Operations</span> + + + + <ul> + + + + + + + + <li><a href="/docs/rmq-arc/" class="">Architecture</a></li> + + + + + + + + <li><a href="/docs/rmq-deployment/" class="">Deployment</a></li> + + + + + + + + <li><a href="/docs/cli-admin-tool/" class="">CLI Admin Tool</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Contributor Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/code-guidelines/" class="">Code Guidelines</a></li> + + + + + + + + <li><a href="/docs/pull-request/" class="">Pull Request</a></li> + + + + + + + + <li><a href="/docs/release-manual" class="">Release Manual</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Best Practice</span> + + + + <ul> + + + + + + + + <li><a href="/docs/core-concept/" class="">Core Concept</a></li> + + + + + + + + <li><a href="/docs/best-practice-broker/" class="">Broker</a></li> + + + + + + + + <li><a href="/docs/best-practice-producer/" class="">Producer</a></li> + + + + + + + + <li><a href="/docs/best-practice-consumer/" class="active">Consumer</a></li> + + + + + + + + <li><a href="/docs/best-practice-namesvr/" class="">NameServer</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Release Notes</span> + + + + <ul> + + + + + + + + <li><a href="/dowloading/releases/" class="">Download</a></li> + + + + + + + + <li><a href="/release_notes/release-notes-4.0.0-incubating/" class="">4.0.0-incubating</a></li> + + </ul> + + </li> + + <li> + + + + + <a href="/docs/roadmap/"><span class="nav__sub-title">RoadMap</span></a> + + + + </li> + + <li> + + + + + <a href="/docs/faq/"><span class="nav__sub-title">FAQ</span></a> + + + + </li> + + </ul> +</nav> + + + </div> + + + <article class="page" itemscope itemtype="http://schema.org/CreativeWork"> + <meta itemprop="headline" content="Best Practice For Consumer"> + <meta itemprop="description" content="Some useful tips for users."> + <meta itemprop="datePublished" content="April 25, 2017"> + <meta itemprop="dateModified" content="December 25, 2016"> + + <div class="page__inner-wrap"> + + <header> + <h1 class="page__title" itemprop="headline">Best Practice For Consumer +</h1> + + </header> + + + <section class="page__content" itemprop="text"> + <p>Some useful tips for users.</p> + +<aside class="sidebar__right"> +<nav class="toc"> + <header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header> +<ul class="toc__menu" id="markdown-toc"> + <li><a href="#consumer-group-and-subscriptions" id="markdown-toc-consumer-group-and-subscriptions">Consumer Group and Subscriptions</a></li> + <li><a href="#messagelistener" id="markdown-toc-messagelistener">MessageListener</a> <ul> + <li><a href="#orderly" id="markdown-toc-orderly">Orderly</a></li> + <li><a href="#concurrently" id="markdown-toc-concurrently">Concurrently</a></li> + <li><a href="#consume-status" id="markdown-toc-consume-status">Consume Status</a></li> + <li><a href="#blocking" id="markdown-toc-blocking">Blocking</a></li> + </ul> + </li> + <li><a href="#thread-number" id="markdown-toc-thread-number">Thread Number</a></li> + <li><a href="#consumefromwhere" id="markdown-toc-consumefromwhere">ConsumeFromWhere</a></li> + <li><a href="#duplication" id="markdown-toc-duplication">Duplication</a></li> +</ul> + + </nav> +</aside> +<h2 id="consumer-group-and-subscriptions">Consumer Group and Subscriptions</h2> +<p>The first thing you should be aware of is that different Consumer Group can consume the same topic independently, each of the group will have their own consuming offsets. +And make sure each Consumer within the same Group to subscribe the same topics.</p> +<h2 id="messagelistener">MessageListener</h2> +<h3 id="orderly">Orderly</h3> +<p>The Consumer will lock each MessageQueue to make sure it is consumed one by one orderly. This will cause performance loss, but it is useful when you are care about the order of the messages. +It is not recommended to throw exception, you can return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT instead.</p> +<h3 id="concurrently">Concurrently</h3> +<p>As the name tells, the Consumer will consume the messages concurrently. It is recommended to use this for achieving good performance. +It is not recommended to throw exception, you can return ConsumeConcurrentlyStatus.RECONSUME_LATER instead.</p> +<h3 id="consume-status">Consume Status</h3> +<p>For MessageListenerConcurrently, you can return RECONSUME_LATER to tell the consumer that you can not consume it right now and want to reconsume it later. Then you can continue to consume other messages. +For MessageListenerOrderly, as that you care about the order, so you can not jump over the message, but you can return SUSPEND_CURRENT_QUEUE_A_MOMENT to tell the consumer to hold on for a moment.</p> +<h3 id="blocking">Blocking</h3> +<p>It is not recommend to block the Listener, for in return it will block the thread pool, and finally the consuming process may get stuck.</p> +<h2 id="thread-number">Thread Number</h2> +<p>The consumer use a ThreadPoolExecutor to process consuming internally. So you can tune it by using setConsumeThreadMin or setConsumeThreadMax.</p> +<h2 id="consumefromwhere">ConsumeFromWhere</h2> +<p>When a new Consumer Group is established, it will need to decide whether it need to consume the historical messages which had already existed in the Broker. +CONSUME_FROM_LAST_OFFSET will ignore the historical messages, and consume any newly produced. +CONSUME_FROM_FIRST_OFFSET will consume every message existed in the Broker. +You can also use CONSUME_FROM_TIMESTAMP to consume messages produced after the specified timestamp.</p> +<h2 id="duplication">Duplication</h2> +<p>Many circumstances could cause duplication, such as:</p> +<ul> + <li>Producer resend messages(i.e, in case of FLUSH_SLAVE_TIMEOUT)</li> + <li>Consumer shutdown with some offsets not updated to the Broker in time.</li> +</ul> + +<p>So you may need to do some external work to handle this if your application cannot tolerate. For example, you may check the primary key of your DB.</p> + + + + </section> + + <footer class="page__meta"> + + + + + + <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> Updated:</strong> <time datetime="2016-12-25">December 25, 2016</time></p> + + </footer> + + <section class="page__share"> + + <h4 class="page__share-title">Share on</h4> + + + <a href="https://twitter.com/intent/tweet?via=ApacheRocketMQ&text=Best Practice For Consumer /docs/best-practice-consumer/" class="btn btn--twitter" title="Share on Twitter"><i class="fa fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a> + + <a href="https://www.facebook.com/sharer/sharer.php?u=/docs/best-practice-consumer/" class="btn btn--facebook" title="Share on Facebook"><i class="fa fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a> + + <a href="https://plus.google.com/share?url=/docs/best-practice-consumer/" class="btn btn--google-plus" title="Share on Google Plus"><i class="fa fa-fw fa-google-plus" aria-hidden="true"></i><span> Google+</span></a> + + <a href="https://www.linkedin.com/shareArticle?mini=true&url=/docs/best-practice-consumer/" class="btn btn--linkedin" title="Share on LinkedIn"><i class="fa fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a> +</section> + + + + <nav class="pagination"> + + <a href="/docs/best-practice-broker/" class="pagination--pager" title="Best Practice For Broker +">Previous</a> + + + <a href="/docs/best-practice-namesvr/" class="pagination--pager" title="Best Practice For NameServer +">Next</a> + + </nav> + + </div> + + + <div class="page__comments"> + + + <h4 class="page__comments-title">Leave a Comment</h4> + <section id="disqus_thread"></section> + +</div> + + </article> + + + +</div> + + <div class="page__footer"> + <footer> + <!-- start custom footer snippets --> + +<!-- end custom footer snippets --> + <style type="text/css"> + div.columns { float: left; margin-left: 10px;} + div.clear { clear: both; } +</style> +<div> + <div class="columns"> + <a href="https://www.apache.org/"><img src="/assets/images/feather-small.gif" alt="Apache Software Foundation" style="height: 88px !important" /></a> + </div> + <div class="columns" style="width: 80%"> + <div class="page__footer-follow"> + <ul class="social-icons"> + + <li><strong>Follow:</strong></li> + + + <li><a href="https://twitter.com/ApacheRocketMQ"><i class="fa fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li> + + + + <li><a href="http://github.com/apache/incubator-rocketmq"><i class="fa fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li> + + + <li><a href="/feed.xml"><i class="fa fa-fw fa-rss-square" aria-hidden="true"></i> Feed</a></li> + </ul> + </div> + + <div class="page__footer-copyright">Copyright © 2017 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</div> + </div> +</div> +<div class="clear"></div> + </footer> + </div> + + <script src="/assets/js/main.min.js"></script> + + + + + <script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-89603173-1', 'auto'); + ga('send', 'pageview'); +</script> + +<script> +var _hmt = _hmt || []; +(function() { + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?36428f2b841d08e7405724cbf7f860d2"; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); +})(); +</script> + + + + + + <script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'rocketmq'; + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function () { + var s = document.createElement('script'); s.async = true; + s.type = 'text/javascript'; + s.src = '//' + disqus_shortname + '.disqus.com/count.js'; + (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); + }()); + </script> + <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> + + + + + + + </body> +</html>
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-site/blob/93c5936c/content/docs/best-practice-namesvr/index.html ---------------------------------------------------------------------- diff --cc content/docs/best-practice-namesvr/index.html index c69bc61,0000000..0f663aa mode 100644,000000..100644 --- a/content/docs/best-practice-namesvr/index.html +++ b/content/docs/best-practice-namesvr/index.html @@@ -1,677 -1,0 +1,677 @@@ +<!doctype html> +<html lang="en" class="no-js"> + <head> + <meta charset="utf-8"> + +<!-- begin SEO --> + + + + + + + + + +<title>Best Practice For NameServer - Apache RocketMQ</title> + + + + +<meta name="description" content="In Apache RocketMQ, name servers are designed to coordinate each component of the distributed systemand fulfill much of this responsibility through managing topic route information."> + + + + +<meta property="og:locale" content="en"> +<meta property="og:site_name" content="Apache RocketMQ"> +<meta property="og:title" content="Best Practice For NameServer"> + + + + + <meta property="og:description" content="In Apache RocketMQ, name servers are designed to coordinate each component of the distributed systemand fulfill much of this responsibility through managing topic route information."> + + + + <meta name="twitter:site" content="@ApacheRocketMQ"> + <meta name="twitter:title" content="Best Practice For NameServer"> + <meta name="twitter:description" content="In Apache RocketMQ, name servers are designed to coordinate each component of the distributed systemand fulfill much of this responsibility through managing topic route information."> + <meta name="twitter:url" content=""> + + + <meta name="twitter:card" content="summary"> + + + + + + + + + + + + + + + + <meta property="og:type" content="article"> - <meta property="article:published_time" content="2017-04-25T01:02:11+08:00"> ++ <meta property="article:published_time" content="2017-04-25T01:06:24+08:00"> + + + + + + + + + <script type="application/ld+json"> + { + "@context" : "http://schema.org", + "@type" : "Person", + "name" : "Apache RocketMQ", + "url" : null, + "sameAs" : null + } + </script> + + + + <meta name="google-site-verification" content="aand0XZkSGsziuC-UPD4ZJniFD0m0JhGx6820y2mAQY" /> + + + <meta name="baidu-site-verification" content="wD06EbDRkQ" /> + + + + +<!-- end SEO --> + + +<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="Apache RocketMQ Feed"> + +<!-- http://t.co/dKP3o1e --> +<meta name="HandheldFriendly" content="True"> +<meta name="MobileOptimized" content="320"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<script> + document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js '; +</script> + +<!-- For all browsers --> +<link rel="stylesheet" href="/assets/css/main.css"> + +<meta http-equiv="cleartype" content="on"> + <!-- start custom head snippets --> + +<!-- insert favicons. use http://realfavicongenerator.net/ --> + +<!-- end custom head snippets --> + </head> + + <body class="layout--single"> + + <!--[if lt IE 9]> +<div class="notice--danger align-center" style="margin: 0;">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</div> +<![endif]--> + <div class="masthead"> + <div class="masthead__inner-wrap"> + <div class="masthead__menu"> + <nav id="site-nav" class="greedy-nav"> + <button><div class="navicon"></div></button> + <ul class="visible-links"> + <li class="masthead__menu-item masthead__menu-item--lg"><a href="/">Apache RocketMQ</a></li> + + + <li class="masthead__menu-item"><a href="/docs/quick-start/">Documentation</a></li> + + + <li class="masthead__menu-item"><a href="/year-archive/">Blog</a></li> + + + <li class="masthead__menu-item"><a href="/community/">Community</a></li> + + + <li class="masthead__menu-item"><a href="/customer/">Customer</a></li> + + + <li class="masthead__menu-item"><a href="/about/team/">About</a></li> + + </ul> + <ul class="hidden-links hidden"></ul> + </nav> + </div> + </div> +</div> + + + + + +<div id="main" role="main"> + + <div class="sidebar sticky"> + + + + + + + + + + +<nav class="nav__list"> + + <input id="ac-toc" name="accordion-toc" type="checkbox" /> + <label for="ac-toc">Toggle Menu</label> + <ul class="nav__items"> + + <li> + + <span class="nav__sub-title">User Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/quick-start/" class="">Quick Start</a></li> + + + + + + + + <li><a href="/docs/motivation/" class="">Why RocketMQ</a></li> + + + + + + + + <li><a href="/docs/simple-example/" class="">Simple Example</a></li> + + + + + + + + <li><a href="/docs/order-example/" class="">Order Example</a></li> + + + + + + + + <li><a href="/docs/broadcast-example/" class="">Broadcasting Example</a></li> + + + + + + + + <li><a href="/docs/schedule-example/" class="">Schedule Example</a></li> + + + + + + + + <li><a href="/docs/batch-example/" class="">Batch Example</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Deployment & Operations</span> + + + + <ul> + + + + + + + + <li><a href="/docs/rmq-arc/" class="">Architecture</a></li> + + + + + + + + <li><a href="/docs/rmq-deployment/" class="">Deployment</a></li> + + + + + + + + <li><a href="/docs/cli-admin-tool/" class="">CLI Admin Tool</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Contributor Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/code-guidelines/" class="">Code Guidelines</a></li> + + + + + + + + <li><a href="/docs/pull-request/" class="">Pull Request</a></li> + + + + + + + + <li><a href="/docs/release-manual" class="">Release Manual</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Best Practice</span> + + + + <ul> + + + + + + + + <li><a href="/docs/core-concept/" class="">Core Concept</a></li> + + + + + + + + <li><a href="/docs/best-practice-broker/" class="">Broker</a></li> + + + + + + + + <li><a href="/docs/best-practice-producer/" class="">Producer</a></li> + + + + + + + + <li><a href="/docs/best-practice-consumer/" class="">Consumer</a></li> + + + + + + + + <li><a href="/docs/best-practice-namesvr/" class="active">NameServer</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Release Notes</span> + + + + <ul> + + + + + + + + <li><a href="/dowloading/releases/" class="">Download</a></li> + + + + + + + + <li><a href="/release_notes/release-notes-4.0.0-incubating/" class="">4.0.0-incubating</a></li> + + </ul> + + </li> + + <li> + + + + + <a href="/docs/roadmap/"><span class="nav__sub-title">RoadMap</span></a> + + + + </li> + + <li> + + + + + <a href="/docs/faq/"><span class="nav__sub-title">FAQ</span></a> + + + + </li> + + </ul> +</nav> + + + </div> + + + <article class="page" itemscope itemtype="http://schema.org/CreativeWork"> + <meta itemprop="headline" content="Best Practice For NameServer"> + <meta itemprop="description" content="In Apache RocketMQ, name servers are designed to coordinate each component of the distributed systemand fulfill much of this responsibility through managing topic route information."> + <meta itemprop="datePublished" content="April 25, 2017"> + <meta itemprop="dateModified" content="December 25, 2016"> + + <div class="page__inner-wrap"> + + <header> + <h1 class="page__title" itemprop="headline">Best Practice For NameServer +</h1> + + </header> + + + <section class="page__content" itemprop="text"> + <p>In Apache RocketMQ, name servers are designed to coordinate each component of the distributed system +and fulfill much of this responsibility through managing topic route information.</p> + +<aside class="sidebar__right"> +<nav class="toc"> + <header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header> +<ul class="toc__menu" id="markdown-toc"> + <li><a href="#programmatic-way" id="markdown-toc-programmatic-way">Programmatic Way</a></li> + <li><a href="#java-options" id="markdown-toc-java-options">Java Options</a></li> + <li><a href="#environment-variable" id="markdown-toc-environment-variable">Environment Variable</a></li> + <li><a href="#http-endpoint" id="markdown-toc-http-endpoint">HTTP Endpoint</a></li> + <li><a href="#priority" id="markdown-toc-priority">Priority</a></li> +</ul> + + </nav> +</aside> + +<p>The management, roughly speaking, consists two parts:</p> +<ul> + <li>Brokers periodically renew meta data, including topics they have, which are kept in every name servers.</li> + <li>Name servers are serving clients, including producers, consumers and command line clients with the latest routing information.</li> +</ul> + +<p>Therefore, before launching brokers and clients, we need to tell them how to reach name servers by feeding them with a name server address list. +In Apache RocketMQ, this can be done in four ways.</p> + +<h2 id="programmatic-way">Programmatic Way</h2> + +<p>For broker, we may specify <code class="highlighter-rouge">namesrvAddr=name-server-ip1:port;name-server-ip2:port</code> in broker configuration file.</p> + +<p>For producers and consumers, we may feed name server address list to them as follows:</p> + +<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">DefaultMQProducer</span> <span class="n">producer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultMQProducer</span><span class="o">(</span><span class="s">"please_rename_unique_group_name"</span><span class="o">);</span> +<span class="n">producer</span><span class="o">.</span><span class="na">setNamesrvAddr</span><span class="o">(</span><span class="s">"name-server1-ip:port;name-server2-ip:port"</span><span class="o">);</span> + +<span class="n">DefaultMQPushConsumer</span> <span class="n">consumer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultMQPushConsumer</span><span class="o">(</span><span class="s">"please_rename_unique_group_name"</span><span class="o">);</span> +<span class="n">consumer</span><span class="o">.</span><span class="na">setNamesrvAddr</span><span class="o">(</span><span class="s">"name-server1-ip:port;name-server2-ip:port"</span><span class="o">);</span> +</code></pre> +</div> + +<p>If you use admin command line from shell, you may specify this way:</p> + +<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">sh</span> <span class="n">mqadmin</span> <span class="n">command</span><span class="o">-</span><span class="n">name</span> <span class="o">-</span><span class="n">n</span> <span class="n">name</span><span class="o">-</span><span class="n">server</span><span class="o">-</span><span class="nl">ip1:</span><span class="n">port</span><span class="o">;</span><span class="n">name</span><span class="o">-</span><span class="n">server</span><span class="o">-</span><span class="nl">ip2:</span><span class="n">port</span> <span class="o">-</span><span class="n">X</span> <span class="n">OTHER</span><span class="o">-</span><span class="n">OPTION</span> +</code></pre> +</div> + +<p>a simple example is: +<code class="highlighter-rouge">sh mqadmin -n localhost:9876 clusterList</code> +assuming to query cluster info on the name server node.</p> + +<p>If integrating admin tool into your own dashboard, you may</p> + +<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">DefaultMQAdminExt</span> <span class="n">defaultMQAdminExt</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultMQAdminExt</span><span class="o">(</span><span class="s">"please_rename_unique_group_name"</span><span class="o">);</span> +<span class="n">defaultMQAdminExt</span><span class="o">.</span><span class="na">setNamesrvAddr</span><span class="o">(</span><span class="s">"name-server1-ip:port;name-server2-ip:port"</span><span class="o">);</span> +</code></pre> +</div> + +<h2 id="java-options">Java Options</h2> + +<p>Name server address list may also be fed to your application through specifying the sequel java option +<code class="highlighter-rouge">rocketmq.namesrv.addr</code> before launching.</p> + +<h2 id="environment-variable">Environment Variable</h2> + +<p>You can export <code class="highlighter-rouge">NAMESRV_ADDR</code> environment variable. Brokers and clients will examine and use its value if set.</p> + +<h2 id="http-endpoint">HTTP Endpoint</h2> + +<p>If you do not specify name server address list using previously mentioned methods, Apache RocketMQ will access + the following HTTP end point to acquire and update name server address list every two minutes with initial delay of + ten seconds.</p> + +<p>On default, the end point is:</p> + +<p><code class="highlighter-rouge">http://jmenv.tbsite.net:8080/rocketmq/nsaddr</code></p> + +<p>You may override <code class="highlighter-rouge">jmenv.tbsite.net</code> by this java option: <code class="highlighter-rouge">rocketmq.namesrv.domain</code>, +You may also override <code class="highlighter-rouge">nsaddr</code> part by this java option: <code class="highlighter-rouge">rocketmq.namesrv.domain.subgroup</code></p> + +<p>If you are running Apache RocketMQ in production, this method is recommended because it gives you maximum flexibility + â you can dynamically add or remove name server nodes without necessity of rebooting your brokers and clients + according to your name serversâ system load.</p> + +<h2 id="priority">Priority</h2> + +<p>Methods introduced first take precedence over the latter, namely, <br /> +<code class="highlighter-rouge">Programmatic Way > Java Options > Environment Variable > HTTP Endpoint</code></p> + + + + </section> + + <footer class="page__meta"> + + + + + + <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> Updated:</strong> <time datetime="2016-12-25">December 25, 2016</time></p> + + </footer> + + <section class="page__share"> + + <h4 class="page__share-title">Share on</h4> + + + <a href="https://twitter.com/intent/tweet?via=ApacheRocketMQ&text=Best Practice For NameServer /docs/best-practice-namesvr/" class="btn btn--twitter" title="Share on Twitter"><i class="fa fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a> + + <a href="https://www.facebook.com/sharer/sharer.php?u=/docs/best-practice-namesvr/" class="btn btn--facebook" title="Share on Facebook"><i class="fa fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a> + + <a href="https://plus.google.com/share?url=/docs/best-practice-namesvr/" class="btn btn--google-plus" title="Share on Google Plus"><i class="fa fa-fw fa-google-plus" aria-hidden="true"></i><span> Google+</span></a> + + <a href="https://www.linkedin.com/shareArticle?mini=true&url=/docs/best-practice-namesvr/" class="btn btn--linkedin" title="Share on LinkedIn"><i class="fa fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a> +</section> + + + + <nav class="pagination"> + + <a href="/docs/best-practice-consumer/" class="pagination--pager" title="Best Practice For Consumer +">Previous</a> + + + <a href="/docs/best-practice-producer/" class="pagination--pager" title="Best Practice For Producer +">Next</a> + + </nav> + + </div> + + + <div class="page__comments"> + + + <h4 class="page__comments-title">Leave a Comment</h4> + <section id="disqus_thread"></section> + +</div> + + </article> + + + +</div> + + <div class="page__footer"> + <footer> + <!-- start custom footer snippets --> + +<!-- end custom footer snippets --> + <style type="text/css"> + div.columns { float: left; margin-left: 10px;} + div.clear { clear: both; } +</style> +<div> + <div class="columns"> + <a href="https://www.apache.org/"><img src="/assets/images/feather-small.gif" alt="Apache Software Foundation" style="height: 88px !important" /></a> + </div> + <div class="columns" style="width: 80%"> + <div class="page__footer-follow"> + <ul class="social-icons"> + + <li><strong>Follow:</strong></li> + + + <li><a href="https://twitter.com/ApacheRocketMQ"><i class="fa fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li> + + + + <li><a href="http://github.com/apache/incubator-rocketmq"><i class="fa fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li> + + + <li><a href="/feed.xml"><i class="fa fa-fw fa-rss-square" aria-hidden="true"></i> Feed</a></li> + </ul> + </div> + + <div class="page__footer-copyright">Copyright © 2017 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</div> + </div> +</div> +<div class="clear"></div> + </footer> + </div> + + <script src="/assets/js/main.min.js"></script> + + + + + <script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-89603173-1', 'auto'); + ga('send', 'pageview'); +</script> + +<script> +var _hmt = _hmt || []; +(function() { + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?36428f2b841d08e7405724cbf7f860d2"; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); +})(); +</script> + + + + + + <script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'rocketmq'; + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function () { + var s = document.createElement('script'); s.async = true; + s.type = 'text/javascript'; + s.src = '//' + disqus_shortname + '.disqus.com/count.js'; + (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); + }()); + </script> + <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> + + + + + + + </body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-site/blob/93c5936c/content/docs/best-practice-producer/index.html ---------------------------------------------------------------------- diff --cc content/docs/best-practice-producer/index.html index f1078f3,0000000..d6ba729 mode 100644,000000..100644 --- a/content/docs/best-practice-producer/index.html +++ b/content/docs/best-practice-producer/index.html @@@ -1,649 -1,0 +1,649 @@@ +<!doctype html> +<html lang="en" class="no-js"> + <head> + <meta charset="utf-8"> + +<!-- begin SEO --> + + + + + + + + + +<title>Best Practice For Producer - Apache RocketMQ</title> + + + + +<meta name="description" content="Some useful tips for users."> + + + + +<meta property="og:locale" content="en"> +<meta property="og:site_name" content="Apache RocketMQ"> +<meta property="og:title" content="Best Practice For Producer"> + + + + + <meta property="og:description" content="Some useful tips for users."> + + + + <meta name="twitter:site" content="@ApacheRocketMQ"> + <meta name="twitter:title" content="Best Practice For Producer"> + <meta name="twitter:description" content="Some useful tips for users."> + <meta name="twitter:url" content=""> + + + <meta name="twitter:card" content="summary"> + + + + + + + + + + + + + + + + <meta property="og:type" content="article"> - <meta property="article:published_time" content="2017-04-25T01:02:11+08:00"> ++ <meta property="article:published_time" content="2017-04-25T01:06:24+08:00"> + + + + + + + + + <script type="application/ld+json"> + { + "@context" : "http://schema.org", + "@type" : "Person", + "name" : "Apache RocketMQ", + "url" : null, + "sameAs" : null + } + </script> + + + + <meta name="google-site-verification" content="aand0XZkSGsziuC-UPD4ZJniFD0m0JhGx6820y2mAQY" /> + + + <meta name="baidu-site-verification" content="wD06EbDRkQ" /> + + + + +<!-- end SEO --> + + +<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="Apache RocketMQ Feed"> + +<!-- http://t.co/dKP3o1e --> +<meta name="HandheldFriendly" content="True"> +<meta name="MobileOptimized" content="320"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<script> + document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js '; +</script> + +<!-- For all browsers --> +<link rel="stylesheet" href="/assets/css/main.css"> + +<meta http-equiv="cleartype" content="on"> + <!-- start custom head snippets --> + +<!-- insert favicons. use http://realfavicongenerator.net/ --> + +<!-- end custom head snippets --> + </head> + + <body class="layout--single"> + + <!--[if lt IE 9]> +<div class="notice--danger align-center" style="margin: 0;">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</div> +<![endif]--> + <div class="masthead"> + <div class="masthead__inner-wrap"> + <div class="masthead__menu"> + <nav id="site-nav" class="greedy-nav"> + <button><div class="navicon"></div></button> + <ul class="visible-links"> + <li class="masthead__menu-item masthead__menu-item--lg"><a href="/">Apache RocketMQ</a></li> + + + <li class="masthead__menu-item"><a href="/docs/quick-start/">Documentation</a></li> + + + <li class="masthead__menu-item"><a href="/year-archive/">Blog</a></li> + + + <li class="masthead__menu-item"><a href="/community/">Community</a></li> + + + <li class="masthead__menu-item"><a href="/customer/">Customer</a></li> + + + <li class="masthead__menu-item"><a href="/about/team/">About</a></li> + + </ul> + <ul class="hidden-links hidden"></ul> + </nav> + </div> + </div> +</div> + + + + + +<div id="main" role="main"> + + <div class="sidebar sticky"> + + + + + + + + + + +<nav class="nav__list"> + + <input id="ac-toc" name="accordion-toc" type="checkbox" /> + <label for="ac-toc">Toggle Menu</label> + <ul class="nav__items"> + + <li> + + <span class="nav__sub-title">User Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/quick-start/" class="">Quick Start</a></li> + + + + + + + + <li><a href="/docs/motivation/" class="">Why RocketMQ</a></li> + + + + + + + + <li><a href="/docs/simple-example/" class="">Simple Example</a></li> + + + + + + + + <li><a href="/docs/order-example/" class="">Order Example</a></li> + + + + + + + + <li><a href="/docs/broadcast-example/" class="">Broadcasting Example</a></li> + + + + + + + + <li><a href="/docs/schedule-example/" class="">Schedule Example</a></li> + + + + + + + + <li><a href="/docs/batch-example/" class="">Batch Example</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Deployment & Operations</span> + + + + <ul> + + + + + + + + <li><a href="/docs/rmq-arc/" class="">Architecture</a></li> + + + + + + + + <li><a href="/docs/rmq-deployment/" class="">Deployment</a></li> + + + + + + + + <li><a href="/docs/cli-admin-tool/" class="">CLI Admin Tool</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Contributor Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/code-guidelines/" class="">Code Guidelines</a></li> + + + + + + + + <li><a href="/docs/pull-request/" class="">Pull Request</a></li> + + + + + + + + <li><a href="/docs/release-manual" class="">Release Manual</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Best Practice</span> + + + + <ul> + + + + + + + + <li><a href="/docs/core-concept/" class="">Core Concept</a></li> + + + + + + + + <li><a href="/docs/best-practice-broker/" class="">Broker</a></li> + + + + + + + + <li><a href="/docs/best-practice-producer/" class="active">Producer</a></li> + + + + + + + + <li><a href="/docs/best-practice-consumer/" class="">Consumer</a></li> + + + + + + + + <li><a href="/docs/best-practice-namesvr/" class="">NameServer</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Release Notes</span> + + + + <ul> + + + + + + + + <li><a href="/dowloading/releases/" class="">Download</a></li> + + + + + + + + <li><a href="/release_notes/release-notes-4.0.0-incubating/" class="">4.0.0-incubating</a></li> + + </ul> + + </li> + + <li> + + + + + <a href="/docs/roadmap/"><span class="nav__sub-title">RoadMap</span></a> + + + + </li> + + <li> + + + + + <a href="/docs/faq/"><span class="nav__sub-title">FAQ</span></a> + + + + </li> + + </ul> +</nav> + + + </div> + + + <article class="page" itemscope itemtype="http://schema.org/CreativeWork"> + <meta itemprop="headline" content="Best Practice For Producer"> + <meta itemprop="description" content="Some useful tips for users."> + <meta itemprop="datePublished" content="April 25, 2017"> + <meta itemprop="dateModified" content="December 25, 2016"> + + <div class="page__inner-wrap"> + + <header> + <h1 class="page__title" itemprop="headline">Best Practice For Producer +</h1> + + </header> + + + <section class="page__content" itemprop="text"> + <p>Some useful tips for users.</p> + +<aside class="sidebar__right"> +<nav class="toc"> + <header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header> +<ul class="toc__menu" id="markdown-toc"> + <li><a href="#sendstatus" id="markdown-toc-sendstatus">SendStatus</a> <ul> + <li><a href="#flush_disk_timeout" id="markdown-toc-flush_disk_timeout">FLUSH_DISK_TIMEOUT</a></li> + <li><a href="#flush_slave_timeout" id="markdown-toc-flush_slave_timeout">FLUSH_SLAVE_TIMEOUT</a></li> + <li><a href="#slave_not_available" id="markdown-toc-slave_not_available">SLAVE_NOT_AVAILABLE</a></li> + <li><a href="#send_ok" id="markdown-toc-send_ok">SEND_OK</a></li> + <li><a href="#duplication-or-missing" id="markdown-toc-duplication-or-missing">Duplication or Missing</a></li> + </ul> + </li> + <li><a href="#timeout" id="markdown-toc-timeout">Timeout</a></li> + <li><a href="#message-size" id="markdown-toc-message-size">Message Size</a></li> + <li><a href="#async-sending" id="markdown-toc-async-sending">Async Sending</a></li> + <li><a href="#producer-group" id="markdown-toc-producer-group">Producer Group</a></li> + <li><a href="#thread-safety" id="markdown-toc-thread-safety">Thread Safety</a></li> + <li><a href="#performance" id="markdown-toc-performance">Performance</a></li> +</ul> + + </nav> +</aside> + +<h2 id="sendstatus">SendStatus</h2> +<p>When sending a message, you will get SendResult and it will contain the SendStatus. Firstly, we assume that Messageâs isWaitStoreMsgOK=true(default is true). If not, we will always get SEND_OK if no exception is thrown. +Follow are the descriptions about each status.</p> +<h3 id="flush_disk_timeout">FLUSH_DISK_TIMEOUT</h3> +<p>If the Broker set MessageStoreConfigâs FlushDiskType=SYNC_FLUSH(default is ASYNC_FLUSH), and the Broker dose not finish flushing disk within MessageStoreConfigâs syncFlushTimeout(default is 5 secs), you will get such status.</p> +<h3 id="flush_slave_timeout">FLUSH_SLAVE_TIMEOUT</h3> +<p>If the Brokerâs role is SYNC_MASTER(default is ASYNC_MASTER), and the slave Broker dose not finish synchronizing with the master within the MessageStoreConfigâs syncFlushTimeout(default is 5 secs), you will get such status.</p> +<h3 id="slave_not_available">SLAVE_NOT_AVAILABLE</h3> +<p>If the Brokerâs role is SYNC_MASTER(default is ASYNC_MASTER), but no slave Broker is configured, you will get such status.</p> +<h3 id="send_ok">SEND_OK</h3> +<p>You should be aware that SEND_OK does not mean it is reliable. If you cannot tolerate message missing, you should also enable SYNC_MASTER or SYNC_FLUSH.</p> +<h3 id="duplication-or-missing">Duplication or Missing</h3> +<p>If you get FLUSH_DISK_TIMEOUT, FLUSH_SLAVE_TIMEOUT and the Broker happens to shutdown right the moment, you may get your message missing. +At this time, you have two choices, one is letting it go, which may get message missing; another is resending, which may get message duplication. +Often we suggest resend and make a way to handle the duplication removal when consuming. Unless you feel it does not matter when some messages are missed. +But be ware that resending has no use when you get SLAVE_NOT_AVAILABLE, youâd better keep the scene and send some alerts to the Cluster Manager.</p> +<h2 id="timeout">Timeout</h2> +<p>The Client send requests to Broker, and wait the responses, but if the max wait time is elapsed and no response is return, the Client will throw a RemotingTimeoutException. +The default wait time is 3 seconds.You can also pass timeout argument using send(msg, timeout) instead of send(msg). +Note that we do not suggest the value to be too small, for the Broker need some time to flush disk or synchronize with slave. Also the value may have little effect if it is too bigger than syncFlushTimeout for Broker may return a response with FLUSH_SLAVE_TIMEOUT or FLUSH_SLAVE_TIMEOUT before the timeout.</p> +<h2 id="message-size">Message Size</h2> +<p>We suggest the message should be no more than 512K.</p> +<h2 id="async-sending">Async Sending</h2> +<p>Default send(msg) will block until the response is return. So if you care about performance, we suggest you use send(msg, callback) which will act in a async way.</p> +<h2 id="producer-group">Producer Group</h2> +<p>Normally, the producer group has no effects. But if you are involved in transaction, you should pay attention to it. +In default, you can only create only one producer with the same producer group in the same JVM. Usually, this is enough.</p> +<h2 id="thread-safety">Thread Safety</h2> +<p>The producer is thread-safe, you can just use it in your business logic.</p> +<h2 id="performance">Performance</h2> +<p>If you want more than one producer in one JVM, maybe for big data processing, we suggest you:</p> +<ul> + <li>use async sending with a few producers(3~5 is enough)</li> + <li>setInstanceName for each producer</li> +</ul> + + + + </section> + + <footer class="page__meta"> + + + + + + <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> Updated:</strong> <time datetime="2016-12-25">December 25, 2016</time></p> + + </footer> + + <section class="page__share"> + + <h4 class="page__share-title">Share on</h4> + + + <a href="https://twitter.com/intent/tweet?via=ApacheRocketMQ&text=Best Practice For Producer /docs/best-practice-producer/" class="btn btn--twitter" title="Share on Twitter"><i class="fa fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a> + + <a href="https://www.facebook.com/sharer/sharer.php?u=/docs/best-practice-producer/" class="btn btn--facebook" title="Share on Facebook"><i class="fa fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a> + + <a href="https://plus.google.com/share?url=/docs/best-practice-producer/" class="btn btn--google-plus" title="Share on Google Plus"><i class="fa fa-fw fa-google-plus" aria-hidden="true"></i><span> Google+</span></a> + + <a href="https://www.linkedin.com/shareArticle?mini=true&url=/docs/best-practice-producer/" class="btn btn--linkedin" title="Share on LinkedIn"><i class="fa fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a> +</section> + + + + <nav class="pagination"> + + <a href="/docs/best-practice-namesvr/" class="pagination--pager" title="Best Practice For NameServer +">Previous</a> + + + <a href="#" class="pagination--pager disabled">Next</a> + + </nav> + + </div> + + + <div class="page__comments"> + + + <h4 class="page__comments-title">Leave a Comment</h4> + <section id="disqus_thread"></section> + +</div> + + </article> + + + +</div> + + <div class="page__footer"> + <footer> + <!-- start custom footer snippets --> + +<!-- end custom footer snippets --> + <style type="text/css"> + div.columns { float: left; margin-left: 10px;} + div.clear { clear: both; } +</style> +<div> + <div class="columns"> + <a href="https://www.apache.org/"><img src="/assets/images/feather-small.gif" alt="Apache Software Foundation" style="height: 88px !important" /></a> + </div> + <div class="columns" style="width: 80%"> + <div class="page__footer-follow"> + <ul class="social-icons"> + + <li><strong>Follow:</strong></li> + + + <li><a href="https://twitter.com/ApacheRocketMQ"><i class="fa fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li> + + + + <li><a href="http://github.com/apache/incubator-rocketmq"><i class="fa fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li> + + + <li><a href="/feed.xml"><i class="fa fa-fw fa-rss-square" aria-hidden="true"></i> Feed</a></li> + </ul> + </div> + + <div class="page__footer-copyright">Copyright © 2017 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</div> + </div> +</div> +<div class="clear"></div> + </footer> + </div> + + <script src="/assets/js/main.min.js"></script> + + + + + <script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-89603173-1', 'auto'); + ga('send', 'pageview'); +</script> + +<script> +var _hmt = _hmt || []; +(function() { + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?36428f2b841d08e7405724cbf7f860d2"; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); +})(); +</script> + + + + + + <script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'rocketmq'; + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function () { + var s = document.createElement('script'); s.async = true; + s.type = 'text/javascript'; + s.src = '//' + disqus_shortname + '.disqus.com/count.js'; + (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); + }()); + </script> + <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> + + + + + + + </body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-site/blob/93c5936c/content/docs/broadcast-example/index.html ---------------------------------------------------------------------- diff --cc content/docs/broadcast-example/index.html index 6712947,0000000..9f2f977 mode 100644,000000..100644 --- a/content/docs/broadcast-example/index.html +++ b/content/docs/broadcast-example/index.html @@@ -1,661 -1,0 +1,661 @@@ +<!doctype html> +<html lang="en" class="no-js"> + <head> + <meta charset="utf-8"> + +<!-- begin SEO --> + + + + + + + + + +<title>Broadcasting - Apache RocketMQ</title> + + + + +<meta name="description" content="How to send broadcast messages in Apache RocketMQ."> + + + + +<meta property="og:locale" content="en"> +<meta property="og:site_name" content="Apache RocketMQ"> +<meta property="og:title" content="Broadcasting"> + + + + + <meta property="og:description" content="How to send broadcast messages in Apache RocketMQ."> + + + + <meta name="twitter:site" content="@ApacheRocketMQ"> + <meta name="twitter:title" content="Broadcasting"> + <meta name="twitter:description" content="How to send broadcast messages in Apache RocketMQ."> + <meta name="twitter:url" content=""> + + + <meta name="twitter:card" content="summary"> + + + + + + + + + + + + + + + + <meta property="og:type" content="article"> - <meta property="article:published_time" content="2017-04-25T01:02:11+08:00"> ++ <meta property="article:published_time" content="2017-04-25T01:06:24+08:00"> + + + + + + + + + <script type="application/ld+json"> + { + "@context" : "http://schema.org", + "@type" : "Person", + "name" : "Apache RocketMQ", + "url" : null, + "sameAs" : null + } + </script> + + + + <meta name="google-site-verification" content="aand0XZkSGsziuC-UPD4ZJniFD0m0JhGx6820y2mAQY" /> + + + <meta name="baidu-site-verification" content="wD06EbDRkQ" /> + + + + +<!-- end SEO --> + + +<link href="/feed.xml" type="application/atom+xml" rel="alternate" title="Apache RocketMQ Feed"> + +<!-- http://t.co/dKP3o1e --> +<meta name="HandheldFriendly" content="True"> +<meta name="MobileOptimized" content="320"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<script> + document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js '; +</script> + +<!-- For all browsers --> +<link rel="stylesheet" href="/assets/css/main.css"> + +<meta http-equiv="cleartype" content="on"> + <!-- start custom head snippets --> + +<!-- insert favicons. use http://realfavicongenerator.net/ --> + +<!-- end custom head snippets --> + </head> + + <body class="layout--single"> + + <!--[if lt IE 9]> +<div class="notice--danger align-center" style="margin: 0;">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</div> +<![endif]--> + <div class="masthead"> + <div class="masthead__inner-wrap"> + <div class="masthead__menu"> + <nav id="site-nav" class="greedy-nav"> + <button><div class="navicon"></div></button> + <ul class="visible-links"> + <li class="masthead__menu-item masthead__menu-item--lg"><a href="/">Apache RocketMQ</a></li> + + + <li class="masthead__menu-item"><a href="/docs/quick-start/">Documentation</a></li> + + + <li class="masthead__menu-item"><a href="/year-archive/">Blog</a></li> + + + <li class="masthead__menu-item"><a href="/community/">Community</a></li> + + + <li class="masthead__menu-item"><a href="/customer/">Customer</a></li> + + + <li class="masthead__menu-item"><a href="/about/team/">About</a></li> + + </ul> + <ul class="hidden-links hidden"></ul> + </nav> + </div> + </div> +</div> + + + + + +<div id="main" role="main"> + + <div class="sidebar sticky"> + + + + + + + + + + +<nav class="nav__list"> + + <input id="ac-toc" name="accordion-toc" type="checkbox" /> + <label for="ac-toc">Toggle Menu</label> + <ul class="nav__items"> + + <li> + + <span class="nav__sub-title">User Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/quick-start/" class="">Quick Start</a></li> + + + + + + + + <li><a href="/docs/motivation/" class="">Why RocketMQ</a></li> + + + + + + + + <li><a href="/docs/simple-example/" class="">Simple Example</a></li> + + + + + + + + <li><a href="/docs/order-example/" class="">Order Example</a></li> + + + + + + + + <li><a href="/docs/broadcast-example/" class="active">Broadcasting Example</a></li> + + + + + + + + <li><a href="/docs/schedule-example/" class="">Schedule Example</a></li> + + + + + + + + <li><a href="/docs/batch-example/" class="">Batch Example</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Deployment & Operations</span> + + + + <ul> + + + + + + + + <li><a href="/docs/rmq-arc/" class="">Architecture</a></li> + + + + + + + + <li><a href="/docs/rmq-deployment/" class="">Deployment</a></li> + + + + + + + + <li><a href="/docs/cli-admin-tool/" class="">CLI Admin Tool</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Contributor Guide</span> + + + + <ul> + + + + + + + + <li><a href="/docs/code-guidelines/" class="">Code Guidelines</a></li> + + + + + + + + <li><a href="/docs/pull-request/" class="">Pull Request</a></li> + + + + + + + + <li><a href="/docs/release-manual" class="">Release Manual</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Best Practice</span> + + + + <ul> + + + + + + + + <li><a href="/docs/core-concept/" class="">Core Concept</a></li> + + + + + + + + <li><a href="/docs/best-practice-broker/" class="">Broker</a></li> + + + + + + + + <li><a href="/docs/best-practice-producer/" class="">Producer</a></li> + + + + + + + + <li><a href="/docs/best-practice-consumer/" class="">Consumer</a></li> + + + + + + + + <li><a href="/docs/best-practice-namesvr/" class="">NameServer</a></li> + + </ul> + + </li> + + <li> + + <span class="nav__sub-title">Release Notes</span> + + + + <ul> + + + + + + + + <li><a href="/dowloading/releases/" class="">Download</a></li> + + + + + + + + <li><a href="/release_notes/release-notes-4.0.0-incubating/" class="">4.0.0-incubating</a></li> + + </ul> + + </li> + + <li> + + + + + <a href="/docs/roadmap/"><span class="nav__sub-title">RoadMap</span></a> + + + + </li> + + <li> + + + + + <a href="/docs/faq/"><span class="nav__sub-title">FAQ</span></a> + + + + </li> + + </ul> +</nav> + + + </div> + + + <article class="page" itemscope itemtype="http://schema.org/CreativeWork"> + <meta itemprop="headline" content="Broadcasting"> + <meta itemprop="description" content="How to send broadcast messages in Apache RocketMQ."> + <meta itemprop="datePublished" content="April 25, 2017"> + <meta itemprop="dateModified" content="April 25, 2017"> + + <div class="page__inner-wrap"> + + <header> + <h1 class="page__title" itemprop="headline">Broadcasting +</h1> + + </header> + + + <section class="page__content" itemprop="text"> + <aside class="sidebar__right"> +<nav class="toc"> + <header><h4 class="nav__title"><i class="fa fa-file-text"></i> On This Page</h4></header> +<ul class="toc__menu" id="markdown-toc"> + <li><a href="#what-is-broadcasting" id="markdown-toc-what-is-broadcasting">What is Broadcasting</a></li> + <li><a href="#how-to-use" id="markdown-toc-how-to-use">How to use</a> <ul> + <li><a href="#firstproduce-message-as-before" id="markdown-toc-firstproduce-message-as-before">First,Produce message as before</a></li> + <li><a href="#secondconsume-message-in-broadcast-mode" id="markdown-toc-secondconsume-message-in-broadcast-mode">Second,Consume message in Broadcast mode</a></li> + </ul> + </li> +</ul> + + </nav> +</aside> + +<h4 id="what-is-broadcasting">What is Broadcasting</h4> +<p>Broadcasting is when sending a meeage to a topic,all subscribers of the topic will receive the message even if they are in the same consumer group.If you want all subscribers in a group receive all the messages in a topic,broadcasting is a good choice.</p> + +<h4 id="how-to-use">How to use</h4> + +<h5 id="firstproduce-message-as-before">First,Produce message as before</h5> + +<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">DefaultMQProducer</span> <span class="n">producer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultMQProducer</span><span class="o">(</span><span class="s">"ProducerGroupName"</span><span class="o">);</span> + +<span class="n">producer</span><span class="o">.</span><span class="na">start</span><span class="o">();</span> + +<span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">10000000</span><span class="o">;</span> <span class="n">i</span><span class="o">++){</span> + <span class="k">try</span> <span class="o">{</span> + <span class="o">{</span> + <span class="n">Message</span> <span class="n">msg</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Message</span><span class="o">(</span><span class="s">"TopicTest"</span><span class="o">,</span> + <span class="s">"TagA"</span><span class="o">,</span> + <span class="s">"OrderID188"</span><span class="o">,</span> + <span class="s">"Hello world"</span><span class="o">.</span><span class="na">getBytes</span><span class="o">(</span><span class="n">RemotingHelper</span><span class="o">.</span><span class="na">DEFAULT_CHARSET</span><span class="o">));</span> + <span class="n">SendResult</span> <span class="n">sendResult</span> <span class="o">=</span> <span class="n">producer</span><span class="o">.</span><span class="na">send</span><span class="o">(</span><span class="n">msg</span><span class="o">);</span> + <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">printf</span><span class="o">(</span><span class="s">"%s%n"</span><span class="o">,</span> <span class="n">sendResult</span><span class="o">);</span> + <span class="o">}</span> + + <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">Exception</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span> + <span class="n">e</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span> + <span class="o">}</span> +<span class="o">}</span> +<span class="n">producer</span><span class="o">.</span><span class="na">shutdown</span><span class="o">();</span> +</code></pre> +</div> + +<h5 id="secondconsume-message-in-broadcast-mode">Second,Consume message in Broadcast mode</h5> + +<div class="language-java highlighter-rouge"><pre class="highlight"><code><span class="n">DefaultMQPushConsumer</span> <span class="n">consumer</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultMQPushConsumer</span><span class="o">(</span><span class="s">"please_rename_unique_group_name_1"</span><span class="o">);</span> + +<span class="n">consumer</span><span class="o">.</span><span class="na">setConsumeFromWhere</span><span class="o">(</span><span class="n">ConsumeFromWhere</span><span class="o">.</span><span class="na">CONSUME_FROM_FIRST_OFFSET</span><span class="o">);</span> + +<span class="c1">//set to broadcast mode</span> +<span class="n">consumer</span><span class="o">.</span><span class="na">setMessageModel</span><span class="o">(</span><span class="n">MessageModel</span><span class="o">.</span><span class="na">BROADCASTING</span><span class="o">);</span> + +<span class="n">consumer</span><span class="o">.</span><span class="na">subscribe</span><span class="o">(</span><span class="s">"TopicTest"</span><span class="o">,</span> <span class="s">"TagA || TagC || TagD"</span><span class="o">);</span> + +<span class="n">consumer</span><span class="o">.</span><span class="na">registerMessageListener</span><span class="o">(</span><span class="k">new</span> <span class="n">MessageListenerConcurrently</span><span class="o">()</span> <span class="o">{</span> + + <span class="nd">@Override</span> + <span class="kd">public</span> <span class="n">ConsumeConcurrentlyStatus</span> <span class="nf">consumeMessage</span><span class="o">(</span><span class="n">List</span><span class="o"><</span><span class="n">MessageExt</span><span class="o">></span> <span class="n">msgs</span><span class="o">,</span> + <span class="n">ConsumeConcurrentlyContext</span> <span class="n">context</span><span class="o">)</span> <span class="o">{</span> + <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">printf</span><span class="o">(</span><span class="n">Thread</span><span class="o">.</span><span class="na">currentThread</span><span class="o">().</span><span class="na">getName</span><span class="o">()</span> <span class="o">+</span> <span class="s">" Receive New Messages: "</span> <span class="o">+</span> <span class="n">msgs</span> <span class="o">+</span> <span class="s">"%n"</span><span class="o">);</span> + <span class="k">return</span> <span class="n">ConsumeConcurrentlyStatus</span><span class="o">.</span><span class="na">CONSUME_SUCCESS</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">});</span> + +<span class="n">consumer</span><span class="o">.</span><span class="na">start</span><span class="o">();</span> +<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">printf</span><span class="o">(</span><span class="s">"Broadcast Consumer Started.%n"</span><span class="o">);</span> +</code></pre> +</div> + +<p>Enjoy it.</p> + + + </section> + + <footer class="page__meta"> + + + + + + <p class="page__date"><strong><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> Updated:</strong> <time datetime="2017-04-25">April 25, 2017</time></p> + + </footer> + + <section class="page__share"> + + <h4 class="page__share-title">Share on</h4> + + + <a href="https://twitter.com/intent/tweet?via=ApacheRocketMQ&text=Broadcasting /docs/broadcast-example/" class="btn btn--twitter" title="Share on Twitter"><i class="fa fa-fw fa-twitter" aria-hidden="true"></i><span> Twitter</span></a> + + <a href="https://www.facebook.com/sharer/sharer.php?u=/docs/broadcast-example/" class="btn btn--facebook" title="Share on Facebook"><i class="fa fa-fw fa-facebook" aria-hidden="true"></i><span> Facebook</span></a> + + <a href="https://plus.google.com/share?url=/docs/broadcast-example/" class="btn btn--google-plus" title="Share on Google Plus"><i class="fa fa-fw fa-google-plus" aria-hidden="true"></i><span> Google+</span></a> + + <a href="https://www.linkedin.com/shareArticle?mini=true&url=/docs/broadcast-example/" class="btn btn--linkedin" title="Share on LinkedIn"><i class="fa fa-fw fa-linkedin" aria-hidden="true"></i><span> LinkedIn</span></a> +</section> + + + + <nav class="pagination"> + + <a href="/docs/batch-example/" class="pagination--pager" title="Batch Example +">Previous</a> + + + <a href="/docs/rmq-deployment/" class="pagination--pager" title="Deployment +">Next</a> + + </nav> + + </div> + + + <div class="page__comments"> + + + <h4 class="page__comments-title">Leave a Comment</h4> + <section id="disqus_thread"></section> + +</div> + + </article> + + + +</div> + + <div class="page__footer"> + <footer> + <!-- start custom footer snippets --> + +<!-- end custom footer snippets --> + <style type="text/css"> + div.columns { float: left; margin-left: 10px;} + div.clear { clear: both; } +</style> +<div> + <div class="columns"> + <a href="https://www.apache.org/"><img src="/assets/images/feather-small.gif" alt="Apache Software Foundation" style="height: 88px !important" /></a> + </div> + <div class="columns" style="width: 80%"> + <div class="page__footer-follow"> + <ul class="social-icons"> + + <li><strong>Follow:</strong></li> + + + <li><a href="https://twitter.com/ApacheRocketMQ"><i class="fa fa-fw fa-twitter-square" aria-hidden="true"></i> Twitter</a></li> + + + + <li><a href="http://github.com/apache/incubator-rocketmq"><i class="fa fa-fw fa-github" aria-hidden="true"></i> GitHub</a></li> + + + <li><a href="/feed.xml"><i class="fa fa-fw fa-rss-square" aria-hidden="true"></i> Feed</a></li> + </ul> + </div> + + <div class="page__footer-copyright">Copyright © 2017 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All Rights Reserved.</div> + </div> +</div> +<div class="clear"></div> + </footer> + </div> + + <script src="/assets/js/main.min.js"></script> + + + + + <script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-89603173-1', 'auto'); + ga('send', 'pageview'); +</script> + +<script> +var _hmt = _hmt || []; +(function() { + var hm = document.createElement("script"); + hm.src = "https://hm.baidu.com/hm.js?36428f2b841d08e7405724cbf7f860d2"; + var s = document.getElementsByTagName("script")[0]; + s.parentNode.insertBefore(hm, s); +})(); +</script> + + + + + + <script type="text/javascript"> + /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ + var disqus_shortname = 'rocketmq'; + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function() { + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + })(); + + /* * * DON'T EDIT BELOW THIS LINE * * */ + (function () { + var s = document.createElement('script'); s.async = true; + s.type = 'text/javascript'; + s.src = '//' + disqus_shortname + '.disqus.com/count.js'; + (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); + }()); + </script> + <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> + + + + + + + </body> +</html>
