@@ -109,10 +109,7 @@ public void run() {
109109 public void testDeadLetterExchangeDeleteTwice ()
110110 throws IOException
111111 {
112- Map <String , Object > args = new HashMap <String , Object >();
113- args .put ("x-message-ttl" , 1 );
114-
115- declareQueue (TEST_QUEUE_NAME , DLX , null , args );
112+ declareQueue (TEST_QUEUE_NAME , DLX , null , null , 1 );
116113
117114 publishN (MSG_COUNT_MANY , PropertiesFactory .NULL );
118115 channel .queueDelete (TEST_QUEUE_NAME );
@@ -153,16 +150,15 @@ public Void call() throws Exception {
153150
154151 public void testDeadLetterNoDeadLetterQueue () throws IOException {
155152 channel .queueDelete (DLQ );
156- declareQueue (DLX );
153+ declareQueue (TEST_QUEUE_NAME , DLX , null , null , 1 );
157154 channel .queueBind (TEST_QUEUE_NAME , "amq.direct" , "test" );
158155 publishN (MSG_COUNT , PropertiesFactory .NULL );
159- channel .queuePurge (TEST_QUEUE_NAME );
160156 }
161157
162158 public void testDeadLetterMultipleDeadLetterQueues ()
163159 throws IOException
164160 {
165- declareQueue (DLX );
161+ declareQueue (TEST_QUEUE_NAME , DLX , null , null , 1 );
166162
167163 channel .queueDeclare (DLQ2 , false , true , false , null );
168164
@@ -171,17 +167,13 @@ public void testDeadLetterMultipleDeadLetterQueues()
171167 channel .queueBind (DLQ2 , DLX , "test" );
172168
173169 publishN (MSG_COUNT , PropertiesFactory .NULL );
174- channel .queuePurge (TEST_QUEUE_NAME );
175170 }
176171
177172 public void testDeadLetterTwice () throws Exception {
178- Map <String , Object > args = new HashMap <String , Object >();
179- args .put ("x-message-ttl" , 1 );
180-
181- declareQueue (TEST_QUEUE_NAME , DLX , null , args );
173+ declareQueue (TEST_QUEUE_NAME , DLX , null , null , 1 );
182174
183175 channel .queueDelete (DLQ );
184- declareQueue (DLQ , DLX , null , args );
176+ declareQueue (DLQ , DLX , null , null , 1 );
185177
186178 channel .queueDeclare (DLQ2 , false , true , false , null );
187179
@@ -215,11 +207,10 @@ public void process(GetResponse getResponse) {
215207 }
216208
217209 public void testDeadLetterSelf () throws Exception {
218- declareQueue (TEST_QUEUE_NAME , "amq.direct" , "test" , null );
210+ declareQueue (TEST_QUEUE_NAME , "amq.direct" , "test" , null , 1 );
219211 channel .queueBind (TEST_QUEUE_NAME , "amq.direct" , "test" );
220212
221213 publishN (MSG_COUNT_MANY , PropertiesFactory .NULL );
222- channel .queuePurge (TEST_QUEUE_NAME );
223214 sleep (100 );
224215
225216 // The messages will NOT be dead-lettered to self.
@@ -230,9 +221,7 @@ public void process(GetResponse getResponse) {
230221 }
231222
232223 public void testDeadLetterNewRK () throws Exception {
233- Map <String , Object > args = new HashMap <String , Object >();
234- args .put ("x-message-ttl" , 1 );
235- declareQueue (TEST_QUEUE_NAME , DLX , "test-other" , args );
224+ declareQueue (TEST_QUEUE_NAME , DLX , "test-other" , null , 1 );
236225
237226 channel .queueDeclare (DLQ2 , false , true , false , null );
238227
@@ -334,10 +323,22 @@ private void declareQueue(Object deadLetterExchange) throws IOException {
334323 private void declareQueue (String queue , Object deadLetterExchange ,
335324 Object deadLetterRoutingKey ,
336325 Map <String , Object > args ) throws IOException {
326+ declareQueue (queue , deadLetterExchange , deadLetterRoutingKey , args , 0 );
327+ }
328+
329+ private void declareQueue (String queue , Object deadLetterExchange ,
330+ Object deadLetterRoutingKey ,
331+ Map <String , Object > args , int ttl )
332+ throws IOException
333+ {
337334 if (args == null ) {
338335 args = new HashMap <String , Object >();
339336 }
340337
338+ if (ttl > 0 ){
339+ args .put ("x-message-ttl" , 1 );
340+ }
341+
341342 args .put (DLX_ARG , deadLetterExchange );
342343 if (deadLetterRoutingKey != null ) {
343344 args .put (DLX_RK_ARG , deadLetterRoutingKey );
0 commit comments