use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class QueueControlTest method testRetryDivertedMessage.
/**
* Test retry - get a diverted message from DLQ and put on original queue.
*/
@Test
public void testRetryDivertedMessage() throws Exception {
final SimpleString dla = new SimpleString("DLA");
final SimpleString dlq = new SimpleString("DLQ");
final SimpleString forwardingQueue = new SimpleString("forwardingQueue");
final SimpleString forwardingAddress = new SimpleString("forwardingAddress");
final SimpleString myTopic = new SimpleString("myTopic");
final String sampleText = "Put me on DLQ";
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
server.getAddressSettingsRepository().addMatch(forwardingAddress.toString(), addressSettings);
// create target queue, DLQ and source topic
session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
session.createQueue(forwardingAddress, RoutingType.MULTICAST, forwardingQueue, null, durable);
session.createAddress(myTopic, RoutingType.MULTICAST, false);
DivertConfiguration divert = new DivertConfiguration().setName("local-divert").setRoutingName("some-name").setAddress(myTopic.toString()).setForwardingAddress(forwardingAddress.toString()).setExclusive(false);
server.deployDivert(divert);
// Send message to topic.
ClientProducer producer = session.createProducer(myTopic);
producer.send(createTextMessage(session, sampleText));
session.start();
ClientConsumer clientConsumer = session.createConsumer(forwardingQueue);
ClientMessage clientMessage = clientConsumer.receive(500);
clientMessage.acknowledge();
Assert.assertNotNull(clientMessage);
Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
// force a rollback to DLQ
session.rollback();
clientMessage = clientConsumer.receiveImmediate();
Assert.assertNull(clientMessage);
QueueControl queueControl = createManagementControl(dla, dlq, RoutingType.MULTICAST);
assertMessageMetrics(queueControl, 1, durable);
final long messageID = getFirstMessageId(queueControl);
// Retry the message - i.e. it should go from DLQ to original Queue.
Assert.assertTrue(queueControl.retryMessage(messageID));
// Assert DLQ is empty...
assertMessageMetrics(queueControl, 0, durable);
// .. and that the message is now on the original queue once more.
clientMessage = clientConsumer.receive(500);
// fails because of AMQ222196 !!!
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
Assert.assertEquals(sampleText, clientMessage.getBodyBuffer().readString());
clientConsumer.close();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class QueueControlTest method testSetExpiryAddress.
@Test
public void testSetExpiryAddress() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
String expiryAddress = RandomUtil.randomString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
AddressSettings addressSettings = new AddressSettings().setExpiryAddress(new SimpleString(expiryAddress));
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
Assert.assertEquals(expiryAddress, queueControl.getExpiryAddress());
Queue serverqueue = server.locateQueue(queue);
assertEquals(expiryAddress, serverqueue.getExpiryAddress().toString());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class AddressControlTest method testGetNumberOfPages.
@Test
public void testGetNumberOfPages() throws Exception {
session.close();
server.stop();
server.getConfiguration().setPersistenceEnabled(true);
SimpleString address = RandomUtil.randomSimpleString();
AddressSettings addressSettings = new AddressSettings().setPageSizeBytes(1024).setMaxSizeBytes(10 * 1024);
final int NUMBER_MESSAGES_BEFORE_PAGING = 7;
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
server.start();
ServerLocator locator2 = createInVMNonHALocator();
addServerLocator(locator2);
ClientSessionFactory sf2 = createSessionFactory(locator2);
session = sf2.createSession(false, true, false);
session.start();
session.createQueue(address, address, true);
QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);
ClientProducer producer = session.createProducer(address);
for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
}
session.commit();
AddressControl addressControl = createManagementControl(address);
Assert.assertEquals(0, addressControl.getNumberOfPages());
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals(1, addressControl.getNumberOfPages());
msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals(1, addressControl.getNumberOfPages());
msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[896]);
producer.send(msg);
session.commit();
Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());
System.out.println("Address size=" + addressControl.getAddressSize());
Assert.assertEquals(serverQueue.getPageSubscription().getPagingStore().getAddressSize(), addressControl.getAddressSize());
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class AddressControlTest method testGetNumberOfBytesPerPage.
@Test
public void testGetNumberOfBytesPerPage() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
session.createQueue(address, address, true);
AddressControl addressControl = createManagementControl(address);
Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), addressControl.getNumberOfBytesPerPage());
session.close();
server.stop();
AddressSettings addressSettings = new AddressSettings();
addressSettings.setPageSizeBytes(1024);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
server.start();
ServerLocator locator2 = createInVMNonHALocator();
ClientSessionFactory sf2 = createSessionFactory(locator2);
session = sf2.createSession(false, true, false);
session.createQueue(address, address, true);
Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class JmsConsumerTest method defaultAutoCreatedQueueConfigTest.
@Test
public void defaultAutoCreatedQueueConfigTest() throws Exception {
final String queueName = "q1";
server.getAddressSettingsRepository().addMatch(queueName, new AddressSettings().setDefaultMaxConsumers(5).setDefaultPurgeOnNoConsumers(true));
Connection connection = cf.createConnection();
Session session = connection.createSession();
session.createConsumer(session.createQueue(queueName));
org.apache.activemq.artemis.core.server.Queue queue = server.locateQueue(SimpleString.toSimpleString(queueName));
assertEquals(5, queue.getMaxConsumers());
assertEquals(true, queue.isPurgeOnNoConsumers());
connection.close();
}
Aggregations