RabbitMQ消息隊列裏積壓不少消息

<div class="htmledit_views" id="content_views"> <p><span style="color:#f33b45;"><strong>一、場景:上千萬條消息在mq裏積壓了幾個小時了還沒解決</strong></span></p>html

<p><span style="color:#f33b45;"><strong>二、解決:</strong></span></p>架構

<pre class="has" name="code" onclick="hljs.copyCode(event)"><code class="hljs cpp"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">1</span>)先修復consumer的問題,確保其恢復消費速度,而後將現有cnosumer都停掉</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">2</span>)新建一個topic,partition是原來的<span class="hljs-number">10</span>倍,臨時創建好原先<span class="hljs-number">10</span>倍或者<span class="hljs-number">20</span>倍的<span class="hljs-built_in">queue</span>數量</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">3</span>)而後寫一個臨時的分發數據的consumer程序,這個程序部署上去消費積壓的數據,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">消費以後不作耗時的處理,直接均勻輪詢寫入臨時創建好的<span class="hljs-number">10</span>倍數量的<span class="hljs-built_in">queue</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">4</span>)接着臨時徵用<span class="hljs-number">10</span>倍的機器來部署consumer,每一批consumer消費一個臨時<span class="hljs-built_in">queue</span>的數據</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">5</span>)這種作法至關因而臨時將<span class="hljs-built_in">queue</span>資源和consumer資源擴大<span class="hljs-number">10</span>倍,以正常的<span class="hljs-number">10</span>倍速度來消費數據</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-number">6</span>)等快速消費完積壓數據以後,得恢復原先部署架構,從新用原先的consumer機器來消費消息</div></div></li></ol></code><div class="hljs-button" data-title="複製"></div></pre>ui

<p><span style="color:#f33b45;"><strong>三、場景:rabbitmq設置過時時間的,就是TTL</strong></span></p>spa

<p><span style="color:#f33b45;">說明:</span></p>code

<pre class="has" name="code" onclick="hljs.copyCode(event)"><code class="hljs cpp"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">若是消息在<span class="hljs-built_in">queue</span>中積壓超過必定的時間就會被rabbitmq給清理掉,這個數據就沒了。</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">那這就是第二個坑了。這就不是說數據會大量積壓在mq裏,而是大量的數據會直接搞丟</div></div></li></ol></code><div class="hljs-button" data-title="複製"></div></pre>htm

<p><span style="color:#f33b45;"><strong>四、解決:</strong></span></p>rabbitmq

<pre class="has" name="code" onclick="hljs.copyCode(event)"><code class="hljs"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">丟了大量的消息。咱們能夠採起一個方案,就是批量重導,這個時候咱們就開始寫程序,</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">將丟失的那批數據,寫個臨時程序,一點一點的查出來,而後從新灌入mq裏面去,把白天丟的數據給他補回來</div></div></li></ol></code><div class="hljs-button" data-title="複製"></div></pre>資源

<p>&nbsp;</p> </div>部署

相關文章
相關標籤/搜索