1
1
package com .rabbitmq .client .test .functional ;
2
2
3
3
import com .rabbitmq .client .AMQP ;
4
+ import com .rabbitmq .client .Channel ;
4
5
import com .rabbitmq .client .GetResponse ;
5
6
import com .rabbitmq .client .QueueingConsumer ;
6
7
import com .rabbitmq .client .QueueingConsumer .Delivery ;
16
17
import java .util .concurrent .Callable ;
17
18
18
19
public class DeadLetterExchange extends BrokerTestCase {
19
- private static final String DLX = "dead.letter.exchange" ;
20
- private static final String DLX_ARG = "x-dead-letter-exchange" ;
21
- private static final String DLX_RK_ARG = "x-dead-letter-routing-key" ;
22
- private static final String TEST_QUEUE_NAME = "test.queue.dead.letter" ;
23
- private static final String DLQ = "queue.dlq" ;
24
- private static final String DLQ2 = "queue.dlq2" ;
25
- private static final int MSG_COUNT = 10 ;
26
- private static final int MSG_COUNT_MANY = 1000 ;
27
- private static final int TTL = 1000 ;
20
+ public static final String DLX = "dead.letter.exchange" ;
21
+ public static final String DLX_ARG = "x-dead-letter-exchange" ;
22
+ public static final String DLX_RK_ARG = "x-dead-letter-routing-key" ;
23
+ public static final String TEST_QUEUE_NAME = "test.queue.dead.letter" ;
24
+ public static final String DLQ = "queue.dlq" ;
25
+ public static final String DLQ2 = "queue.dlq2" ;
26
+ public static final int MSG_COUNT = 10 ;
27
+ public static final int MSG_COUNT_MANY = 1000 ;
28
+ public static final int TTL = 1000 ;
28
29
29
30
@ Override
30
31
protected void createResources () throws IOException {
@@ -348,19 +349,23 @@ private void deadLetterTest(Callable<?> deathTrigger,
348
349
349
350
deathTrigger .call ();
350
351
351
- consumeN (DLQ , MSG_COUNT , new WithResponse () {
352
- @ SuppressWarnings ("unchecked" )
353
- public void process (GetResponse getResponse ) {
354
- Map <String , Object > headers = getResponse .getProps ().getHeaders ();
355
- assertNotNull (headers );
356
- ArrayList <Object > death = (ArrayList <Object >)headers .get ("x-death" );
357
- assertNotNull (death );
358
- assertEquals (1 , death .size ());
359
- assertDeathReason (death , 0 , TEST_QUEUE_NAME , reason ,
360
- "amq.direct" ,
361
- Arrays .asList (new String []{"test" }));
362
- }
363
- });
352
+ consume (channel , reason );
353
+ }
354
+
355
+ public static void consume (final Channel channel , final String reason ) throws IOException {
356
+ consumeN (channel , DLQ , MSG_COUNT , new WithResponse () {
357
+ @ SuppressWarnings ("unchecked" )
358
+ public void process (GetResponse getResponse ) {
359
+ Map <String , Object > headers = getResponse .getProps ().getHeaders ();
360
+ assertNotNull (headers );
361
+ ArrayList <Object > death = (ArrayList <Object >) headers .get ("x-death" );
362
+ assertNotNull (death );
363
+ assertEquals (1 , death .size ());
364
+ assertDeathReason (death , 0 , TEST_QUEUE_NAME , reason ,
365
+ "amq.direct" ,
366
+ Arrays .asList (new String []{"test" }));
367
+ }
368
+ });
364
369
}
365
370
366
371
private void ttlTest (final long ttl ) throws Exception {
@@ -455,6 +460,12 @@ private void waitUntil(long when) throws Exception {
455
460
456
461
private void consumeN (String queue , int n , WithResponse withResponse )
457
462
throws IOException
463
+ {
464
+ consumeN (channel , queue , n , withResponse );
465
+ }
466
+
467
+ private static void consumeN (Channel channel , String queue , int n , WithResponse withResponse )
468
+ throws IOException
458
469
{
459
470
for (int x = 0 ; x < n ; x ++) {
460
471
GetResponse getResponse =
@@ -469,7 +480,7 @@ private void consumeN(String queue, int n, WithResponse withResponse)
469
480
}
470
481
471
482
@ SuppressWarnings ("unchecked" )
472
- private void assertDeathReason (List <Object > death , int num ,
483
+ private static void assertDeathReason (List <Object > death , int num ,
473
484
String queue , String reason ,
474
485
String exchange , List <String > routingKeys )
475
486
{
@@ -489,7 +500,7 @@ private void assertDeathReason(List<Object> death, int num,
489
500
}
490
501
491
502
@ SuppressWarnings ("unchecked" )
492
- private void assertDeathReason (List <Object > death , int num ,
503
+ private static void assertDeathReason (List <Object > death , int num ,
493
504
String queue , String reason ) {
494
505
Map <String , Object > deathHeader =
495
506
(Map <String , Object >)death .get (num );
0 commit comments