Search in sources :

Example 1 with Queue

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

the class PostOfficeImpl method schedulePageDelivery.

/**
 * This will kick a delivery async on the queue, so the queue may have a chance to depage messages
 *
 * @param tx
 * @param entry
 */
private void schedulePageDelivery(Transaction tx, Map.Entry<SimpleString, RouteContextList> entry) {
    if (tx != null) {
        PageDelivery delivery = (PageDelivery) tx.getProperty(TransactionPropertyIndexes.PAGE_DELIVERY);
        if (delivery == null) {
            delivery = new PageDelivery();
            tx.putProperty(TransactionPropertyIndexes.PAGE_DELIVERY, delivery);
            tx.addOperation(delivery);
        }
        delivery.addQueues(entry.getValue().getDurableQueues());
        delivery.addQueues(entry.getValue().getNonDurableQueues());
    } else {
        List<Queue> durableQueues = entry.getValue().getDurableQueues();
        List<Queue> nonDurableQueues = entry.getValue().getNonDurableQueues();
        final List<Queue> queues = new ArrayList<>(durableQueues.size() + nonDurableQueues.size());
        queues.addAll(durableQueues);
        queues.addAll(nonDurableQueues);
        storageManager.afterCompleteOperations(new IOCallback() {

            @Override
            public void onError(int errorCode, String errorMessage) {
            }

            @Override
            public void done() {
                for (Queue queue : queues) {
                    // in case of paging, we need to kick asynchronous delivery to try delivering
                    queue.deliverAsync();
                }
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) IOCallback(org.apache.activemq.artemis.core.io.IOCallback)

Example 2 with Queue

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

the class PostOfficeImpl method removeBinding.

@Override
public synchronized Binding removeBinding(final SimpleString uniqueName, Transaction tx, boolean deleteData) throws Exception {
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeRemoveBinding(uniqueName, tx, deleteData));
    }
    addressSettingsRepository.clearCache();
    Binding binding = addressManager.removeBinding(uniqueName, tx);
    if (binding == null) {
        throw new ActiveMQNonExistentQueueException();
    }
    if (deleteData && addressManager.getBindingsForRoutingAddress(binding.getAddress()) == null) {
        pagingManager.deletePageStore(binding.getAddress());
        deleteDuplicateCache(binding.getAddress());
    }
    if (binding.getType() == BindingType.LOCAL_QUEUE) {
        Queue queue = (Queue) binding.getBindable();
        managementService.unregisterQueue(uniqueName, binding.getAddress(), queue.getRoutingType());
    } else if (binding.getType() == BindingType.DIVERT) {
        managementService.unregisterDivert(uniqueName, binding.getAddress());
    }
    if (binding.getType() != BindingType.DIVERT) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        props.putLongProperty(ManagementHelper.HDR_BINDING_ID, binding.getID());
        if (binding.getFilter() == null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, null);
        } else {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, binding.getFilter().getFilterString());
        }
        managementService.sendNotification(new Notification(null, CoreNotificationType.BINDING_REMOVED, props));
    }
    binding.close();
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterRemoveBinding(binding, tx, deleteData));
    }
    return binding;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 3 with Queue

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

the class PostOfficeImpl method updateQueue.

@Override
public QueueBinding updateQueue(SimpleString name, RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception {
    synchronized (addressLock) {
        final QueueBinding queueBinding = (QueueBinding) addressManager.getBinding(name);
        if (queueBinding == null) {
            return null;
        }
        final Queue queue = queueBinding.getQueue();
        boolean changed = false;
        // validate update
        if (maxConsumers != null && maxConsumers.intValue() != Queue.MAX_CONSUMERS_UNLIMITED) {
            final int consumerCount = queue.getConsumerCount();
            if (consumerCount > maxConsumers) {
                throw ActiveMQMessageBundle.BUNDLE.invalidMaxConsumersUpdate(name.toString(), maxConsumers, consumerCount);
            }
        }
        if (routingType != null) {
            final SimpleString address = queue.getAddress();
            final AddressInfo addressInfo = addressManager.getAddressInfo(address);
            final EnumSet<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
            if (!addressRoutingTypes.contains(routingType)) {
                throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes);
            }
        }
        // atomic update
        if (maxConsumers != null && queue.getMaxConsumers() != maxConsumers.intValue()) {
            changed = true;
            queue.setMaxConsumer(maxConsumers);
        }
        if (routingType != null && queue.getRoutingType() != routingType) {
            changed = true;
            queue.setRoutingType(routingType);
        }
        if (purgeOnNoConsumers != null && queue.isPurgeOnNoConsumers() != purgeOnNoConsumers.booleanValue()) {
            changed = true;
            queue.setPurgeOnNoConsumers(purgeOnNoConsumers);
        }
        if (exclusive != null && queue.isExclusive() != exclusive.booleanValue()) {
            changed = true;
            queue.setExclusive(exclusive);
        }
        if (changed) {
            final long txID = storageManager.generateID();
            try {
                storageManager.updateQueueBinding(txID, queueBinding);
                storageManager.commitBindings(txID);
            } catch (Throwable throwable) {
                storageManager.rollback(txID);
                logger.warn(throwable.getMessage(), throwable);
                throw throwable;
            }
        }
        return queueBinding;
    }
}
Also used : QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 4 with Queue

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

