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