<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Dear fangbot,<div>You do not say whether you are using Python or Java (the two languages shown on the tutorials pages) but I will assume it is Java.</div><div><br></div><div><blockquote type="cite"><div>is there a way to create an event<br>such that when a queue gets pushed a message, it automatically calls<br>consumer.nextDelivery somehow</div></blockquote></div><div><br></div><div>The simple answer is 'yes', approximately. There is a push interface (defined by the Consumer interface) which is driven whenever a message is delivered.</div><div><br></div><div>The tutorials use QueueingConsumer, which is a way to isolate the clients engine (the channel thread) from the user's thread. As you observe, this is a pull interface. QueueingConsumer.nextDelivery() will block until there is a message to return.</div><div><br></div><div>If you want to use a push interface (which is what QueueingConsumer uses under the covers) then you are free to create your own Consumer (implementation of the Consumer interface) class, and the handleDelivery() method therein will be driven when a message arrives. The drawback is that this 'callback' is driven on a RabbitMQ client thread, and (at the moment) you are not permitted to do long-running things on this thread or make channel calls, or block, as this will often result in deadlocks. However, if you can limit what this does, you are free to communicate with another thread of yours, for example to put it on a BlockingQueue (like QueueingConsumer does), or to otherwise trigger another thread to do something.</div><div><br></div><div>The easiest (and recommended) way to code your own Consumer is to subclass DefaultConsumer, and override the methods you want to change (in your case handleDelivery()). Take a look at the DefaultConsumer class to see what it does.</div><div><br></div><div>Other methods on the Consumer interface are driven if other events occur, like channel close, for example. Your class can then do the right thing.</div><div><br></div><div>This area is currently being reworked -- not to change the interface (much!) but to lift some of the restrictions on the things a callback method can do without causing deadlocks -- which will also see better control of the system resources used by the consumer callbacks.</div><div><br></div><div>I hope this helps -- please come back here if you have any more questions; or even if you don't -- we'd like to know how you get on.</div><div><br></div><div><span class="Apple-style-span" style="font-size: 12px; ">Steve Powell </span><span class="Apple-style-span" style="font-size: 11px; ">(<i>a happy bunny</i>)</span></div><div><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Georgia; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Georgia; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Georgia; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Georgia; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Georgia; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 11px; "><div style="font-family: Helvetica; font-size: 12px; "><i><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; ">----------some definitions from the SPD----------</span></font></i></div><div style="font-family: Helvetica; font-size: 12px; "><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; "><b>Rigatoni</b> </span><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="font-size: 10px; "><i>n.</i></span></font><span class="Apple-style-span" style="font-size: 10px; "> A prime-ministerial grin.</span></font></div><div style="font-family: Helvetica; font-size: 12px; "><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; "><b>Nigella</b> <i>n.</i> The next bottle-size up from a </span></font><span class="Apple-style-span" style="line-height: 15px; "><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; ">Nebuchadnezzar</span></font></span><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; ">.</span></font></div><div style="font-family: Helvetica; font-size: 12px; "><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; "><b>Homily</b> </span></font><font class="Apple-style-span" face="Georgia" size="2"><span class="Apple-style-span" style="font-size: 10px; "><i>adv.</i> Rather like a frenchman.</span></font></div></span></font></div></div></span></div></span></div></span></span></span>
</div>
<br><div><div>On 20 Jul 2011, at 23:26, fangbot wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>I'm looking to create multiple publishers/subscribers from the main thread<br>that my program is run (i.e. the thread where I have declared my channel).<br>It seems that in the tutorials, the only way for consumers to get a message<br>from the queue its connected to is to explicitly call<br>consumer.nextDelivery(). However, as far as my understanding, in order to<br>constantly check for new publications, this call must reside within a<br>while(true) loop. <br><br>Say I wanted to create a consumer with an anonymous queue and attach it to<br>an exchange. Then, I want to make a publication to that exchange. When that<br>publication is made, the consumer will print something to the console using<br>an overridden nextDelivery(). In order to do this, do I have to basically<br><br>1. Create the consumer/queue and attach it with a routingId to the exchange<br>2. Publish a method with that routingId to the exchange<br>3. Invoke the while loop to constantly check for messages<br><br>in that order?<br><br>If so, then is there a way to support two (or more) consumers to<br>automatically get nextDelivery? It seems that the only way is to write a<br>while loop that goes through every consumer, and calls nextDelivery on that<br>consumer, in an infinite loop. Instead, is there a way to create an event<br>such that when a queue gets pushed a message, it automatically calls<br>consumer.nextDelivery somehow?<br><br>Thanks in advance for the reply. I'm fairly new to RabbitMQ, so please<br>forgive me if the question is somewhat basic/has already been answered<br>elsewhere :-D.<br>-- <br>View this message in context: <a href="http://old.nabble.com/Consumer-Callback-tp32103305p32103305.html">http://old.nabble.com/Consumer-Callback-tp32103305p32103305.html</a><br>Sent from the RabbitMQ mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>rabbitmq-discuss mailing list<br><a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss<br></div></blockquote></div><br></div></body></html>