Search in sources :

Example 6 with BindingQueryResult

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

the class ActiveMQServerImpl method bindingQuery.

@Override
public BindingQueryResult bindingQuery(SimpleString address) throws Exception {
    if (address == null) {
        throw ActiveMQMessageBundle.BUNDLE.addressIsNull();
    }
    CompositeAddress addressKey = new CompositeAddress(address.toString());
    String realAddress = addressKey.isFqqn() ? addressKey.getAddress() : addressKey.getQueueName();
    AddressSettings addressSettings = getAddressSettingsRepository().getMatch(realAddress);
    boolean autoCreateQeueus = addressSettings.isAutoCreateQueues();
    boolean autoCreateAddresses = addressSettings.isAutoCreateAddresses();
    boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers();
    int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers();
    boolean defaultExclusive = addressSettings.isDefaultExclusiveQueue();
    boolean defaultLastValie = addressSettings.isDefaultLastValueQueue();
    List<SimpleString> names = new ArrayList<>();
    // make an exception for the management address (see HORNETQ-29)
    ManagementService managementService = getManagementService();
    SimpleString bindAddress = new SimpleString(realAddress);
    if (managementService != null) {
        if (bindAddress.equals(managementService.getManagementAddress())) {
            return new BindingQueryResult(true, null, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValie);
        }
    }
    Bindings bindings = getPostOffice().getMatchingBindings(bindAddress);
    for (Binding binding : bindings.getBindings()) {
        if (binding.getType() == BindingType.LOCAL_QUEUE || binding.getType() == BindingType.REMOTE_QUEUE) {
            if (addressKey.isFqqn()) {
                names.add(new SimpleString(addressKey.getAddress()).concat(CompositeAddress.SEPARATOR).concat(binding.getUniqueName()));
            } else {
                names.add(binding.getUniqueName());
            }
        }
    }
    AddressInfo info = getAddressInfo(bindAddress);
    return new BindingQueryResult(info != null, info, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValie);
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) 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) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) CompositeAddress(org.apache.activemq.artemis.utils.CompositeAddress) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService)

Example 7 with BindingQueryResult

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

the class OpenWireConnection method validateDestination.

/**
 * Checks to see if this destination exists.  If it does not throw an invalid destination exception.
 *
 * @param destination
 */
private void validateDestination(ActiveMQDestination destination) throws Exception {
    if (destination.isQueue()) {
        SimpleString physicalName = new SimpleString(destination.getPhysicalName());
        BindingQueryResult result = server.bindingQuery(physicalName);
        if (!result.isExists() && !result.isAutoCreateQueues()) {
            throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(physicalName);
        }
    }
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 8 with BindingQueryResult

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

the class AMQSession method checkAutoCreateQueue.

private boolean checkAutoCreateQueue(SimpleString queueName, boolean isTemporary) throws Exception {
    boolean hasQueue = true;
    if (!connection.containsKnownDestination(queueName)) {
        BindingQueryResult bindingQuery = server.bindingQuery(queueName);
        QueueQueryResult queueBinding = server.queueQuery(queueName);
        try {
            if (!queueBinding.isExists()) {
                if (bindingQuery.isAutoCreateQueues()) {
                    SimpleString queueNameToUse = queueName;
                    SimpleString addressToUse = queueName;
                    RoutingType routingTypeToUse = RoutingType.ANYCAST;
                    if (CompositeAddress.isFullyQualified(queueName.toString())) {
                        CompositeAddress compositeAddress = CompositeAddress.getQueueName(queueName.toString());
                        addressToUse = new SimpleString(compositeAddress.getAddress());
                        queueNameToUse = new SimpleString(compositeAddress.getQueueName());
                        if (bindingQuery.getAddressInfo() != null) {
                            routingTypeToUse = bindingQuery.getAddressInfo().getRoutingType();
                        } else {
                            AddressSettings as = server.getAddressSettingsRepository().getMatch(addressToUse.toString());
                            routingTypeToUse = as.getDefaultAddressRoutingType();
                        }
                    }
                    coreSession.createQueue(addressToUse, queueNameToUse, routingTypeToUse, null, isTemporary, true);
                    connection.addKnownDestination(queueName);
                } else {
                    hasQueue = false;
                }
            }
        } catch (ActiveMQQueueExistsException e) {
            // In case another thread created the queue before us but after we did the binding query
            hasQueue = true;
        }
    }
    return hasQueue;
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) CompositeAddress(org.apache.activemq.artemis.utils.CompositeAddress) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 9 with BindingQueryResult

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

the class EmbeddedJMSResource method getDestinationQueue.

/**
 * Get the Queue corresponding to a JMS Destination.
 * <p>
 * The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue
 * or topic://myTopic.  If the destination type prefix is not included in the destination name, a prefix
 * of "queue://" is assumed.
 *
 * @param destinationName the full name of the JMS Destination
 * @return the number of messages in the JMS Destination
 */
public Queue getDestinationQueue(String destinationName) {
    Queue queue = null;
    ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
    String address = destination.getAddress();
    String name = destination.getName();
    if (destination.isQueue()) {
        queue = jmsServer.getActiveMQServer().locateQueue(destination.getSimpleAddress());
    } else {
        BindingQueryResult bindingQueryResult = null;
        try {
            bindingQueryResult = jmsServer.getActiveMQServer().bindingQuery(destination.getSimpleAddress());
        } catch (Exception ex) {
            log.error(String.format("getDestinationQueue( %s ) - bindingQuery for %s failed", destinationName, destination.getAddress()), ex);
            return null;
        }
        if (bindingQueryResult.isExists()) {
            List<SimpleString> queueNames = bindingQueryResult.getQueueNames();
            if (queueNames.size() > 0) {
                queue = jmsServer.getActiveMQServer().locateQueue(queueNames.get(0));
            }
        }
    }
    return queue;
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) JMSException(javax.jms.JMSException) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination)

Example 10 with BindingQueryResult

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

Aggregations

BindingQueryResult (org.apache.activemq.artemis.core.server.BindingQueryResult)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 Queue (org.apache.activemq.artemis.core.server.Queue)5 JMSException (javax.jms.JMSException)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)2 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQQueueMaxConsumerLimitReached (org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)1 Message (org.apache.activemq.artemis.api.core.Message)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)1 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)1 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)1 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)1