Search in sources :

Example 36 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class MessageImplTest method testProperties.

@Test
public void testProperties() {
    for (int j = 0; j < 10; j++) {
        Message msg = new ClientMessageImpl();
        SimpleString prop1 = new SimpleString("prop1");
        boolean val1 = RandomUtil.randomBoolean();
        msg.putBooleanProperty(prop1, val1);
        SimpleString prop2 = new SimpleString("prop2");
        byte val2 = RandomUtil.randomByte();
        msg.putByteProperty(prop2, val2);
        SimpleString prop3 = new SimpleString("prop3");
        byte[] val3 = RandomUtil.randomBytes();
        msg.putBytesProperty(prop3, val3);
        SimpleString prop4 = new SimpleString("prop4");
        double val4 = RandomUtil.randomDouble();
        msg.putDoubleProperty(prop4, val4);
        SimpleString prop5 = new SimpleString("prop5");
        float val5 = RandomUtil.randomFloat();
        msg.putFloatProperty(prop5, val5);
        SimpleString prop6 = new SimpleString("prop6");
        int val6 = RandomUtil.randomInt();
        msg.putIntProperty(prop6, val6);
        SimpleString prop7 = new SimpleString("prop7");
        long val7 = RandomUtil.randomLong();
        msg.putLongProperty(prop7, val7);
        SimpleString prop8 = new SimpleString("prop8");
        short val8 = RandomUtil.randomShort();
        msg.putShortProperty(prop8, val8);
        SimpleString prop9 = new SimpleString("prop9");
        SimpleString val9 = new SimpleString(RandomUtil.randomString());
        msg.putStringProperty(prop9, val9);
        Assert.assertEquals(9, msg.getPropertyNames().size());
        Assert.assertTrue(msg.getPropertyNames().contains(prop1));
        Assert.assertTrue(msg.getPropertyNames().contains(prop2));
        Assert.assertTrue(msg.getPropertyNames().contains(prop3));
        Assert.assertTrue(msg.getPropertyNames().contains(prop4));
        Assert.assertTrue(msg.getPropertyNames().contains(prop5));
        Assert.assertTrue(msg.getPropertyNames().contains(prop6));
        Assert.assertTrue(msg.getPropertyNames().contains(prop7));
        Assert.assertTrue(msg.getPropertyNames().contains(prop8));
        Assert.assertTrue(msg.getPropertyNames().contains(prop9));
        Assert.assertTrue(msg.containsProperty(prop1));
        Assert.assertTrue(msg.containsProperty(prop2));
        Assert.assertTrue(msg.containsProperty(prop3));
        Assert.assertTrue(msg.containsProperty(prop4));
        Assert.assertTrue(msg.containsProperty(prop5));
        Assert.assertTrue(msg.containsProperty(prop6));
        Assert.assertTrue(msg.containsProperty(prop7));
        Assert.assertTrue(msg.containsProperty(prop8));
        Assert.assertTrue(msg.containsProperty(prop9));
        Assert.assertEquals(val1, msg.getObjectProperty(prop1));
        Assert.assertEquals(val2, msg.getObjectProperty(prop2));
        Assert.assertEquals(val3, msg.getObjectProperty(prop3));
        Assert.assertEquals(val4, msg.getObjectProperty(prop4));
        Assert.assertEquals(val5, msg.getObjectProperty(prop5));
        Assert.assertEquals(val6, msg.getObjectProperty(prop6));
        Assert.assertEquals(val7, msg.getObjectProperty(prop7));
        Assert.assertEquals(val8, msg.getObjectProperty(prop8));
        Assert.assertEquals(val9, msg.getObjectProperty(prop9));
        SimpleString val10 = new SimpleString(RandomUtil.randomString());
        // test overwrite
        msg.putStringProperty(prop9, val10);
        Assert.assertEquals(val10, msg.getObjectProperty(prop9));
        int val11 = RandomUtil.randomInt();
        msg.putIntProperty(prop9, val11);
        Assert.assertEquals(val11, msg.getObjectProperty(prop9));
        msg.removeProperty(prop1);
        Assert.assertEquals(8, msg.getPropertyNames().size());
        Assert.assertTrue(msg.getPropertyNames().contains(prop2));
        Assert.assertTrue(msg.getPropertyNames().contains(prop3));
        Assert.assertTrue(msg.getPropertyNames().contains(prop4));
        Assert.assertTrue(msg.getPropertyNames().contains(prop5));
        Assert.assertTrue(msg.getPropertyNames().contains(prop6));
        Assert.assertTrue(msg.getPropertyNames().contains(prop7));
        Assert.assertTrue(msg.getPropertyNames().contains(prop8));
        Assert.assertTrue(msg.getPropertyNames().contains(prop9));
        msg.removeProperty(prop2);
        Assert.assertEquals(7, msg.getPropertyNames().size());
        Assert.assertTrue(msg.getPropertyNames().contains(prop3));
        Assert.assertTrue(msg.getPropertyNames().contains(prop4));
        Assert.assertTrue(msg.getPropertyNames().contains(prop5));
        Assert.assertTrue(msg.getPropertyNames().contains(prop6));
        Assert.assertTrue(msg.getPropertyNames().contains(prop7));
        Assert.assertTrue(msg.getPropertyNames().contains(prop8));
        Assert.assertTrue(msg.getPropertyNames().contains(prop9));
        msg.removeProperty(prop9);
        Assert.assertEquals(6, msg.getPropertyNames().size());
        Assert.assertTrue(msg.getPropertyNames().contains(prop3));
        Assert.assertTrue(msg.getPropertyNames().contains(prop4));
        Assert.assertTrue(msg.getPropertyNames().contains(prop5));
        Assert.assertTrue(msg.getPropertyNames().contains(prop6));
        Assert.assertTrue(msg.getPropertyNames().contains(prop7));
        Assert.assertTrue(msg.getPropertyNames().contains(prop8));
        msg.removeProperty(prop3);
        msg.removeProperty(prop4);
        msg.removeProperty(prop5);
        msg.removeProperty(prop6);
        msg.removeProperty(prop7);
        msg.removeProperty(prop8);
        Assert.assertEquals(0, msg.getPropertyNames().size());
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessageImpl(org.apache.activemq.artemis.core.client.impl.ClientMessageImpl) Test(org.junit.Test)

Example 37 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class DivertImpl method route.

@Override
public void route(final Message message, final RoutingContext context) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("Diverting message " + message + " into " + this);
    }
    Message copy = null;
    // Shouldn't copy if it's not routed anywhere else
    if (!forwardAddress.equals(context.getAddress(message))) {
        long id = storageManager.generateID();
        copy = message.copy(id);
        // This will set the original MessageId, and the original address
        copy.referenceOriginalMessage(message, this.getUniqueName().toString());
        copy.setAddress(forwardAddress);
        copy.setExpiration(message.getExpiration());
        copy.reencode();
        switch(routingType) {
            case ANYCAST:
                copy.setRoutingType(RoutingType.ANYCAST);
                break;
            case MULTICAST:
                copy.setRoutingType(RoutingType.MULTICAST);
                break;
            case STRIP:
                copy.setRoutingType(null);
                break;
            case PASS:
                break;
        }
        if (transformer != null) {
            copy = transformer.transform(copy);
        }
    } else {
        copy = message;
    }
    postOffice.route(copy, context.getTransaction(), false);
}
Also used : Message(org.apache.activemq.artemis.api.core.Message)

Example 38 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class QueueImpl method acknowledge.

@Override
public void acknowledge(final MessageReference ref, AckReason reason) throws Exception {
    if (ref.isPaged()) {
        pageSubscription.ack((PagedReference) ref);
        postAcknowledge(ref);
    } else {
        Message message = ref.getMessage();
        boolean durableRef = message.isDurable() && isDurableMessage();
        if (durableRef) {
            storageManager.storeAcknowledge(id, message.getMessageID());
        }
        postAcknowledge(ref);
    }
    if (reason == AckReason.EXPIRED) {
        messagesExpired.incrementAndGet();
    } else if (reason == AckReason.KILLED) {
        messagesKilled.incrementAndGet();
    } else {
        messagesAcknowledged.incrementAndGet();
    }
    if (server != null && server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.messageAcknowledged(ref, reason));
    }
}
Also used : Message(org.apache.activemq.artemis.api.core.Message)

Example 39 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class QueueImpl method move.

private void move(final Transaction originalTX, final SimpleString address, final Binding binding, final MessageReference ref, final boolean rejectDuplicate, final AckReason reason) throws Exception {
    Transaction tx;
    if (originalTX != null) {
        tx = originalTX;
    } else {
        // if no TX we create a new one to commit at the end
        tx = new TransactionImpl(storageManager);
    }
    Message copyMessage = makeCopy(ref, reason == AckReason.EXPIRED);
    copyMessage.setAddress(address);
    postOffice.route(copyMessage, tx, false, rejectDuplicate, binding);
    acknowledge(tx, ref, reason);
    if (originalTX == null) {
        tx.commit();
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Message(org.apache.activemq.artemis.api.core.Message) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) BindingsTransactionImpl(org.apache.activemq.artemis.core.transaction.impl.BindingsTransactionImpl)

Example 40 with Message

use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.

the class QueueImpl method checkRedelivery.

@Override
public boolean checkRedelivery(final MessageReference reference, final long timeBase, final boolean ignoreRedeliveryDelay) throws Exception {
    Message message = reference.getMessage();
    if (internalQueue) {
        if (logger.isTraceEnabled()) {
            logger.trace("Queue " + this.getName() + " is an internal queue, no checkRedelivery");
        }
        // no DLQ check on internal queues
        return true;
    }
    if (!internalQueue && message.isDurable() && isDurableMessage() && !reference.isPaged()) {
        storageManager.updateDeliveryCount(reference);
    }
    AddressSettings addressSettings = addressSettingsRepository.getMatch(address.toString());
    int maxDeliveries = addressSettings.getMaxDeliveryAttempts();
    long redeliveryDelay = addressSettings.getRedeliveryDelay();
    int deliveryCount = reference.getDeliveryCount();
    // First check DLA
    if (maxDeliveries > 0 && deliveryCount >= maxDeliveries) {
        if (logger.isTraceEnabled()) {
            logger.trace("Sending reference " + reference + " to DLA = " + addressSettings.getDeadLetterAddress() + " since ref.getDeliveryCount=" + reference.getDeliveryCount() + "and maxDeliveries=" + maxDeliveries + " from queue=" + this.getName());
        }
        sendToDeadLetterAddress(null, reference, addressSettings.getDeadLetterAddress());
        return false;
    } else {
        // Second check Redelivery Delay
        if (!ignoreRedeliveryDelay && redeliveryDelay > 0) {
            redeliveryDelay = calculateRedeliveryDelay(addressSettings, deliveryCount);
            if (logger.isTraceEnabled()) {
                logger.trace("Setting redeliveryDelay=" + redeliveryDelay + " on reference=" + reference);
            }
            reference.setScheduledDeliveryTime(timeBase + redeliveryDelay);
            if (!reference.isPaged() && message.isDurable() && isDurableMessage()) {
                storageManager.updateScheduledDeliveryTime(reference);
            }
        }
        decDelivering(reference);
        return true;
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Message(org.apache.activemq.artemis.api.core.Message)

Aggregations

Message (org.apache.activemq.artemis.api.core.Message)114 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)56 Test (org.junit.Test)52 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)48 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)46 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)41 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)34 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)28 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)18 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)16 ArrayList (java.util.ArrayList)15 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)10 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)10 HashMap (java.util.HashMap)9 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)8