Search in sources :

Example 6 with Queue

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

the class ClusterManager method deployBridge.

public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
    if (config.getName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNotUnique();
        return;
    }
    if (config.getQueueName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoQueue(config.getName());
        return;
    }
    if (config.getForwardingAddress() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
    }
    if (bridges.containsKey(config.getName())) {
        ActiveMQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());
        return;
    }
    Transformer transformer = server.getServiceRegistry().getBridgeTransformer(config.getName(), config.getTransformerConfiguration());
    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));
    if (binding == null) {
        ActiveMQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());
        return;
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeDeployBridge(config));
    }
    Queue queue = (Queue) binding.getBindable();
    ServerLocatorInternal serverLocator;
    if (config.getDiscoveryGroupName() != null) {
        DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
        if (discoveryGroupConfiguration == null) {
            ActiveMQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
        }
    } else {
        TransportConfiguration[] tcConfigs = configuration.getTransportConfigurations(config.getStaticConnectors());
        if (tcConfigs == null) {
            ActiveMQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(tcConfigs);
        }
    }
    serverLocator.setIdentity("Bridge " + config.getName());
    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(0);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setConnectionTTL(config.getConnectionTTL());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    serverLocator.setProducerWindowSize(config.getProducerWindowSize());
    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    serverLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(this, executor));
    if (!config.isUseDuplicateDetection()) {
        logger.debug("Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously");
    }
    clusterLocators.add(serverLocator);
    Bridge bridge = new BridgeImpl(serverLocator, config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), server);
    bridges.put(config.getName(), bridge);
    managementService.registerBridge(bridge, config);
    bridge.start();
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterDeployBridge(bridge));
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 7 with Queue

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

the class MQTTRetainMessageManager method addRetainedMessagesToQueue.

// SEND to Queue.
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception {
    // The address filter that matches all retained message queues.
    String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration());
    BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress));
    // Iterate over all matching retain queues and add the queue
    Transaction tx = session.getServerSession().newTransaction();
    try {
        synchronized (queue) {
            for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) {
                Queue retainedQueue = session.getServer().locateQueue(retainedQueueName);
                try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) {
                    if (i.hasNext()) {
                        Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID());
                        sendToQueue(message, queue, tx);
                    }
                }
            }
        }
    } catch (Throwable t) {
        tx.rollback();
        throw t;
    }
    tx.commit();
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 8 with Queue

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

the class MQTTSubscriptionManager method createQueueForSubscription.

/**
 * Creates a Queue if it doesn't already exist, based on a topic and address.  Returning the queue name.
 */
private Queue createQueueForSubscription(String address, int qos) throws Exception {
    // Check to see if a subscription queue already exists.
    SimpleString queue = getQueueNameForTopic(address);
    Queue q = session.getServer().locateQueue(queue);
    // The queue does not exist so we need to create it.
    if (q == null) {
        SimpleString sAddress = SimpleString.toSimpleString(address);
        // Check we can auto create queues.
        BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(sAddress);
        if (!bindingQueryResult.isAutoCreateQueues()) {
            throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(sAddress);
        }
        // Check that the address exists, if not we try to auto create it.
        AddressInfo addressInfo = session.getServerSession().getAddress(sAddress);
        if (addressInfo == null) {
            if (!bindingQueryResult.isAutoCreateAddresses()) {
                throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(SimpleString.toSimpleString(address));
            }
            addressInfo = session.getServerSession().createAddress(SimpleString.toSimpleString(address), RoutingType.MULTICAST, true);
        }
        return findOrCreateQueue(bindingQueryResult, addressInfo, queue, qos);
    }
    return q;
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) 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)

Example 9 with Queue

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

the class MQTTSubscriptionManager method start.

synchronized void start() throws Exception {
    for (MqttTopicSubscription subscription : session.getSessionState().getSubscriptions()) {
        String coreAddress = MQTTUtil.convertMQTTAddressFilterToCore(subscription.topicName(), session.getWildcardConfiguration());
        Queue q = createQueueForSubscription(coreAddress, subscription.qualityOfService().value());
        createConsumerForSubscriptionQueue(q, subscription.topicName(), subscription.qualityOfService().value());
    }
}
Also used : MqttTopicSubscription(io.netty.handler.codec.mqtt.MqttTopicSubscription) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 10 with Queue

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

the class OpenWireConnection method removeDestination.

public void removeDestination(ActiveMQDestination dest) throws Exception {
    if (dest.isQueue()) {
        try {
            server.destroyQueue(new SimpleString(dest.getPhysicalName()), getRemotingConnection());
        } catch (ActiveMQNonExistentQueueException neq) {
            // this is ok, ActiveMQ 5 allows this and will actually do it quite often
            ActiveMQServerLogger.LOGGER.debug("queue never existed");
        }
    } else {
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(dest.getPhysicalName()));
        for (Binding binding : bindings.getBindings()) {
            Queue b = (Queue) binding.getBindable();
            if (b.getConsumerCount() > 0) {
                throw new Exception("Destination still has an active subscription: " + dest.getPhysicalName());
            }
            if (b.isDurable()) {
                throw new Exception("Destination still has durable subscription: " + dest.getPhysicalName());
            }
            b.deleteQueue();
        }
    }
    if (!AdvisorySupport.isAdvisoryTopic(dest)) {
        AMQConnectionContext context = getContext();
        DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.REMOVE_OPERATION_TYPE, dest);
        ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
        protocolManager.fireAdvisory(context, topic, advInfo);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DestinationInfo(org.apache.activemq.command.DestinationInfo) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQTempQueue(org.apache.activemq.command.ActiveMQTempQueue) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) IllegalStateException(javax.jms.IllegalStateException) XAException(javax.transaction.xa.XAException) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) IOException(java.io.IOException) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) JMSSecurityException(javax.jms.JMSSecurityException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) InvalidClientIDException(javax.jms.InvalidClientIDException)

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