Search in sources :

Example 56 with MessageReference

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

the class QueueImplTest method testRate.

@Test
public void testRate() throws InterruptedException {
    QueueImpl queue = getTemporaryQueue();
    final int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        MessageReference ref = generateReference(queue, i);
        queue.addTail(ref);
    }
    Thread.sleep(1000);
    float rate = queue.getRate();
    Assert.assertTrue(rate <= 10.0f);
    System.out.println("Rate: " + rate);
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 57 with MessageReference

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

the class QueueImplTest method testResetMessagesAdded.

@Test
public void testResetMessagesAdded() throws Exception {
    QueueImpl queue = getTemporaryQueue();
    MessageReference messageReference = generateReference(queue, 1);
    MessageReference messageReference2 = generateReference(queue, 2);
    queue.addTail(messageReference);
    queue.addTail(messageReference2);
    Assert.assertEquals(2, getMessagesAdded(queue));
    queue.resetMessagesAdded();
    Assert.assertEquals(0, getMessagesAdded(queue));
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 58 with MessageReference

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

the class BridgeImpl method cancelRefs.

private void cancelRefs() {
    LinkedList<MessageReference> list = new LinkedList<>();
    synchronized (refs) {
        list.addAll(refs.values());
        refs.clear();
    }
    if (logger.isTraceEnabled()) {
        logger.trace("BridgeImpl::cancelRefs cancelling " + list.size() + " references");
    }
    if (logger.isTraceEnabled() && list.isEmpty()) {
        logger.trace("didn't have any references to cancel on bridge " + this);
        return;
    }
    ListIterator<MessageReference> listIterator = list.listIterator(list.size());
    Queue refqueue;
    long timeBase = System.currentTimeMillis();
    while (listIterator.hasPrevious()) {
        MessageReference ref = listIterator.previous();
        if (logger.isTraceEnabled()) {
            logger.trace("BridgeImpl::cancelRefs Cancelling reference " + ref + " on bridge " + this);
        }
        refqueue = ref.getQueue();
        try {
            refqueue.cancel(ref, timeBase);
        } catch (Exception e) {
            // There isn't much we can do besides log an error
            ActiveMQServerLogger.LOGGER.errorCancellingRefOnBridge(e, ref);
        }
    }
}
Also used : MessageReference(org.apache.activemq.artemis.core.server.MessageReference) Queue(org.apache.activemq.artemis.core.server.Queue) LinkedList(java.util.LinkedList) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 59 with MessageReference

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

the class MQTTRetainMessageManager method handleRetainedMessage.

/**
 * FIXME
 * Retained messages should be handled in the core API.  There is currently no support for retained messages
 * at the time of writing.  Instead we handle retained messages here.  This method will create a new queue for
 * every address that is used to store retained messages.  THere should only ever be one message in the retained
 * message queue.  When a new subscription is created the queue should be browsed and the message copied onto
 * the subscription queue for the consumer.  When a new retained message is received the message will be sent to
 * the retained queue and the previous retain message consumed to remove it from the queue.
 */
void handleRetainedMessage(Message message, String address, boolean reset, Transaction tx) throws Exception {
    SimpleString retainAddress = new SimpleString(MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration()));
    Queue queue = session.getServer().locateQueue(retainAddress);
    if (queue == null) {
        queue = session.getServer().createQueue(retainAddress, retainAddress, null, true, false);
    }
    try (LinkedListIterator<MessageReference> iterator = queue.iterator()) {
        synchronized (queue) {
            if (iterator.hasNext()) {
                MessageReference ref = iterator.next();
                iterator.remove();
                queue.acknowledge(tx, ref);
            }
            if (!reset) {
                sendToQueue(message.copy(session.getServer().getStorageManager().generateID()), queue, tx);
            }
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 60 with MessageReference

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

the class AMQConsumer method acknowledge.

/**
 * The acknowledgement in openwire is done based on intervals.
 * We will iterate through the list of delivering messages at {@link ServerConsumer#getDeliveringReferencesBasedOnProtocol(boolean, Object, Object)}
 * and add those to the Transaction.
 * Notice that we will start a new transaction on the cases where there is no transaction.
 */
public void acknowledge(MessageAck ack) throws Exception {
    MessageId first = ack.getFirstMessageId();
    MessageId last = ack.getLastMessageId();
    if (first == null) {
        first = last;
    }
    // if it's browse only, nothing to be acked, we just remove the lists
    boolean removeReferences = !serverConsumer.isBrowseOnly();
    if (ack.isRedeliveredAck() || ack.isDeliveredAck() || ack.isExpiredAck()) {
        removeReferences = false;
    }
    List<MessageReference> ackList = serverConsumer.getDeliveringReferencesBasedOnProtocol(removeReferences, first, last);
    acquireCredit(ack.getMessageCount());
    if (removeReferences) {
        Transaction originalTX = session.getCoreSession().getCurrentTransaction();
        Transaction transaction;
        if (originalTX == null) {
            transaction = session.getCoreSession().newTransaction();
        } else {
            transaction = originalTX;
        }
        if (ack.isIndividualAck() || ack.isStandardAck()) {
            for (MessageReference ref : ackList) {
                ref.acknowledge(transaction);
            }
        } else if (ack.isPoisonAck()) {
            for (MessageReference ref : ackList) {
                Throwable poisonCause = ack.getPoisonCause();
                if (poisonCause != null) {
                    ref.getMessage().putStringProperty(OpenWireMessageConverter.AMQ_MSG_DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY, new SimpleString(poisonCause.toString()));
                }
                ref.getQueue().sendToDeadLetterAddress(transaction, ref);
            }
        }
        if (originalTX == null) {
            transaction.commit(true);
        }
    }
    if (ack.isExpiredAck()) {
        for (MessageReference ref : ackList) {
            ref.getQueue().expire(ref);
        }
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) MessageId(org.apache.activemq.command.MessageId)

Aggregations

MessageReference (org.apache.activemq.artemis.core.server.MessageReference)82 ArrayList (java.util.ArrayList)29 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)26 Test (org.junit.Test)26 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)14 Message (org.apache.activemq.artemis.api.core.Message)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)11 Queue (org.apache.activemq.artemis.core.server.Queue)10 HashMap (java.util.HashMap)9 NoSuchElementException (java.util.NoSuchElementException)9 Map (java.util.Map)8 Filter (org.apache.activemq.artemis.core.filter.Filter)7 LinkedList (java.util.LinkedList)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 BindingsTransactionImpl (org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl)4 HashSet (java.util.HashSet)3