Search in sources :

Example 11 with ActiveMQQueueExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException 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 12 with ActiveMQQueueExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.

the class AMQConsumer method init.

public void init(SlowConsumerDetectionListener slowConsumerDetectionListener, long nativeId) throws Exception {
    SimpleString selector = info.getSelector() == null ? null : new SimpleString(info.getSelector());
    boolean preAck = false;
    if (info.isNoLocal()) {
        if (!AdvisorySupport.isAdvisoryTopic(openwireDestination)) {
            // tell the connection to add the property
            this.session.getConnection().setNoLocal(true);
        } else {
            preAck = true;
        }
        String id = info.getClientId() != null ? info.getClientId() : this.getId().getConnectionId();
        String noLocalSelector = MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + id + "'";
        if (selector == null) {
            selector = new SimpleString(noLocalSelector);
        } else {
            selector = new SimpleString(info.getSelector() + " AND " + noLocalSelector);
        }
    }
    SimpleString destinationName = new SimpleString(session.convertWildcard(openwireDestination.getPhysicalName()));
    if (openwireDestination.isTopic()) {
        SimpleString queueName = createTopicSubscription(info.isDurable(), info.getClientId(), destinationName.toString(), info.getSubscriptionName(), selector, destinationName);
        serverConsumer = session.getCoreSession().createConsumer(nativeId, queueName, null, info.isBrowser(), false, -1);
        serverConsumer.setlowConsumerDetection(slowConsumerDetectionListener);
        // only advisory topic consumers need this.
        ((ServerConsumerImpl) serverConsumer).setPreAcknowledge(preAck);
    } else {
        try {
            session.getCoreServer().createQueue(destinationName, RoutingType.ANYCAST, destinationName, null, true, false);
        } catch (ActiveMQQueueExistsException e) {
        // ignore
        }
        serverConsumer = session.getCoreSession().createConsumer(nativeId, destinationName, selector, info.isBrowser(), false, -1);
        serverConsumer.setlowConsumerDetection(slowConsumerDetectionListener);
        AddressSettings addrSettings = session.getCoreServer().getAddressSettingsRepository().getMatch(destinationName.toString());
        if (addrSettings != null) {
            // see PolicyEntry
            if (info.getPrefetchSize() != 0 && addrSettings.getQueuePrefetch() == 0) {
                // sends back a ConsumerControl
                ConsumerControl cc = new ConsumerControl();
                cc.setConsumerId(info.getConsumerId());
                cc.setPrefetch(0);
                session.getConnection().dispatch(cc);
            }
        }
    }
    serverConsumer.setProtocolData(this);
}
Also used : ServerConsumerImpl(org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ConsumerControl(org.apache.activemq.command.ConsumerControl) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 13 with ActiveMQQueueExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.

the class StompConnection method autoCreateDestinationIfPossible.

public void autoCreateDestinationIfPossible(String queue, RoutingType routingType) throws ActiveMQStompException {
    ServerSession session = getSession().getCoreSession();
    try {
        SimpleString simpleQueue = SimpleString.toSimpleString(queue);
        if (manager.getServer().getAddressInfo(simpleQueue) == null) {
            AddressSettings addressSettings = manager.getServer().getAddressSettingsRepository().getMatch(queue);
            RoutingType effectiveAddressRoutingType = routingType == null ? addressSettings.getDefaultAddressRoutingType() : routingType;
            if (addressSettings.isAutoCreateAddresses()) {
                session.createAddress(simpleQueue, effectiveAddressRoutingType, true);
            }
            // only auto create the queue if the address is ANYCAST
            if (effectiveAddressRoutingType == RoutingType.ANYCAST && addressSettings.isAutoCreateQueues()) {
                session.createQueue(simpleQueue, simpleQueue, routingType == null ? addressSettings.getDefaultQueueRoutingType() : routingType, null, false, true, true);
            }
        }
    } catch (ActiveMQQueueExistsException e) {
    // ignore
    } catch (Exception e) {
        throw new ActiveMQStompException(e.getMessage(), e).setHandler(frameHandler);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 14 with ActiveMQQueueExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.

the class ActiveMQSession method createProducer.

@Override
public MessageProducer createProducer(final Destination destination) throws JMSException {
    if (destination != null && !(destination instanceof ActiveMQDestination)) {
        throw new InvalidDestinationException("Not an ActiveMQ Artemis Destination:" + destination);
    }
    try {
        ActiveMQDestination jbd = (ActiveMQDestination) destination;
        if (jbd != null) {
            ClientSession.AddressQuery response = session.addressQuery(jbd.getSimpleAddress());
            if (!response.isExists()) {
                try {
                    if (jbd.isQueue() && response.isAutoCreateQueues()) {
                        // perhaps just relying on the broker to do it is simplest (i.e. purgeOnNoConsumers)
                        session.createAddress(jbd.getSimpleAddress(), RoutingType.ANYCAST, true);
                        createQueue(jbd, RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
                    } else if (!jbd.isQueue() && response.isAutoCreateAddresses()) {
                        session.createAddress(jbd.getSimpleAddress(), RoutingType.MULTICAST, true);
                    } else {
                        throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
                    }
                } catch (ActiveMQQueueExistsException e) {
                // Queue was created between our query and create queue request.  Ignore.
                }
            }
        }
        ClientProducer producer = session.createProducer(jbd == null ? null : jbd.getSimpleAddress());
        return new ActiveMQMessageProducer(connection, producer, jbd, session, options);
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) InvalidDestinationException(javax.jms.InvalidDestinationException) AddressQuery(org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 15 with ActiveMQQueueExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.

the class ActiveMQServerImpl method deployQueuesFromListCoreQueueConfiguration.

private void deployQueuesFromListCoreQueueConfiguration(List<CoreQueueConfiguration> queues) throws Exception {
    for (CoreQueueConfiguration config : queues) {
        SimpleString queueName = SimpleString.toSimpleString(config.getName());
        ActiveMQServerLogger.LOGGER.deployQueue(config.getName(), config.getAddress());
        AddressSettings as = addressSettingsRepository.getMatch(config.getAddress());
        // determine if there is an address::queue match; update it if so
        if (locateQueue(queueName) != null && locateQueue(queueName).getAddress().toString().equals(config.getAddress())) {
            updateQueue(config.getName(), config.getRoutingType(), config.getMaxConsumers(), config.getPurgeOnNoConsumers(), config.isExclusive() == null ? as.isDefaultExclusiveQueue() : config.isExclusive());
        } else {
            // if the address::queue doesn't exist then create it
            try {
                createQueue(SimpleString.toSimpleString(config.getAddress()), config.getRoutingType(), queueName, SimpleString.toSimpleString(config.getFilterString()), SimpleString.toSimpleString(config.getUser()), config.isDurable(), false, false, false, false, config.getMaxConsumers(), config.getPurgeOnNoConsumers(), config.isExclusive() == null ? as.isDefaultExclusiveQueue() : config.isExclusive(), config.isLastValue() == null ? as.isDefaultLastValueQueue() : config.isLastValue(), true);
            } catch (ActiveMQQueueExistsException e) {
                // the queue may exist on a *different* address
                ActiveMQServerLogger.LOGGER.warn(e.getMessage());
            }
        }
    }
}
Also used : 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) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration)

Aggregations

ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)16 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 InvalidDestinationException (javax.jms.InvalidDestinationException)4 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)3 AddressQuery (org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery)3 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)3 IllegalStateException (javax.jms.IllegalStateException)2 ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)2 AddressQueryResult (org.apache.activemq.artemis.core.server.AddressQueryResult)2 BindingQueryResult (org.apache.activemq.artemis.core.server.BindingQueryResult)2 CompositeAddress (org.apache.activemq.artemis.utils.CompositeAddress)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1