Search in sources :

Example 6 with QueueQuery

use of org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery in project activemq-artemis by apache.

the class SessionTest method testQueueQueryWithFilter.

@Test
public void testQueueQueryWithFilter() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, true, true);
    clientSession.createQueue("a1", queueName, "foo=bar", false);
    clientSession.createConsumer(queueName);
    clientSession.createConsumer(queueName);
    QueueQuery resp = clientSession.queueQuery(new SimpleString(queueName));
    Assert.assertEquals(new SimpleString("a1"), resp.getAddress());
    Assert.assertEquals(2, resp.getConsumerCount());
    Assert.assertEquals(0, resp.getMessageCount());
    Assert.assertEquals(new SimpleString("foo=bar"), resp.getFilterString());
    clientSession.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery) Test(org.junit.Test)

Example 7 with QueueQuery

use of org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery in project activemq-artemis by apache.

the class ActiveMQSession method lookupQueue.

private ActiveMQQueue lookupQueue(final String queueName, boolean isTemporary) throws ActiveMQException {
    ActiveMQQueue queue;
    if (isTemporary) {
        queue = ActiveMQDestination.createTemporaryQueue(queueName);
    } else {
        queue = ActiveMQDestination.createQueue(queueName);
    }
    QueueQuery response = session.queueQuery(queue.getSimpleAddress());
    if (!response.isExists() && !response.isAutoCreateQueues()) {
        return null;
    } else {
        return queue;
    }
}
Also used : QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Example 8 with QueueQuery

use of org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery in project activemq-artemis by apache.

the class ActiveMQSession method unsubscribe.

@Override
public void unsubscribe(final String name) throws JMSException {
    // As per spec. section 4.11
    if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
        throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
    }
    SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);
    try {
        QueueQuery response = session.queueQuery(queueName);
        if (!response.isExists()) {
            throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name + " does not exist");
        }
        if (response.getConsumerCount() != 0) {
            throw new IllegalStateException("Cannot unsubscribe durable subscription " + name + " since it has active subscribers");
        }
        session.deleteQueue(queueName);
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Example 9 with QueueQuery

use of org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery in project activemq-artemis by apache.

the class ActiveMQSession method deleteTemporaryQueue.

public void deleteTemporaryQueue(final ActiveMQDestination tempQueue) throws JMSException {
    if (!tempQueue.isTemporary()) {
        throw new InvalidDestinationException("Not a temporary queue " + tempQueue);
    }
    try {
        QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress());
        if (!response.isExists()) {
            throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() + " does not exist");
        }
        if (response.getConsumerCount() > 0) {
            throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() + " since it has subscribers");
        }
        SimpleString address = tempQueue.getSimpleAddress();
        session.deleteQueue(address);
        connection.removeTemporaryQueue(address);
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Example 10 with QueueQuery

use of org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery in project activemq-artemis by apache.

the class ActiveMQMessageHandler method teardown.

/**
 * Stop the handler
 */
public void teardown() {
    if (logger.isTraceEnabled()) {
        logger.trace("teardown()");
    }
    try {
        if (endpoint != null) {
            endpoint.release();
            endpoint = null;
        }
    } catch (Throwable t) {
        logger.debug("Error releasing endpoint " + endpoint, t);
    }
    // only do this if we haven't been disconnected at some point whilst failing over
    if (connected) {
        try {
            consumer.close();
            if (activation.getTopicTemporaryQueue() != null) {
                // We need to delete temporary topics when the activation is stopped or messages will build up on the server
                SimpleString tmpQueue = activation.getTopicTemporaryQueue();
                QueueQuery subResponse = session.queueQuery(tmpQueue);
                if (subResponse.getConsumerCount() == 0) {
                    // This is optional really, since we now use temporaryQueues, we could simply ignore this
                    // and the server temporary queue would remove this as soon as the queue was removed
                    session.deleteQueue(tmpQueue);
                }
            }
        } catch (Throwable t) {
            logger.debug("Error closing core-queue consumer", t);
        }
        try {
            if (session != null) {
                session.close();
            }
        } catch (Throwable t) {
            logger.debug("Error releasing session " + session, t);
        }
        try {
            if (cf != null) {
                cf.close();
            }
        } catch (Throwable t) {
            logger.debug("Error releasing session factory " + session, t);
        }
    } else {
        // otherwise we just clean up
        try {
            if (cf != null) {
                cf.cleanup();
            }
        } catch (Throwable t) {
            logger.debug("Error releasing session factory " + session, t);
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Aggregations

QueueQuery (org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)4 Test (org.junit.Test)4 IllegalStateException (javax.jms.IllegalStateException)3 InvalidDestinationException (javax.jms.InvalidDestinationException)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MessageEndpointFactory (javax.resource.spi.endpoint.MessageEndpointFactory)1 XAResource (javax.transaction.xa.XAResource)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 AddressQuery (org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)1 ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)1 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)1