<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
BODY {
        LINE-HEIGHT: 1.5; FONT-FAMILY: 宋体; COLOR: #000080; FONT-SIZE: 10.5pt
}
</STYLE>

<META name=GENERATOR content="MSHTML 8.00.7601.17874"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>&nbsp;</DIV>
<DIV>Hi Matthias,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks for your reply. I wrote some test code and found a wired 
problem.</DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV>The&nbsp;init&nbsp;code&nbsp;is&nbsp;like</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;factory&nbsp;=&nbsp;new&nbsp;ConnectionFactory();</DIV>
<DIV>&nbsp;connection&nbsp;=&nbsp;factory.newConnection(address);</DIV>
<DIV>&nbsp;channel&nbsp;=&nbsp;connection.createChannel();</DIV>
<DIV>&nbsp;channel.basicQos(1);</DIV>
<DIV>&nbsp;</DIV>
<DIV>And&nbsp;the&nbsp;receive&nbsp;code&nbsp;is&nbsp;like</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;QueueingConsumer&nbsp;consumer&nbsp;=&nbsp;new&nbsp;QueueingConsumer(channel);</DIV>
<DIV>&nbsp;boolean&nbsp;autoAck&nbsp;=&nbsp;false;&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Queue.DeclareOk&nbsp;declare&nbsp;=&nbsp;channel.queueDeclarePassive("LBCQueue");</DIV>
<DIV>&nbsp;int&nbsp;consumerCount&nbsp;=&nbsp;declare.getConsumerCount();</DIV>
<DIV>&nbsp;if&nbsp;(consumerCount&nbsp;&gt;&nbsp;0)</DIV>
<DIV>&nbsp; return&nbsp;false;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;channel.basicConsume("LBCQueue",&nbsp;autoAck,&nbsp;consumer);</DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>First&nbsp;I&nbsp;started&nbsp;the&nbsp;first&nbsp;consumer&nbsp;and&nbsp;didn't&nbsp;publish&nbsp;any&nbsp;message. 
</DIV>
<DIV><IMG src="cid:_Foxmail.0@E5021B12-DF76-4489-B95D-44A01851CE5E"></DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV>Then&nbsp;I&nbsp;started&nbsp;the&nbsp;second&nbsp;consumer&nbsp;and&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;variable&nbsp;declare&nbsp;is&nbsp;#method&lt;queue.declare-ok&gt;(queue=LBCQueue,&nbsp;message-count=0,&nbsp;consumer-count=1).</DIV>
<DIV>So&nbsp;far&nbsp;everything&nbsp;is&nbsp;OK.</DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV>Now&nbsp;I&nbsp;publish&nbsp;1&nbsp;messge&nbsp;into&nbsp;the&nbsp;queue&nbsp;and&nbsp;restart&nbsp;the&nbsp;second&nbsp;consumer.&nbsp;The&nbsp;value&nbsp;of&nbsp;the&nbsp;variable&nbsp;declare&nbsp;is&nbsp;#method&lt;queue.declare-ok&gt;(queue=LBCQueue,&nbsp;message-count=0,&nbsp;consumer-count=1).</DIV>
<DIV>So&nbsp;far&nbsp;everything&nbsp;is&nbsp;still&nbsp;OK.</DIV></DIV>
<DIV><IMG src="cid:_Foxmail.1@F9AF6563-F0B6-497D-B6D2-96E6852953D1"></DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV>Then&nbsp;I&nbsp;publish&nbsp;another&nbsp;message&nbsp;into&nbsp;the&nbsp;queue&nbsp;and&nbsp;restart&nbsp;the&nbsp;second&nbsp;consumer&nbsp;again.&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><IMG src="cid:_Foxmail.2@751C887C-8CEB-41D7-94A1-9A17CA968CBA"></DIV>
<DIV>This&nbsp;time&nbsp;the&nbsp;value&nbsp;of&nbsp;declare&nbsp;is&nbsp;#method&lt;queue.declare-ok&gt;(queue=LBCQueue,&nbsp;message-count=1,&nbsp;consumer-count=0).</DIV>
<DIV>The&nbsp;message-count&nbsp;is&nbsp;correct&nbsp;but&nbsp;the&nbsp;consumer-count&nbsp;is&nbsp;changed&nbsp;from&nbsp;1&nbsp;to&nbsp;0.&nbsp;I&nbsp;don't&nbsp;know&nbsp;why. 
Is it a bug?</DIV>
<DIV>&nbsp;</DIV></DIV>
<HR style="WIDTH: 210px; HEIGHT: 1px" align=left color=#b5c4df SIZE=1>

