Search in sources :

Example 71 with AddressSettings

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();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 72 with AddressSettings

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);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 73 with AddressSettings

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());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 74 with AddressSettings

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());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 75 with AddressSettings

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();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Connection(javax.jms.Connection) Queue(org.apache.activemq.artemis.core.server.Queue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14