Search in sources :

Example 26 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueImplTest method testConsumerWithFilterAddAndRemove.

@Test
public void testConsumerWithFilterAddAndRemove() {
    QueueImpl queue = getTemporaryQueue();
    Filter filter = new FakeFilter("fruit", "orange");
    FakeConsumer consumer = new FakeConsumer(filter);
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Filter(org.apache.activemq.artemis.core.filter.Filter) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) FakeFilter(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeFilter) Test(org.junit.Test)

Example 27 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class PageCursorStressTest method testSimpleCursorWithFilter.

@Test
public void testSimpleCursorWithFilter() throws Exception {
    final int NUM_MESSAGES = 100;
    PageSubscription cursorEven = createNonPersistentCursor(new Filter() {

        @Override
        public boolean match(Message message) {
            Boolean property = message.getBooleanProperty("even");
            if (property == null) {
                return false;
            } else {
                return property.booleanValue();
            }
        }

        @Override
        public SimpleString getFilterString() {
            return new SimpleString("even=true");
        }
    });
    PageSubscription cursorOdd = createNonPersistentCursor(new Filter() {

        @Override
        public boolean match(Message message) {
            Boolean property = message.getBooleanProperty("even");
            if (property == null) {
                return false;
            } else {
                return !property.booleanValue();
            }
        }

        @Override
        public SimpleString getFilterString() {
            return new SimpleString("even=true");
        }
    });
    int numberOfPages = addMessages(NUM_MESSAGES, 1024 * 1024);
    System.out.println("NumberOfPages = " + numberOfPages);
    queue.getPageSubscription().destroy();
    PagedReference msg;
    LinkedListIterator<PagedReference> iteratorEven = cursorEven.iterator();
    LinkedListIterator<PagedReference> iteratorOdd = cursorOdd.iterator();
    int key = 0;
    while ((msg = iteratorEven.next()) != null) {
        System.out.println("Received" + msg);
        assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
        assertTrue(msg.getMessage().getBooleanProperty("even").booleanValue());
        key += 2;
        cursorEven.confirmPosition(msg.getPosition());
    }
    assertEquals(NUM_MESSAGES, key);
    key = 1;
    while ((msg = iteratorOdd.next()) != null) {
        assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
        assertFalse(msg.getMessage().getBooleanProperty("even").booleanValue());
        key += 2;
        cursorOdd.confirmPosition(msg.getPosition());
    }
    assertEquals(NUM_MESSAGES + 1, key);
    forceGC();
    // assertTrue(lookupCursorProvider().getCacheSize() < numberOfPages);
    server.stop();
    createServer();
    waitCleanup();
    assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());
}
Also used : PagedReference(org.apache.activemq.artemis.core.paging.cursor.PagedReference) 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) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) Test(org.junit.Test)

Example 28 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class QueueImpl method hasMatchingConsumer.

@Override
public boolean hasMatchingConsumer(final Message message) {
    for (ConsumerHolder holder : consumerList) {
        Consumer consumer = holder.consumer;
        if (consumer instanceof Redistributor) {
            continue;
        }
        Filter filter1 = consumer.getFilter();
        if (filter1 == null) {
            return true;
        } else {
            if (filter1.match(message)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Consumer(org.apache.activemq.artemis.core.server.Consumer) Filter(org.apache.activemq.artemis.core.filter.Filter) Redistributor(org.apache.activemq.artemis.core.server.cluster.impl.Redistributor)

Example 29 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class ServerSessionImpl method createConsumer.

@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
    final SimpleString unPrefixedQueueName = removePrefix(queueName);
    Binding binding = postOffice.getBinding(unPrefixedQueueName);
    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
    }
    SimpleString address = removePrefix(binding.getAddress());
    if (browseOnly) {
        try {
            securityCheck(address, queueName, CheckType.BROWSE, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
        }
    } else {
        try {
            securityCheck(address, queueName, CheckType.CONSUME, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
        }
    }
    Filter filter = FilterImpl.createFilter(filterString);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
    }
    ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
    consumers.put(consumer.getID(), consumer);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
    }
    if (!browseOnly) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        Queue theQueue = (Queue) binding.getBindable();
        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
        // HORNETQ-946
        props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
        props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
        props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
        if (filterString != null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }
        Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
        if (logger.isDebugEnabled()) {
            logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
        }
        managementService.sendNotification(notification);
    }
    return consumer;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 30 with Filter

use of org.apache.activemq.artemis.core.filter.Filter in project activemq-artemis by apache.

the class ActiveMQServerImpl method queueQuery.

@Override
public QueueQueryResult queueQuery(SimpleString name) {
    if (name == null) {
        throw ActiveMQMessageBundle.BUNDLE.queueNameIsNull();
    }
    boolean autoCreateQueues = getAddressSettingsRepository().getMatch(name.toString()).isAutoCreateQueues();
    boolean defaultPurgeOnNoConsumers = getAddressSettingsRepository().getMatch(name.toString()).isDefaultPurgeOnNoConsumers();
    int defaultMaxConsumers = getAddressSettingsRepository().getMatch(name.toString()).getDefaultMaxConsumers();
    boolean defaultExclusiveQueue = getAddressSettingsRepository().getMatch(name.toString()).isDefaultExclusiveQueue();
    boolean defaultLastValueQueue = getAddressSettingsRepository().getMatch(name.toString()).isDefaultLastValueQueue();
    QueueQueryResult response;
    Binding binding = getPostOffice().getBinding(name);
    SimpleString managementAddress = getManagementService() != null ? getManagementService().getManagementAddress() : null;
    if (binding != null && binding.getType() == BindingType.LOCAL_QUEUE) {
        Queue queue = (Queue) binding.getBindable();
        Filter filter = queue.getFilter();
        SimpleString filterString = filter == null ? null : filter.getFilterString();
        response = new QueueQueryResult(name, binding.getAddress(), queue.isDurable(), queue.isTemporary(), filterString, queue.getConsumerCount(), queue.getMessageCount(), autoCreateQueues, true, queue.isAutoCreated(), queue.isPurgeOnNoConsumers(), queue.getRoutingType(), queue.getMaxConsumers(), queue.isExclusive(), queue.isLastValue());
    } else if (name.equals(managementAddress)) {
        // make an exception for the management address (see HORNETQ-29)
        response = new QueueQueryResult(name, managementAddress, true, false, null, -1, -1, autoCreateQueues, true, false, false, RoutingType.MULTICAST, -1, false, false);
    } else if (autoCreateQueues) {
        response = new QueueQueryResult(name, name, true, false, null, 0, 0, true, false, false, defaultPurgeOnNoConsumers, RoutingType.MULTICAST, defaultMaxConsumers, defaultExclusiveQueue, defaultLastValueQueue);
    } else {
        response = new QueueQueryResult(null, null, false, false, null, 0, 0, false, false, false, false, RoutingType.MULTICAST, 0, null, null);
    }
    return response;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SynchronousQueue(java.util.concurrent.SynchronousQueue) Queue(org.apache.activemq.artemis.core.server.Queue) ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint)

Aggregations

Filter (org.apache.activemq.artemis.core.filter.Filter)30 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)18 Binding (org.apache.activemq.artemis.core.postoffice.Binding)9 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 ArrayList (java.util.ArrayList)7 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)7 Test (org.junit.Test)7 Queue (org.apache.activemq.artemis.core.server.Queue)6 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)6 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)5 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)5 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Message (org.apache.activemq.artemis.api.core.Message)4 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)4 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)4 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 HierarchicalRepository (org.apache.activemq.artemis.core.settings.HierarchicalRepository)4