I am using spring amqp. Simple POJOs get message automatically upon arrival of a new message or rabbitMQ's delivery.<br><br><u>spring configurations for template :</u><br><br><!-- Define a RabbitMQ connectionFactory --><br>
<bean id="connectionFactory"<br> class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"><br> <constructor-arg value="localhost" /><br> <property name="username" value="guest" /><br>
<property name="password" value="guest" /><br> </bean><br><br><div class="gmail_quote"><u>use that template in ur POJO to become a "magical" consumer:</u><br><br><bean id="msgHandler" class="com.xyz.MsgHandler" /><br>
<br> <bean id="msgHandlerAdaptor" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter"><br> <constructor-arg ref="msgHandler" /><br> </bean><br>
<br> <bean id="msgListener" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"<br> p:connectionFactory-ref="connectionFactory" p:queueName="Queue1" p:autoAck="false" p:concurrentConsumers="20" p:messageListener-ref="msgHandlerAdaptor" /><br>
<br><u>Bean has</u><br><br> public void handleMessage(String msg) {<br><br> }<br><br><br>That's it !!!<br><br><br>On Thu, Oct 14, 2010 at 12:05 PM, sam_mis <span dir="ltr"><<a href="mailto:sameek@arosys.com">sameek@arosys.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>
Hi<br>
<br>
i am using the following code to read an queue and extract the messages from<br>
queue. I want to know that there is another approach to retrieve message<br>
from queue? if there is another approach please describe the details<br>
information to get the messages from queue.<br>
<br>
while (runInfinite)<br>
{<br>
QueueingConsumer.Delivery delivery;<br>
try<br>
{<br>
delivery = consumer.nextDelivery();<br>
} catch (InterruptedException ie)<br>
{<br>
continue;<br>
}<br>
System.out.println("Message received-"<br>
+ new String(delivery.getBody()));<br>
<br>
file included that contain the code for reading and extracting message:<br>
--------------------------------------------------------------------------<br>
<a href="http://old.nabble.com/file/p29959643/Result.java" target="_blank">http://old.nabble.com/file/p29959643/Result.java</a> Result.java<br>
<br>
Thanks<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://old.nabble.com/another-approach-to-retrieve-message-from-queue--tp29959643p29959643.html" target="_blank">http://old.nabble.com/another-approach-to-retrieve-message-from-queue--tp29959643p29959643.html</a><br>
Sent from the RabbitMQ mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
</font></blockquote></div><br>