|
40 | 40 | import com.rabbitmq.utility.Utility; |
41 | 41 |
|
42 | 42 | /** |
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, exchangeName, 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, false, consumer); |
| 61 | + * |
| 62 | + * // Process deliveries |
| 63 | + * while (/* some condition * /) { |
| 64 | + * {@link QueueingConsumer.Delivery} delivery = consumer.{@link QueueingConsumer#nextDelivery nextDelivery}(); |
| 65 | + * // process delivery |
| 66 | + * ch1.{@link Channel#basicAck basicAck}(delivery.{@link QueueingConsumer.Delivery#getEnvelope getEnvelope}().{@link Envelope#getDeliveryTag getDeliveryTag}(), false); |
| 67 | + * } |
| 68 | + * </pre> |
| 69 | + * |
| 70 | + * <p>For a more detailed explanation, see <a href="http://www.rabbitmq.com/api-guide.html#consuming">the java api guide</a>.</p> |
| 71 | + * |
| 72 | + * <p>For a more complete example, see LogTail in the test/src/com/rabbitmq/examples |
| 73 | + * directory of the source distribution.</p> |
44 | 74 | */ |
45 | 75 | public class QueueingConsumer extends DefaultConsumer { |
46 | 76 | private final BlockingQueue<Delivery> _queue; |
|
0 commit comments