the class QueueView method toJson.

@Override
public JsonObjectBuilder toJson(QueueControl queue) {
    Queue q = server.locateQueue(new SimpleString(queue.getName()));
    JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(queue.getID())).add("name", toString(queue.getName())).add("address", toString(queue.getAddress())).add("filter", toString(queue.getFilter())).add("rate", toString(q.getRate())).add("durable", toString(queue.isDurable())).add("paused", toString(q.isPaused())).add("temporary", toString(queue.isTemporary())).add("purgeOnNoConsumers", toString(queue.isPurgeOnNoConsumers())).add("consumerCount", toString(queue.getConsumerCount())).add("maxConsumers", toString(queue.getMaxConsumers())).add("autoCreated", toString(q.isAutoCreated())).add("user", toString(q.getUser())).add("routingType", toString(queue.getRoutingType())).add("messagesAdded", toString(queue.getMessagesAdded())).add("messageCount", toString(queue.getMessageCount())).add("messagesAcked", toString(queue.getMessagesAcknowledged())).add("deliveringCount", toString(queue.getDeliveringCount())).add("messagesKilled", toString(queue.getMessagesKilled())).add("deliverDeliver", toString(q.isDirectDeliver())).add("exclusive", toString(queue.isExclusive())).add("lastValue", toString(queue.isLastValue()));
    return obj;
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObjectBuilder(javax.json.JsonObjectBuilder) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 5 with Queue

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

the class ClusterConnectionImpl method nodeUP.

@Override
public void nodeUP(final TopologyMember topologyMember, final boolean last) {
    if (stopping) {
        return;
    }
    final String nodeID = topologyMember.getNodeId();
    if (logger.isDebugEnabled()) {
        String ClusterTestBase = "receiving nodeUP for nodeID=";
        logger.debug(this + ClusterTestBase + nodeID + " connectionPair=" + topologyMember);
    }
    if (nodeID.equals(nodeManager.getNodeId().toString())) {
        if (logger.isTraceEnabled()) {
            logger.trace(this + "::informing about backup to itself, nodeUUID=" + nodeManager.getNodeId() + ", connectorPair=" + topologyMember + ", this = " + this);
        }
        return;
    }
    // if the node is more than 1 hop away, we do not create a bridge for direct cluster connection
    if (allowDirectConnectionsOnly && !allowableConnections.contains(topologyMember.getLive().newTransportConfig(TRANSPORT_CONFIG_NAME))) {
        return;
    }
    // and empty static connectors to create bridges... ulgy!
    if (serverLocator == null) {
        return;
    }
    /*we don't create bridges to backups*/
    if (topologyMember.getLive() == null) {
        if (logger.isTraceEnabled()) {
            logger.trace(this + " ignoring call with nodeID=" + nodeID + ", topologyMember=" + topologyMember + ", last=" + last);
        }
        return;
    }
    synchronized (recordsGuard) {
        try {
            MessageFlowRecord record = records.get(nodeID);
            if (record == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug(this + "::Creating record for nodeID=" + nodeID + ", topologyMember=" + topologyMember);
                }
                // New node - create a new flow record
                final SimpleString queueName = new SimpleString(storeAndForwardPrefix + name + "." + nodeID);
                Binding queueBinding = postOffice.getBinding(queueName);
                Queue queue;
                if (queueBinding != null) {
                    queue = (Queue) queueBinding.getBindable();
                } else {
                    // Add binding in storage so the queue will get reloaded on startup and we can find it - it's never
                    // actually routed to at that address though
                    queue = server.createQueue(queueName, RoutingType.MULTICAST, queueName, null, true, false, -1, false, true);
                }
                // There are a few things that will behave differently when it's an internal queue
                // such as we don't hold groupIDs inside the SnF queue
                queue.setInternalQueue(true);
                createNewRecord(topologyMember.getUniqueEventID(), nodeID, topologyMember.getLive(), queueName, queue, true);
            } else {
                if (logger.isTraceEnabled()) {
                    logger.trace(this + " ignored nodeUp record for " + topologyMember + " on nodeID=" + nodeID + " as the record already existed");
                }
            }
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorUpdatingTopology(e);
        }
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Aggregations

Queue (org.apache.activemq.artemis.core.server.Queue)275 Test (org.junit.Test)193 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)128 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)89 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)85 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)75 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)70 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)70 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)70 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)64 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)59 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)56 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)49 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)47 Session (javax.jms.Session)36 Connection (javax.jms.Connection)32 Configuration (org.apache.activemq.artemis.core.config.Configuration)31 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)30 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)27 TextMessage (javax.jms.TextMessage)25