|
2 | 2 |
|
3 | 3 | import com.rabbitmq.client.AMQP;
|
4 | 4 | import com.rabbitmq.client.Channel;
|
| 5 | +import com.rabbitmq.client.DefaultConsumer; |
| 6 | +import com.rabbitmq.client.Envelope; |
5 | 7 | import com.rabbitmq.client.GetResponse;
|
| 8 | +import com.rabbitmq.client.MessageProperties; |
6 | 9 | import com.rabbitmq.client.QueueingConsumer;
|
7 | 10 | import com.rabbitmq.client.QueueingConsumer.Delivery;
|
8 | 11 | import com.rabbitmq.client.test.BrokerTestCase;
|
|
15 | 18 | import java.util.List;
|
16 | 19 | import java.util.Map;
|
17 | 20 | import java.util.concurrent.Callable;
|
| 21 | +import java.util.concurrent.CountDownLatch; |
| 22 | +import java.util.concurrent.TimeUnit; |
18 | 23 |
|
19 | 24 | public class DeadLetterExchange extends BrokerTestCase {
|
20 | 25 | public static final String DLX = "dead.letter.exchange";
|
@@ -266,6 +271,28 @@ public void testDeadLetterSelf() throws Exception {
|
266 | 271 | consumeN(TEST_QUEUE_NAME, 0, WithResponse.NULL);
|
267 | 272 | }
|
268 | 273 |
|
| 274 | + public void testDeadLetterCycle() throws Exception { |
| 275 | + // testDeadLetterTwice and testDeadLetterSelf both test that we drop |
| 276 | + // messages in pure-expiry cycles. So we just need to test that |
| 277 | + // non-pure-expiry cycles do not drop messages. |
| 278 | + |
| 279 | + declareQueue("queue1", "", "queue2", null, 1); |
| 280 | + declareQueue("queue2", "", "queue1", null, 0); |
| 281 | + |
| 282 | + channel.basicPublish("", "queue1", MessageProperties.BASIC, "".getBytes()); |
| 283 | + final CountDownLatch latch = new CountDownLatch(10); |
| 284 | + channel.basicConsume("queue2", false, |
| 285 | + new DefaultConsumer(channel) { |
| 286 | + @Override |
| 287 | + public void handleDelivery(String consumerTag, Envelope envelope, |
| 288 | + AMQP.BasicProperties properties, byte[] body) throws IOException { |
| 289 | + channel.basicReject(envelope.getDeliveryTag(), false); |
| 290 | + latch.countDown(); |
| 291 | + } |
| 292 | + }); |
| 293 | + assertTrue(latch.await(10, TimeUnit.SECONDS)); |
| 294 | + } |
| 295 | + |
269 | 296 | public void testDeadLetterNewRK() throws Exception {
|
270 | 297 | declareQueue(TEST_QUEUE_NAME, DLX, "test-other", null, 1);
|
271 | 298 |
|
|
0 commit comments