Search in sources :

Example 11 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class ThreeBrokerQueueNetworkTest method verifyConsumePriority.

private void verifyConsumePriority(BrokerService broker, byte expectedPriority, Destination dest) throws Exception {
    RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
    Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
    for (Subscription consumer : internalQueue.getConsumers()) {
        assertEquals("consumer on " + broker.getBrokerName() + " matches priority: " + internalQueue, expectedPriority, consumer.getConsumerInfo().getPriority());
    }
}
Also used : RegionBroker(org.apache.activemq.broker.region.RegionBroker) Subscription(org.apache.activemq.broker.region.Subscription) Queue(org.apache.activemq.broker.region.Queue)

Example 12 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class QueueMemoryFullMultiBrokersTest method testQueueNetworkWithConsumerFull.

public void testQueueNetworkWithConsumerFull() throws Exception {
    bridgeAllBrokers();
    startAllBrokers();
    Destination dest = createDestination("TEST.FOO", false);
    sendMessages("Broker1", dest, 50);
    CountDownLatch latch = new CountDownLatch(MESSAGE_COUNT);
    createConsumer("Broker2", dest, latch);
    assertConsumersConnect("Broker1", dest, 1, 30000);
    sendMessages("Broker1", dest, MESSAGE_COUNT - 50);
    // Wait for messages to be delivered
    assertTrue("Missing " + latch.getCount() + " messages", latch.await(45, TimeUnit.SECONDS));
    // verify stats, all messages acked
    BrokerService broker1 = brokers.get("Broker1").broker;
    RegionBroker regionBroker = (RegionBroker) broker1.getRegionBroker();
    // give the acks a chance to flow
    Thread.sleep(2000);
    Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
    assertTrue("All messages are consumed and acked from source:" + internalQueue, internalQueue.getMessages().isEmpty());
    assertEquals("messages source:" + internalQueue, 0, internalQueue.getDestinationStatistics().getMessages().getCount());
    assertEquals("inflight source:" + internalQueue, 0, internalQueue.getDestinationStatistics().getInflight().getCount());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) RegionBroker(org.apache.activemq.broker.region.RegionBroker) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerService(org.apache.activemq.broker.BrokerService) Queue(org.apache.activemq.broker.region.Queue)

Example 13 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class StoreQueueCursorNoDuplicateTest method testNoDuplicateAfterCacheFullAndReadPast.

public void testNoDuplicateAfterCacheFullAndReadPast() throws Exception {
    final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
    queueMessageStore.start();
    queueMessageStore.registerIndexListener(null);
    QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
    SystemUsage systemUsage = new SystemUsage();
    // ensure memory limit is reached
    systemUsage.getMemoryUsage().setLimit(messageBytesSize * (count + 2));
    underTest.setSystemUsage(systemUsage);
    underTest.setEnableAudit(false);
    underTest.start();
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    final ConnectionContext contextNotInTx = new ConnectionContext();
    for (int i = 0; i < count; i++) {
        ActiveMQTextMessage msg = getMessage(i);
        msg.setMemoryUsage(systemUsage.getMemoryUsage());
        queueMessageStore.addMessage(contextNotInTx, msg);
        underTest.addMessageLast(msg);
    }
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    int dequeueCount = 0;
    underTest.setMaxBatchSize(2);
    underTest.reset();
    while (underTest.hasNext() && dequeueCount < count) {
        MessageReference ref = underTest.next();
        ref.decrementReferenceCount();
        underTest.remove();
        LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
        assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
    }
    underTest.release();
    assertEquals(count, dequeueCount);
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) SystemUsage(org.apache.activemq.usage.SystemUsage) ConnectionContext(org.apache.activemq.broker.ConnectionContext) MessageReference(org.apache.activemq.broker.region.MessageReference) Queue(org.apache.activemq.broker.region.Queue) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 14 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class StoreQueueCursorOrderTest method testNoSetBatchWithUnOrderedFutureCurrentSync.

@Test
public void testNoSetBatchWithUnOrderedFutureCurrentSync() throws Exception {
    final int count = 2;
    final Message[] messages = new Message[count];
    final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
    queueMessageStore.start();
    queueMessageStore.registerIndexListener(null);
    QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
    SystemUsage systemUsage = new SystemUsage();
    // ensure memory limit is reached
    systemUsage.getMemoryUsage().setLimit(messageBytesSize * 1);
    underTest.setSystemUsage(systemUsage);
    underTest.setEnableAudit(false);
    underTest.start();
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    ActiveMQTextMessage msg = getMessage(0);
    messages[1] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.setRecievedByDFBridge(true);
    final ActiveMQTextMessage msgRef = msg;
    FutureTask<Long> future = new FutureTask<Long>(new Runnable() {

        @Override
        public void run() {
            msgRef.getMessageId().setFutureOrSequenceLong(1L);
        }
    }, 1L) {
    };
    msg.getMessageId().setFutureOrSequenceLong(future);
    Executors.newSingleThreadExecutor().submit(future);
    underTest.addMessageLast(msg);
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    // second message will flip the cache but will be stored before the future task
    msg = getMessage(1);
    messages[0] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.getMessageId().setFutureOrSequenceLong(1L);
    underTest.addMessageLast(msg);
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    assertEquals("setBatch unset", 0L, queueMessageStore.batch.get());
    int dequeueCount = 0;
    underTest.setMaxBatchSize(2);
    underTest.reset();
    while (underTest.hasNext() && dequeueCount < count) {
        MessageReference ref = underTest.next();
        ref.decrementReferenceCount();
        underTest.remove();
        LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
        assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
    }
    underTest.release();
    assertEquals(count, dequeueCount);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) SystemUsage(org.apache.activemq.usage.SystemUsage) MessageReference(org.apache.activemq.broker.region.MessageReference) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) FutureTask(java.util.concurrent.FutureTask) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(org.apache.activemq.broker.region.Queue) Test(org.junit.Test)

Example 15 with Queue

use of org.apache.activemq.broker.region.Queue in project fabric8 by jboss-fuse.

the class LocalBrokerFacade method purgeQueue.

public void purgeQueue(ActiveMQDestination destination) throws Exception {
    Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
    for (Iterator i = destinations.iterator(); i.hasNext(); ) {
        Destination dest = (Destination) i.next();
        if (dest instanceof Queue) {
            Queue regionQueue = (Queue) dest;
            regionQueue.purge();
        }
    }
}
Also used : Destination(org.apache.activemq.broker.region.Destination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Set(java.util.Set) Iterator(java.util.Iterator) Queue(org.apache.activemq.broker.region.Queue)

Aggregations

Queue (org.apache.activemq.broker.region.Queue)15 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 MessageReference (org.apache.activemq.broker.region.MessageReference)6 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)6 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)6 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)6 SystemUsage (org.apache.activemq.usage.SystemUsage)6 Message (org.apache.activemq.command.Message)5 Test (org.junit.Test)5 FutureTask (java.util.concurrent.FutureTask)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4 RegionBroker (org.apache.activemq.broker.region.RegionBroker)4 Connection (javax.jms.Connection)3 Message (javax.jms.Message)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)3 NonCachedMessageEvaluationContext (org.apache.activemq.filter.NonCachedMessageEvaluationContext)3 BrokerService (org.apache.activemq.broker.BrokerService)2