Search in sources :

Example 16 with QueueQueryResult

use of org.apache.activemq.artemis.core.server.QueueQueryResult 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)

Example 17 with QueueQueryResult

use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.

the class FQQNOpenWireTest method testQueue.

@Test
public // core queues by its FQQN.
void testQueue() throws Exception {
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ2, null, true, false, -1, false, true);
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ3, null, true, false, -1, false, true);
    Connection connection = factory.createConnection();
    try {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue q1 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ1).toString());
        Queue q2 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ2).toString());
        Queue q3 = session.createQueue(CompositeAddress.toFullQN(anycastAddress, anycastQ3).toString());
        // send 3 messages to anycastAddress
        locator = createNonHALocator(true);
        ClientSessionFactory cf = createSessionFactory(locator);
        ClientSession coreSession = cf.createSession();
        // send 3 messages
        ClientProducer coreProducer = coreSession.createProducer(anycastAddress);
        sendMessages(coreSession, coreProducer, 3);
        System.out.println("Queue is: " + q1);
        MessageConsumer consumer1 = session.createConsumer(q1);
        MessageConsumer consumer2 = session.createConsumer(q2);
        MessageConsumer consumer3 = session.createConsumer(q3);
        // each consumer receives one
        assertNotNull(consumer1.receive(2000));
        assertNotNull(consumer2.receive(2000));
        assertNotNull(consumer3.receive(2000));
        connection.close();
        // queues are empty now
        for (SimpleString q : new SimpleString[] { anycastQ1, anycastQ2, anycastQ3 }) {
            // FQQN query
            QueueQueryResult query = server.queueQuery(CompositeAddress.toFullQN(anycastAddress, q));
            assertTrue(query.isExists());
            assertEquals(anycastAddress, query.getAddress());
            assertEquals(CompositeAddress.toFullQN(anycastAddress, q), query.getName());
            assertEquals(0, query.getMessageCount());
            // try query again using qName
            query = server.queueQuery(q);
            assertEquals(q, query.getName());
        }
    } finally {
        connection.close();
        if (locator != null) {
            locator.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Queue(javax.jms.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 18 with QueueQueryResult

use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.

the class FQQNOpenWireTest method testTopic.

@Test
public // however we can test query functionality
void testTopic() throws Exception {
    Connection connection = factory.createConnection();
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(multicastAddress.toString());
        MessageConsumer consumer1 = session.createConsumer(topic);
        MessageConsumer consumer2 = session.createConsumer(topic);
        MessageConsumer consumer3 = session.createConsumer(topic);
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createMessage());
        // each consumer receives one
        Message m = consumer1.receive(2000);
        assertNotNull(m);
        m = consumer2.receive(2000);
        assertNotNull(m);
        m = consumer3.receive(2000);
        assertNotNull(m);
        Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
        for (Binding b : bindings.getBindings()) {
            System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
            SimpleString qName = b.getUniqueName();
            // do FQQN query
            QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
            assertTrue(result.isExists());
            assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
            // do qname query
            result = server.queueQuery(qName);
            assertTrue(result.isExists());
            assertEquals(result.getName(), qName);
        }
    } finally {
        connection.close();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Topic(javax.jms.Topic) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 19 with QueueQueryResult

use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.

the class AMQPSessionCallback method bindingQuery.

public boolean bindingQuery(SimpleString address, RoutingType routingType) throws Exception {
    BindingQueryResult bindingQueryResult = bindingQueryCache.getResult(address);
    if (bindingQueryResult != null) {
        return bindingQueryResult.isExists();
    }
    bindingQueryResult = serverSession.executeBindingQuery(address);
    if (routingType == RoutingType.MULTICAST && !bindingQueryResult.isExists() && bindingQueryResult.isAutoCreateAddresses()) {
        try {
            serverSession.createAddress(address, routingType, true);
        } catch (ActiveMQAddressExistsException e) {
        // The address may have been created by another thread in the mean time.  Catch and do nothing.
        }
        bindingQueryResult = serverSession.executeBindingQuery(address);
    } else if (routingType == RoutingType.ANYCAST && bindingQueryResult.isAutoCreateQueues()) {
        QueueQueryResult queueBinding = serverSession.executeQueueQuery(address);
        if (!queueBinding.isExists()) {
            try {
                serverSession.createQueue(address, address, routingType, null, false, true, true);
            } catch (ActiveMQQueueExistsException e) {
            // The queue may have been created by another thread in the mean time.  Catch and do nothing.
            }
        }
        bindingQueryResult = serverSession.executeBindingQuery(address);
    }
    bindingQueryCache.setResult(address, bindingQueryResult);
    return bindingQueryResult.isExists();
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult)

Example 20 with QueueQueryResult

use of org.apache.activemq.artemis.core.server.QueueQueryResult in project activemq-artemis by apache.

the class ProtonServerSenderContext method close.

/*
    * close the session
    */
@Override
public void close(boolean remoteLinkClose) throws ActiveMQAMQPException {
    try {
        closed = true;
        sessionSPI.closeSender(brokerConsumer);
        // any durable resources for say pub subs
        if (remoteLinkClose) {
            Source source = (Source) sender.getSource();
            if (source != null && source.getAddress() != null && multicast) {
                SimpleString queueName = SimpleString.toSimpleString(source.getAddress());
                QueueQueryResult result = sessionSPI.queueQuery(queueName, routingTypeToUse, false);
                if (result.isExists() && source.getDynamic()) {
                    sessionSPI.deleteQueue(queueName);
                } else {
                    if (source.getDurable() == TerminusDurability.NONE && tempQueueName != null && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                        sessionSPI.removeTemporaryQueue(tempQueueName);
                    } else {
                        String clientId = getClientId();
                        String pubId = sender.getName();
                        if (pubId.contains("|")) {
                            pubId = pubId.split("\\|")[0];
                        }
                        SimpleString queue = createQueueName(connection.isUseCoreSubscriptionNaming(), clientId, pubId, shared, global, isVolatile);
                        result = sessionSPI.queueQuery(queue, multicast ? RoutingType.MULTICAST : RoutingType.ANYCAST, false);
                        // only delete if it isn't volatile and has no consumers
                        if (result.isExists() && !isVolatile && result.getConsumerCount() == 0) {
                            sessionSPI.deleteQueue(queue);
                        }
                    }
                }
            } else if (source != null && source.getDynamic() && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                try {
                    sessionSPI.removeTemporaryQueue(SimpleString.toSimpleString(source.getAddress()));
                } catch (Exception e) {
                // ignore on close, its temp anyway and will be removed later
                }
            }
        }
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
        throw new ActiveMQAMQPInternalErrorException(e.getMessage());
    }
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Aggregations

QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)18 Test (org.junit.Test)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Binding (org.apache.activemq.artemis.core.postoffice.Binding)5 Connection (javax.jms.Connection)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)4 PrintStream (java.io.PrintStream)3 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ActionContext (org.apache.activemq.artemis.cli.commands.ActionContext)3 UpdateQueue (org.apache.activemq.artemis.cli.commands.queue.UpdateQueue)3 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)3 Message (javax.jms.Message)2