Search in sources :

Example 6 with Message

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

the class BridgeImpl method beforeForward.

/* Hook for processing message before forwarding */
protected Message beforeForward(final Message message, final SimpleString forwardingAddress) {
    if (useDuplicateDetection) {
        // We keep our own DuplicateID for the Bridge, so bouncing back and forth will work fine
        byte[] bytes = getDuplicateBytes(nodeUUID, message.getMessageID());
        message.putExtraBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, bytes);
    }
    if (forwardingAddress != null) {
        // for AMQP messages this modification will be transient
        message.setAddress(forwardingAddress);
    }
    if (transformer != null) {
        final Message transformedMessage = transformer.transform(message);
        if (transformedMessage != message) {
            if (logger.isDebugEnabled()) {
                logger.debug("The transformer " + transformer + " made a copy of the message " + message + " as transformedMessage");
            }
        }
        return EmbedMessageUtil.embedAsCoreMessage(transformedMessage);
    } else {
        return EmbedMessageUtil.embedAsCoreMessage(message);
    }
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) Message(org.apache.activemq.artemis.api.core.Message)

Example 7 with Message

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

the class BridgeImpl method handle.

@Override
public HandleStatus handle(final MessageReference ref) throws Exception {
    if (filter != null && !filter.match(ref.getMessage())) {
        return HandleStatus.NO_MATCH;
    }
    synchronized (this) {
        if (!active || !session.isWritable(this)) {
            if (logger.isDebugEnabled()) {
                logger.debug(this + "::Ignoring reference on bridge as it is set to inactive ref=" + ref);
            }
            return HandleStatus.BUSY;
        }
        if (blockedOnFlowControl) {
            return HandleStatus.BUSY;
        }
        if (deliveringLargeMessage) {
            return HandleStatus.BUSY;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("Bridge " + this + " is handling reference=" + ref);
        }
        ref.handled();
        synchronized (refs) {
            refs.put(ref.getMessage().getMessageID(), ref);
        }
        final SimpleString dest;
        if (forwardingAddress != null) {
            dest = forwardingAddress;
        } else {
            // Preserve the original address
            dest = ref.getMessage().getAddressSimpleString();
        }
        final Message message = beforeForward(ref.getMessage(), dest);
        pendingAcks.countUp();
        try {
            if (message.isLargeMessage()) {
                deliveringLargeMessage = true;
                deliverLargeMessage(dest, ref, (LargeServerMessage) message);
                return HandleStatus.HANDLED;
            } else {
                return deliverStandardMessage(dest, ref, message);
            }
        } catch (Exception e) {
            // If an exception happened, we must count down immediately
            pendingAcks.countDown();
            throw e;
        }
    }
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 8 with Message

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

the class MQTTRetainMessageManager method addRetainedMessagesToQueue.

// SEND to Queue.
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception {
    // The address filter that matches all retained message queues.
    String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration());
    BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress));
    // Iterate over all matching retain queues and add the queue
    Transaction tx = session.getServerSession().newTransaction();
    try {
        synchronized (queue) {
            for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) {
                Queue retainedQueue = session.getServer().locateQueue(retainedQueueName);
                try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) {
                    if (i.hasNext()) {
                        Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID());
                        sendToQueue(message, queue, tx);
                    }
                }
            }
        }
    } catch (Throwable t) {
        tx.rollback();
        throw t;
    }
    tx.commit();
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 9 with Message

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

the class XmlDataImporter method processMessage.

private void processMessage() throws Exception {
    Byte type = 0;
    Byte priority = 0;
    Long expiration = 0L;
    Long timestamp = 0L;
    Long id = 0L;
    org.apache.activemq.artemis.utils.UUID userId = null;
    ArrayList<String> queues = new ArrayList<>();
    // get message's attributes
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attributeName = reader.getAttributeLocalName(i);
        switch(attributeName) {
            case XmlDataConstants.MESSAGE_TYPE:
                type = getMessageType(reader.getAttributeValue(i));
                break;
            case XmlDataConstants.MESSAGE_PRIORITY:
                priority = Byte.parseByte(reader.getAttributeValue(i));
                break;
            case XmlDataConstants.MESSAGE_EXPIRATION:
                expiration = Long.parseLong(reader.getAttributeValue(i));
                break;
            case XmlDataConstants.MESSAGE_TIMESTAMP:
                timestamp = Long.parseLong(reader.getAttributeValue(i));
                break;
            case XmlDataConstants.MESSAGE_USER_ID:
                userId = UUIDGenerator.getInstance().generateUUID();
                break;
            case XmlDataConstants.MESSAGE_ID:
                id = Long.parseLong(reader.getAttributeValue(i));
                break;
        }
    }
    Message message = session.createMessage(type, true, expiration, timestamp, priority);
    message.setUserID(userId);
    boolean endLoop = false;
    File largeMessageTemporaryFile = null;
    // loop through the XML and gather up all the message's data (i.e. body, properties, queues, etc.)
    while (reader.hasNext()) {
        int eventType = reader.getEventType();
        switch(eventType) {
            case XMLStreamConstants.START_ELEMENT:
                if (XmlDataConstants.MESSAGE_BODY.equals(reader.getLocalName())) {
                    largeMessageTemporaryFile = processMessageBody(message.toCore());
                } else if (XmlDataConstants.PROPERTIES_CHILD.equals(reader.getLocalName())) {
                    processMessageProperties(message);
                } else if (XmlDataConstants.QUEUES_CHILD.equals(reader.getLocalName())) {
                    processMessageQueues(queues);
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                if (XmlDataConstants.MESSAGES_CHILD.equals(reader.getLocalName())) {
                    endLoop = true;
                }
                break;
        }
        if (endLoop) {
            break;
        }
        reader.next();
    }
    if (sort) {
        messages.add(new MessageTemp(id, queues, message, largeMessageTemporaryFile));
    } else {
        sendMessage(queues, message, largeMessageTemporaryFile);
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) File(java.io.File)

Example 10 with Message

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

the class InterruptedLargeMessageTest method testInterruptLargeMessageSend.

@Test
public void testInterruptLargeMessageSend() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
    server.start();
    locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
    clientFile.setExpiration(System.currentTimeMillis());
    producer.send(clientFile);
    Thread.sleep(500);
    // 
    // for (ServerSession srvSession : server.getSessions()) {
    // ((ServerSessionImpl) srvSession).clearLargeMessage();
    // }
    server.fail(false);
    ActiveMQTestBase.forceGC();
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

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