Skip to content

Commit 29efbd2

Browse files
author
Alexandru Scvortov
committed
added example for QueueingConsumer
1 parent 66a4a5e commit 29efbd2

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/com/rabbitmq/client/QueueingConsumer.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,34 @@
4040
import com.rabbitmq.utility.Utility;
4141

4242
/**
43-
* Convenience class: an implementation of {@link Consumer} with straightforward blocking semantics
43+
* Convenience class: an implementation of {@link Consumer} with
44+
* straightforward blocking semantics.
45+
*
46+
* The general pattern for using QueueingConsumer is as follows:
47+
*
48+
* <pre>
49+
* // Create connection and channel.
50+
* {@link ConnectionFactory} factory = new ConnectionFactory();
51+
* Connection conn = factory.newConnection();
52+
* {@link Channel} ch1 = conn.createChannel();
53+
*
54+
* // Declare a queue and bind it to an exchange.
55+
* String queueName = ch1.queueDeclare().{@link AMQP.Queue.DeclareOk#getQueue getQueue}();
56+
* ch1.{@link Channel#queueBind queueBind}(queueName, "amq.direct", queueName);
57+
*
58+
* // Create the QueueingConsumer and have it consume from the queue
59+
* QueueingConsumer consumer = new {@link QueueingConsumer#QueueingConsumer QueueingConsumer}(ch1);
60+
* ch1.{@link Channel#basicConsume basicConsume}(queueName, true, consumer);
61+
*
62+
* // Process deliveries
63+
* while (true) {
64+
* {@link QueueingConsumer.Delivery} delivery = consumer.{@link QueueingConsumer#nextDelivery nextDelivery}();
65+
* // process delivery
66+
* }
67+
* </pre>
68+
*
69+
* For a more complete example, see LogTail in the test/src/com/rabbitmq/examples
70+
* directory of the source distribution.
4471
*/
4572
public class QueueingConsumer extends DefaultConsumer {
4673
private final BlockingQueue<Delivery> _queue;

0 commit comments

Comments
 (0)