Search in sources :

Example 66 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class OpenWireTestBase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = this.createServer(realStore, true);
    Configuration serverConfig = server.getConfiguration();
    serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ")).setAutoCreateAddresses(true));
    serverConfig.setSecurityEnabled(enableSecurity);
    extraServerConfig(serverConfig);
    if (enableSecurity) {
        ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
        securityManager.getConfiguration().addRole("openwireSender", "sender");
        securityManager.getConfiguration().addUser("openwireSender", "SeNdEr");
        // sender cannot receive
        Role senderRole = new Role("sender", true, false, false, false, true, true, false, false, true, true);
        securityManager.getConfiguration().addRole("openwireReceiver", "receiver");
        securityManager.getConfiguration().addUser("openwireReceiver", "ReCeIvEr");
        // receiver cannot send
        Role receiverRole = new Role("receiver", false, true, false, false, true, true, false, true, false, false);
        securityManager.getConfiguration().addRole("openwireGuest", "guest");
        securityManager.getConfiguration().addUser("openwireGuest", "GuEsT");
        // guest cannot do anything
        Role guestRole = new Role("guest", false, false, false, false, false, false, false, false, false, false);
        securityManager.getConfiguration().addRole("openwireDestinationManager", "manager");
        securityManager.getConfiguration().addUser("openwireDestinationManager", "DeStInAtIoN");
        Role destRole = new Role("manager", false, false, false, false, true, true, false, false, false, false);
        Set<Role> roles = new HashSet<>();
        roles.add(senderRole);
        roles.add(receiverRole);
        roles.add(guestRole);
        roles.add(destRole);
        server.getConfiguration().putSecurityRoles("#", roles);
    }
    mbeanServer = MBeanServerFactory.createMBeanServer();
    server.setMBeanServer(mbeanServer);
    addServer(server);
    jmsServer = new JMSServerManagerImpl(server);
    namingContext = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
    jmsServer.start();
    registerConnectionFactory();
    System.out.println("debug: server started");
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) HashSet(java.util.HashSet) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Before(org.junit.Before)

Example 67 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ManagementWithPagingServerTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true);
    server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, true));
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(5120).setMaxSizeBytes(10240).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(false).setConsumerWindowSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    session1 = sf.createSession(false, true, false);
    session1.start();
    session2 = sf.createSession(false, true, false);
    session2.start();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Before(org.junit.Before)

Example 68 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class QueueControlTest method testSendMessageToDeadLetterAddress.

