use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class EmbeddedActiveMQResourceCustomConfigurationTest method testCustomConfiguration.
@Test
public void testCustomConfiguration() throws Exception {
Configuration configuration = server.getServer().getActiveMQServer().getConfiguration();
assertFalse("Persistence should have been disabled", configuration.isPersistenceEnabled());
assertTrue("Security should have been enabled", configuration.isSecurityEnabled());
assertNotNull(TEST_QUEUE + " should exist", server.locateQueue(TEST_QUEUE));
List<Queue> boundQueues = server.getBoundQueues(TEST_ADDRESS);
assertNotNull("List should never be null", boundQueues);
assertEquals("Should have one queue bound to address " + TEST_ADDRESS, 1, boundQueues.size());
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class EmbeddedJMSResource method getTopicQueues.
/**
* Get the Queues corresponding to a JMS Topic.
* <p>
* The full name of the JMS Topic including the prefix should be provided - i.e. topic://myTopic. If the destination type prefix
* is not included in the destination name, a prefix of "topic://" is assumed.
*
* @param topicName the full name of the JMS Destination
* @return the number of messages in the JMS Destination
*/
public List<Queue> getTopicQueues(String topicName) {
List<Queue> queues = new LinkedList<>();
ActiveMQDestination destination = ActiveMQDestination.createDestination(topicName, ActiveMQDestination.TYPE.TOPIC);
if (!destination.isQueue()) {
BindingQueryResult bindingQueryResult = null;
try {
bindingQueryResult = jmsServer.getActiveMQServer().bindingQuery(destination.getSimpleAddress());
} catch (Exception ex) {
log.error(String.format("getTopicQueues( %s ) - bindingQuery for %s failed", topicName, destination.getAddress()), ex);
return queues;
}
if (bindingQueryResult.isExists()) {
ActiveMQServer activeMQServer = jmsServer.getActiveMQServer();
for (SimpleString queueName : bindingQueryResult.getQueueNames()) {
queues.add(activeMQServer.locateQueue(queueName));
}
}
}
return queues;
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class EmbeddedActiveMQResource method getBoundQueues.
public List<Queue> getBoundQueues(SimpleString address) {
if (address == null) {
throw new IllegalArgumentException("getBoundQueues( address ) - address cannot be null");
}
List<Queue> boundQueues = new java.util.LinkedList<>();
BindingQueryResult bindingQueryResult = null;
try {
bindingQueryResult = server.getActiveMQServer().bindingQuery(address);
} catch (Exception e) {
throw new EmbeddedActiveMQResourceException(String.format("getBoundQueues( %s ) - bindingQuery( %s ) failed", address.toString(), address.toString()));
}
if (bindingQueryResult.isExists()) {
for (SimpleString queueName : bindingQueryResult.getQueueNames()) {
boundQueues.add(server.getActiveMQServer().locateQueue(queueName));
}
}
return boundQueues;
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class ActiveMQServerImpl method createQueue.
public Queue createQueue(final AddressInfo addrInfo, final SimpleString queueName, final SimpleString filterString, final SimpleString user, final boolean durable, final boolean temporary, final boolean ignoreIfExists, final boolean transientQueue, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, final boolean exclusive, final boolean lastValue, final boolean autoCreateAddress) throws Exception {
final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueName);
if (binding != null) {
if (ignoreIfExists) {
return binding.getQueue();
} else {
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName, binding.getAddress());
}
}
final Filter filter = FilterImpl.createFilter(filterString);
final long txID = storageManager.generateID();
final long queueID = storageManager.generateID();
final QueueConfig.Builder queueConfigBuilder;
final SimpleString addressToUse = addrInfo == null ? queueName : addrInfo.getName();
queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, addressToUse);
AddressInfo info = postOffice.getAddressInfo(addressToUse);
RoutingType routingType = addrInfo == null ? null : addrInfo.getRoutingType();
RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType);
if (autoCreateAddress) {
if (info == null) {
final AddressInfo addressInfo = new AddressInfo(addressToUse, rt);
addressInfo.setAutoCreated(true);
addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal());
addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(rt)) {
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.add(rt);
updateAddressInfo(info.getName(), routingTypes);
}
} else if (info == null) {
throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressToUse);
} else if (!info.getRoutingTypes().contains(rt)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(rt, info.getName().toString(), info.getRoutingTypes());
}
final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(addrInfo.getRoutingType()).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateQueue(queueConfig) : null);
final Queue queue = queueFactory.createQueueWith(queueConfig);
if (transientQueue) {
queue.setConsumersRefCount(new TransientQueueManagerImpl(this, queue.getName()));
} else {
queue.setConsumersRefCount(new QueueManagerImpl(this, queue.getName()));
}
final QueueBinding localQueueBinding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
if (queue.isDurable()) {
storageManager.addQueueBinding(txID, localQueueBinding);
}
try {
postOffice.addBinding(localQueueBinding);
if (queue.isDurable()) {
storageManager.commitBindings(txID);
}
} catch (Exception e) {
try {
if (durable) {
storageManager.rollbackBindings(txID);
}
final PageSubscription pageSubscription = queue.getPageSubscription();
try {
queue.close();
} finally {
if (pageSubscription != null) {
pageSubscription.destroy();
}
}
} catch (Throwable ignored) {
logger.debug(ignored.getMessage(), ignored);
}
throw e;
}
if (addrInfo == null || !addrInfo.isInternal()) {
managementService.registerQueue(queue, queue.getAddress(), storageManager);
}
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterCreateQueue(queue) : null);
callPostQueueCreationCallbacks(queue.getName());
return queue;
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class ActiveMQServerImpl method destroyQueue.
@Override
public void destroyQueue(final SimpleString queueName, final SecurityAuth session, final boolean checkConsumerCount, final boolean removeConsumers, final boolean autoDeleteAddress) throws Exception {
if (postOffice == null) {
return;
}
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeDestroyQueue(queueName, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
addressSettingsRepository.clearCache();
Binding binding = postOffice.getBinding(queueName);
if (binding == null) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(queueName);
}
SimpleString address = binding.getAddress();
Queue queue = (Queue) binding.getBindable();
// This check is only valid if checkConsumerCount == true
if (checkConsumerCount && queue.getConsumerCount() != 0) {
throw ActiveMQMessageBundle.BUNDLE.cannotDeleteQueue(queue.getName(), queueName, binding.getClass().getName());
}
if (session != null) {
if (queue.isDurable()) {
// make sure the user has privileges to delete this queue
securityStore.check(address, queueName, CheckType.DELETE_DURABLE_QUEUE, session);
} else {
securityStore.check(address, queueName, CheckType.DELETE_NON_DURABLE_QUEUE, session);
}
}
queue.deleteQueue(removeConsumers);
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterDestroyQueue(queue, address, session, checkConsumerCount, removeConsumers, autoDeleteAddress) : null);
AddressInfo addressInfo = getAddressInfo(address);
if (autoDeleteAddress && postOffice != null && addressInfo != null && addressInfo.isAutoCreated()) {
try {
removeAddressInfo(address, session);
} catch (ActiveMQDeleteAddressException e) {
// Could be thrown if the address has bindings or is not deletable.
}
}
callPostQueueDeletionCallbacks(address, queueName);
}
Aggregations