Search in sources :

Example 61 with Message

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

the class PostOfficeImpl method sendQueueInfoToQueue.

@Override
public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception {
    // We send direct to the queue so we can send it to the same queue that is bound to the notifications address -
    // this is crucial for ensuring
    // that queue infos and notifications are received in a contiguous consistent stream
    Binding binding = addressManager.getBinding(queueName);
    if (binding == null) {
        throw new IllegalStateException("Cannot find queue " + queueName);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("PostOffice.sendQueueInfoToQueue on server=" + this.server + ", queueName=" + queueName + " and address=" + address);
    }
    Queue queue = (Queue) binding.getBindable();
    // Need to lock to make sure all queue info and notifications are in the correct order with no gaps
    synchronized (notificationLock) {
        // First send a reset message
        Message message = new CoreMessage(storageManager.generateID(), 50);
        message.setAddress(queueName);
        message.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA, true);
        routeQueueInfo(message, queue, false);
        for (QueueInfo info : queueInfos.values()) {
            if (logger.isTraceEnabled()) {
                logger.trace("QueueInfo on sendQueueInfoToQueue = " + info);
            }
            if (info.matchesAddress(address)) {
                message = createQueueInfoMessage(CoreNotificationType.BINDING_ADDED, queueName);
                message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                message.putLongProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
                message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
                message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                routeQueueInfo(message, queue, true);
                int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
                for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++) {
                    message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                    message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                    message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                    message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                    message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                    routeQueueInfo(message, queue, true);
                }
                if (info.getFilterStrings() != null) {
                    for (SimpleString filterString : info.getFilterStrings()) {
                        message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                        message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                        message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                        message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                        message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
                        message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                        routeQueueInfo(message, queue, true);
                    }
                }
            }
        }
        Message completeMessage = new CoreMessage(storageManager.generateID(), 50);
        completeMessage.setAddress(queueName);
        completeMessage.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA_COMPLETE, true);
        routeQueueInfo(completeMessage, queue, false);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueInfo(org.apache.activemq.artemis.core.postoffice.QueueInfo) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 62 with Message

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

the class HornetQProtocolTest method testDuplicateIDPropertyWithHornetQAndCoreProtocol.

@Test
public void testDuplicateIDPropertyWithHornetQAndCoreProtocol() throws Exception {
    org.hornetq.api.core.client.ClientSession hqSession = createHQClientSession();
    String queueName = "test.hq.queue";
    hqSession.createQueue(queueName, queueName, true);
    org.hornetq.api.core.client.ClientProducer hqProducer = hqSession.createProducer(queueName);
    org.hornetq.api.core.client.ClientMessage message = hqSession.createMessage(false);
    String messageId = UUID.randomUUID().toString();
    message.putStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), messageId);
    ClientSession coreSession = createCoreClientSession();
    ClientConsumer coreConsumer = coreSession.createConsumer(queueName);
    hqSession.start();
    coreSession.start();
    hqProducer.send(message);
    Message m = coreConsumer.receive(1000);
    assertTrue(m.containsProperty(Message.HDR_DUPLICATE_DETECTION_ID));
    assertNotNull(m);
    hqProducer.send(message);
    m = coreConsumer.receive(1000);
    assertNull(m);
    hqProducer.send(message);
    m = coreConsumer.receive(1000);
    assertNull(m);
}
Also used : 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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 63 with Message

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

the class QueueControlImpl method convertMessagesToMaps.

/**
 * @param refs
 * @return
 */
private Map<String, Object>[] convertMessagesToMaps(List<MessageReference> refs) throws ActiveMQException {
    Map<String, Object>[] messages = new Map[refs.size()];
    int i = 0;
    for (MessageReference ref : refs) {
        Message message = ref.getMessage();
        messages[i++] = message.toMap();
    }
    return messages;
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with Message

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

the class QueueControlImpl method retryMessage.

@Override
public boolean retryMessage(final long messageID) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter singleMessageFilter = new Filter() {

            @Override
            public boolean match(Message message) {
                return message.getMessageID() == messageID;
            }

            @Override
            public SimpleString getFilterString() {
                return new SimpleString("custom filter for MESSAGEID= messageID");
            }
        };
        return queue.retryMessages(singleMessageFilter) > 0;
    } finally {
        blockOnIO();
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 65 with Message

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

the class QueueControlImpl method listMessages.

@Override
public Map<String, Object>[] listMessages(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        List<Map<String, Object>> messages = new ArrayList<>();
        queue.flushExecutor();
        try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
            try {
                while (iterator.hasNext()) {
                    MessageReference ref = iterator.next();
                    if (filter == null || filter.match(ref.getMessage())) {
                        Message message = ref.getMessage();
                        messages.add(message.toMap());
                    }
                }
            } catch (NoSuchElementException ignored) {
            // this could happen through paging browsing
            }
            return messages.toArray(new Map[messages.size()]);
        }
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    } finally {
        blockOnIO();
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Filter(org.apache.activemq.artemis.core.filter.Filter) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) HashMap(java.util.HashMap) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException)

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