<DIV><SPAN>johnson</SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV 
style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<DIV 
style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px; PADDING-RIGHT: 8px; BACKGROUND: #efefef; COLOR: #000000; FONT-SIZE: 12px; PADDING-TOP: 8px">
<DIV><B>From:</B>&nbsp;<A href="mailto:matthias@rabbitmq.com">Matthias 
Radestock</A></DIV>
<DIV><B>Date:</B>&nbsp;2012-09-05&nbsp;15:48</DIV>
<DIV><B>To:</B>&nbsp;<A href="mailto:johnson@edocom.cn">johnson</A></DIV>
<DIV><B>CC:</B>&nbsp;<A 
href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss</A>; <A 
href="mailto:francesco@rabbitmq.com">Francesco Mazzoli</A></DIV>
<DIV><B>Subject:</B>&nbsp;Re: [rabbitmq-discuss] How to achieve HA 
consumers?</DIV></DIV></DIV>
<DIV>
<DIV>Johnson,</DIV>
<DIV>&nbsp;</DIV>
<DIV>On&nbsp;05/09/12&nbsp;05:32,&nbsp;johnson&nbsp;wrote:</DIV>
<DIV>&gt;&nbsp;The&nbsp;channel.queueDeclarePassive&nbsp;method&nbsp;returns&nbsp;the&nbsp;consumer&nbsp;count&nbsp;of</DIV>
<DIV>&gt;&nbsp;&nbsp;the&nbsp;specified&nbsp;channel,</DIV>
<DIV>&nbsp;</DIV>
<DIV>No&nbsp;it&nbsp;doesn't.&nbsp;queue.declarePassive&nbsp;returns&nbsp;the&nbsp;total&nbsp;number&nbsp;of&nbsp;active</DIV>
<DIV>consumers&nbsp;of&nbsp;the&nbsp;queue&nbsp;at&nbsp;that&nbsp;point&nbsp;in&nbsp;time.&nbsp;Regardless&nbsp;of&nbsp;what</DIV>
<DIV>connection/channel&nbsp;they&nbsp;were&nbsp;created&nbsp;on.</DIV>
<DIV>&nbsp;</DIV>
<DIV>That&nbsp;should&nbsp;be&nbsp;pretty&nbsp;clear&nbsp;from&nbsp;the&nbsp;docs&nbsp;-</DIV>
<DIV>http://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.declare-ok.consumer-count</DIV>
<DIV>-&nbsp;which&nbsp;make&nbsp;no&nbsp;mention&nbsp;of&nbsp;the&nbsp;count&nbsp;being&nbsp;connection/channel&nbsp;specific.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&nbsp;So&nbsp;if&nbsp;I&nbsp;start&nbsp;two&nbsp;consumers&nbsp;[...]&nbsp;in&nbsp;two&nbsp;different&nbsp;machines&nbsp;[...]&nbsp;the</DIV>
<DIV>&gt;&nbsp;channel.queueDeclarePassive&nbsp;method&nbsp;always&nbsp;return&nbsp;the&nbsp;consumer&nbsp;count</DIV>
<DIV>&gt;&nbsp;==&nbsp;1,&nbsp;not&nbsp;2.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I&nbsp;am&nbsp;not&nbsp;sure&nbsp;what&nbsp;you&nbsp;are&nbsp;expecting&nbsp;to&nbsp;see&nbsp;here.&nbsp;If&nbsp;you&nbsp;start&nbsp;two</DIV>
<DIV>consumers,&nbsp;the&nbsp;count&nbsp;they&nbsp;will&nbsp;see&nbsp;prior&nbsp;to&nbsp;consuming&nbsp;will&nbsp;be&nbsp;0&nbsp;or&nbsp;1.</DIV>
<DIV>&nbsp;</DIV>
<DIV>As&nbsp;mentioned&nbsp;"You'd&nbsp;need&nbsp;to&nbsp;be&nbsp;mindful&nbsp;of&nbsp;races&nbsp;when&nbsp;consumers&nbsp;start&nbsp;</DIV>
<DIV>up.",&nbsp;i.e.&nbsp;if&nbsp;both&nbsp;consumers&nbsp;start&nbsp;up&nbsp;near&nbsp;simultaneously&nbsp;then&nbsp;they&nbsp;will&nbsp;</DIV>
<DIV>both&nbsp;see&nbsp;a&nbsp;count&nbsp;of&nbsp;0.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&nbsp;I&nbsp;also&nbsp;try&nbsp;to&nbsp;find&nbsp;a&nbsp;API&nbsp;that&nbsp;can&nbsp;retrieve&nbsp;the&nbsp;existing&nbsp;connection&nbsp;or</DIV>
<DIV>&gt;&nbsp;channel.&nbsp;Then&nbsp;the&nbsp;second&nbsp;consumer&nbsp;can&nbsp;reuse&nbsp;the&nbsp;connection&nbsp;or&nbsp;channel</DIV>
<DIV>&gt;&nbsp;the&nbsp;first&nbsp;consumer&nbsp;created.&nbsp;But&nbsp;it&nbsp;seems&nbsp;no&nbsp;such&nbsp;APIs.</DIV>
<DIV>&nbsp;</DIV>
<DIV>A&nbsp;connection&nbsp;represents&nbsp;a&nbsp;point-to-point&nbsp;TCP&nbsp;connection.&nbsp;You&nbsp;can't&nbsp;</DIV>
<DIV>"reuse"&nbsp;that&nbsp;from&nbsp;a&nbsp;third&nbsp;point.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards,</DIV>
<DIV>&nbsp;</DIV>
<DIV>Matthias.</DIV>
<DIV>&nbsp;</DIV></DIV></BODY></HTML>