@Test
public void testSendMessageToDeadLetterAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString deadLetterAddress = RandomUtil.randomSimpleString();
    SimpleString deadLetterQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    session.createQueue(deadLetterAddress, RoutingType.MULTICAST, deadLetterQueue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send 2 messages on queue
    producer.send(session.createMessage(durable));
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    QueueControl deadLetterQueueControl = createManagementControl(deadLetterAddress, deadLetterQueue);
    assertMessageMetrics(queueControl, 2, durable);
    // the message IDs are set on the server
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(2, messages.length);
    long messageID = (Long) messages[0].get("messageID");
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(deadLetterAddress);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    Assert.assertEquals(0, getMessageCount(deadLetterQueueControl));
    boolean movedToDeadLetterAddress = queueControl.sendMessageToDeadLetterAddress(messageID);
    Assert.assertTrue(movedToDeadLetterAddress);
    assertMessageMetrics(queueControl, 1, durable);
    Thread.sleep(200);
    assertMessageMetrics(deadLetterQueueControl, 1, durable);
    // check there is a single message to consume from queue
    consumeMessages(1, session, queue);
    // check there is a single message to consume from deadletter queue
    consumeMessages(1, session, deadLetterQueue);
    session.deleteQueue(queue);
    session.deleteQueue(deadLetterQueue);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Map(java.util.Map) HashMap(java.util.HashMap) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 69 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class QueueControlTest method testRetryMultipleMessages.

/**
 * Test retry multiple messages from  DLQ to original queue.
 */
@Test
public void testRetryMultipleMessages() throws Exception {
    final SimpleString dla = new SimpleString("DLA");
    final SimpleString qName = new SimpleString("q1");
    final SimpleString adName = new SimpleString("ad1");
    final SimpleString dlq = new SimpleString("DLQ1");
    final String sampleText = "Put me on DLQ";
    final int numMessagesToTest = 10;
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
    session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
    session.createQueue(adName, RoutingType.MULTICAST, qName, null, durable);
    // Send message to queue.
    ClientProducer producer = session.createProducer(adName);
    for (int i = 0; i < numMessagesToTest; i++) {
        producer.send(createTextMessage(session, sampleText));
    }
    session.start();
    final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(qName);
    Queue q = binding.getQueue();
    final LocalQueueBinding binding2 = (LocalQueueBinding) server.getPostOffice().getBinding(dlq);
    Queue q2 = binding2.getQueue();
    Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
    queueMemorySizeField.setAccessible(true);
    // Get memory size counters to verify
    AtomicInteger queueMemorySize1 = (AtomicInteger) queueMemorySizeField.get(q);
    AtomicInteger queueMemorySize2 = (AtomicInteger) queueMemorySizeField.get(q2);
    // Verify that original queue has a memory size greater than 0 and DLQ is 0
    assertTrue(queueMemorySize1.get() > 0);
    assertTrue(queueMemorySize2.get() == 0);
    // Read and rollback all messages to DLQ
    ClientConsumer clientConsumer = session.createConsumer(qName);
    for (int i = 0; i < numMessagesToTest; i++) {
        ClientMessage clientMessage = clientConsumer.receive(500);
        clientMessage.acknowledge();
        Assert.assertNotNull(clientMessage);
        Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
        session.rollback();
    }
    Assert.assertNull(clientConsumer.receiveImmediate());
    // Verify that original queue has a memory size of 0 and DLQ is greater than 0 after rollback
    assertTrue(queueMemorySize1.get() == 0);
    assertTrue(queueMemorySize2.get() > 0);
    QueueControl dlqQueueControl = createManagementControl(dla, dlq);
    assertMessageMetrics(dlqQueueControl, numMessagesToTest, durable);
    // Retry all messages - i.e. they should go from DLQ to original Queue.
    Assert.assertEquals(numMessagesToTest, dlqQueueControl.retryMessages());
    // Assert DLQ is empty...
    assertMessageMetrics(dlqQueueControl, 0, durable);
    // Verify that original queue has a memory size of greater than 0 and DLQ is 0 after move
    assertTrue(queueMemorySize1.get() > 0);
    assertTrue(queueMemorySize2.get() == 0);
    // .. and that the messages is now on the original queue once more.
    for (int i = 0; i < numMessagesToTest; i++) {
        ClientMessage clientMessage = clientConsumer.receive(500);
        clientMessage.acknowledge();
        Assert.assertNotNull(clientMessage);
        Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
    }
    clientConsumer.close();
    // Verify that original queue and DLQ have a memory size of 0
    assertTrue(queueMemorySize1.get() == 0);
    assertTrue(queueMemorySize2.get() == 0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Field(java.lang.reflect.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Queue(org.apache.activemq.artemis.core.server.Queue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 70 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class QueueControlTest method testExpireMessage.

@Test
public void testExpireMessage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString expiryAddress = RandomUtil.randomSimpleString();
    SimpleString expiryQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    session.createQueue(expiryAddress, RoutingType.MULTICAST, expiryQueue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    QueueControl expiryQueueControl = createManagementControl(expiryAddress, expiryQueue);
    assertMessageMetrics(queueControl, 1, durable);
    assertMessageMetrics(expiryQueueControl, 0, durable);
    // the message IDs are set on the server
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(1, messages.length);
    long messageID = (Long) messages[0].get("messageID");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    boolean expired = queueControl.expireMessage(messageID);
    Assert.assertTrue(expired);
    Thread.sleep(200);
    assertMessageMetrics(queueControl, 0, durable);
    assertMessageMetrics(expiryQueueControl, 1, durable);
    consumeMessages(0, session, queue);
    consumeMessages(1, session, expiryQueue);
    session.deleteQueue(queue);
    session.deleteQueue(expiryQueue);
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Map(java.util.Map) HashMap(java.util.HashMap) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) 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