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);
}
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));
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations