@Test public void testDeadLetterAddressWithOverridenSublevelAddressSettings() throws Exception { int defaultDeliveryAttempt = 3; int specificeDeliveryAttempt = defaultDeliveryAttempt + 1; SimpleString address = new SimpleString("prefix.address"); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString defaultDeadLetterAddress = RandomUtil.randomSimpleString(); SimpleString defaultDeadLetterQueue = RandomUtil.randomSimpleString(); SimpleString specificDeadLetterAddress = RandomUtil.randomSimpleString(); SimpleString specificDeadLetterQueue = RandomUtil.randomSimpleString(); AddressSettings defaultAddressSettings = new AddressSettings() .setMaxDeliveryAttempts(defaultDeliveryAttempt) .setDeadLetterAddress(defaultDeadLetterAddress); server.getAddressSettingsRepository().addMatch("*", defaultAddressSettings); AddressSettings specificAddressSettings = new AddressSettings() .setMaxDeliveryAttempts(specificeDeliveryAttempt) .setDeadLetterAddress(specificDeadLetterAddress); server.getAddressSettingsRepository().addMatch(address.toString(), specificAddressSettings); clientSession.createQueue(address, queue, false); clientSession.createQueue(defaultDeadLetterAddress, defaultDeadLetterQueue, false); clientSession.createQueue(specificDeadLetterAddress, specificDeadLetterQueue, false); ClientProducer producer = clientSession.createProducer(address); ClientMessage clientMessage = createTextMessage(clientSession, "heyho!"); producer.send(clientMessage); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(queue); ClientConsumer defaultDeadLetterConsumer = clientSession.createConsumer(defaultDeadLetterQueue); ClientConsumer specificDeadLetterConsumer = clientSession.createConsumer(specificDeadLetterQueue); for (int i = 0; i < defaultDeliveryAttempt; i++) { ClientMessage m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(i + 1, m.getDeliveryCount()); m.acknowledge(); clientSession.rollback(); } Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate()); Assert.assertNull(specificDeadLetterConsumer.receiveImmediate()); // one more redelivery attempt: ClientMessage m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(specificeDeliveryAttempt, m.getDeliveryCount()); m.acknowledge(); clientSession.rollback(); Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate()); Assert.assertNotNull(specificDeadLetterConsumer.receive(500)); }
@Test public void testDeadlLetterAddressWithDefaultAddressSettings() throws Exception { int deliveryAttempt = 3; SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); SimpleString deadLetterAddress = RandomUtil.randomSimpleString(); SimpleString deadLetterQueue = RandomUtil.randomSimpleString(); AddressSettings addressSettings = new AddressSettings() .setMaxDeliveryAttempts(deliveryAttempt) .setDeadLetterAddress(deadLetterAddress); server.getAddressSettingsRepository().setDefault(addressSettings); clientSession.createQueue(address, queue, false); clientSession.createQueue(deadLetterAddress, deadLetterQueue, false); ClientProducer producer = clientSession.createProducer(address); ClientMessage clientMessage = createTextMessage(clientSession, "heyho!"); producer.send(clientMessage); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(queue); for (int i = 0; i < deliveryAttempt; i++) { ClientMessage m = clientConsumer.receive(500); Assert.assertNotNull(m); DeadLetterAddressTest.log.info("i is " + i); DeadLetterAddressTest.log.info("delivery cout is " + m.getDeliveryCount()); Assert.assertEquals(i + 1, m.getDeliveryCount()); m.acknowledge(); clientSession.rollback(); } ClientMessage m = clientConsumer.receive(500); Assert.assertNull("not expecting a message", m); clientConsumer.close(); clientConsumer = clientSession.createConsumer(deadLetterQueue); m = clientConsumer.receive(500); Assert.assertNotNull(m); Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!"); }