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();
}
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;
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations