Search in sources :

Example 51 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class ManagementServiceImplTest method testGetResources.

@Test
public void testGetResources() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ManagementServiceImpl managementService = new ManagementServiceImpl(null, config);
    managementService.setStorageManager(new NullStorageManager());
    SimpleString address = RandomUtil.randomSimpleString();
    managementService.registerAddress(new AddressInfo(address));
    Queue queue = new FakeQueue(RandomUtil.randomSimpleString());
    managementService.registerQueue(queue, RandomUtil.randomSimpleString(), new FakeStorageManager());
    Object[] addresses = managementService.getResources(AddressControl.class);
    Assert.assertEquals(1, addresses.length);
    Assert.assertTrue(addresses[0] instanceof AddressControl);
    AddressControl addressControl = (AddressControl) addresses[0];
    Assert.assertEquals(address.toString(), addressControl.getAddress());
    Object[] queues = managementService.getResources(QueueControl.class);
    Assert.assertEquals(1, queues.length);
    Assert.assertTrue(queues[0] instanceof QueueControl);
    QueueControl queueControl = (QueueControl) queues[0];
    Assert.assertEquals(queue.getName().toString(), queueControl.getName());
}
Also used : ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) FakeStorageManager(org.apache.activemq.artemis.tests.integration.server.FakeStorageManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 52 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class QueueControlTest method testListDeliveringMessages.

@Test
public void testListDeliveringMessages() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    int intValue = RandomUtil.randomInt();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    Queue srvqueue = server.locateQueue(queue);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(durable);
    message.putIntProperty(new SimpleString("key"), intValue);
    producer.send(message);
    producer.send(session.createMessage(durable));
    ClientConsumer consumer = session.createConsumer(queue);
    session.start();
    ClientMessage msgRec = consumer.receive(5000);
    assertNotNull(msgRec);
    assertEquals(msgRec.getIntProperty("key").intValue(), intValue);
    ClientSessionFactory sf2 = createSessionFactory(locator);
    ClientSession session2 = sf2.createSession(false, true, false);
    ClientConsumer consumer2 = session2.createConsumer(queue);
    session2.start();
    ClientMessage msgRec2 = consumer2.receive(5000);
    assertNotNull(msgRec2);
    assertEquals(2, srvqueue.getDeliveringCount());
    assertEquals(2, srvqueue.getConsumerCount());
    System.out.println(queueControl.listDeliveringMessagesAsJSON());
    Map<String, Map<String, Object>[]> deliveringMap = queueControl.listDeliveringMessages();
    assertEquals(2, deliveringMap.size());
    consumer.close();
    consumer2.close();
    session.deleteQueue(queue);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 53 with Queue

use of org.apache.activemq.artemis.core.server.Queue 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 54 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class QueueControlTest method testRemoveAllWithPagingMode.

@Test
public void testRemoveAllWithPagingMode() throws Exception {
    // 3k
    final int MESSAGE_SIZE = 1024 * 3;
    // reset maxSize for Paging mode
    Field maxSizField = PagingManagerImpl.class.getDeclaredField("maxSize");
    maxSizField.setAccessible(true);
    maxSizField.setLong(server.getPagingManager(), 10240);
    clearDataRecreateServerDirs();
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queueName = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queueName, null, durable);
    Queue queue = server.locateQueue(queueName);
    Assert.assertEquals(false, queue.getPageSubscription().isPaging());
    ClientProducer producer = session.createProducer(address);
    byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    final int numberOfMessages = 8000;
    ClientMessage message;
    for (int i = 0; i < numberOfMessages; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        producer.send(message);
    }
    Assert.assertEquals(true, queue.getPageSubscription().isPaging());
    QueueControl queueControl = createManagementControl(address, queueName);
    assertMessageMetrics(queueControl, numberOfMessages, durable);
    int removedMatchedMessagesCount = queueControl.removeAllMessages();
    Assert.assertEquals(numberOfMessages, removedMatchedMessagesCount);
    assertMessageMetrics(queueControl, 0, durable);
    Field queueMemoprySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
    queueMemoprySizeField.setAccessible(true);
    AtomicInteger queueMemorySize = (AtomicInteger) queueMemoprySizeField.get(queue);
    Assert.assertEquals(0, queueMemorySize.get());
    session.deleteQueue(queueName);
}
Also used : Field(java.lang.reflect.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ByteBuffer(java.nio.ByteBuffer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 55 with Queue

use of org.apache.activemq.artemis.core.server.Queue 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)

Aggregations

Queue (org.apache.activemq.artemis.core.server.Queue)275 Test (org.junit.Test)193 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)128 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)89 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)85 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)75 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)70 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)70 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)70 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)64 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)59 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)56 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)49 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)47 Session (javax.jms.Session)36 Connection (javax.jms.Connection)32 Configuration (org.apache.activemq.artemis.core.config.Configuration)31 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)30 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)27 TextMessage (javax.jms.TextMessage)25