Search in sources :

Example 11 with Bindings

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

use of org.apache.activemq.artemis.core.postoffice.Bindings 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);
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) Binding(org.apache.activemq.artemis.core.postoffice.Binding) ProtocolManagerFactory(org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) RemotingServiceImpl(org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl) ActiveMQThreadPoolExecutor(org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor) JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) Map(java.util.Map) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) EnumSet(java.util.EnumSet) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) ConfigurationUtils(org.apache.activemq.artemis.core.config.ConfigurationUtils) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin) PrintWriter(java.io.PrintWriter) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) BackupManager(org.apache.activemq.artemis.core.server.cluster.BackupManager) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback) Set(java.util.Set) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) HAPolicy(org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy) ResourceManager(org.apache.activemq.artemis.core.transaction.ResourceManager) ReloadManager(org.apache.activemq.artemis.core.server.reload.ReloadManager) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) PostQueueCreationCallback(org.apache.activemq.artemis.core.server.PostQueueCreationCallback) LocalGroupingHandler(org.apache.activemq.artemis.core.server.group.impl.LocalGroupingHandler) DeletionPolicy(org.apache.activemq.artemis.core.settings.impl.DeletionPolicy) AccessController(java.security.AccessController) Bindable(org.apache.activemq.artemis.core.server.Bindable) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Configuration(org.apache.activemq.artemis.core.config.Configuration) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) Version(org.apache.activemq.artemis.core.version.Version) ReusableLatch(org.apache.activemq.artemis.utils.ReusableLatch) ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) Pair(org.apache.activemq.artemis.api.core.Pair) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CompositeAddress(org.apache.activemq.artemis.utils.CompositeAddress) AddressQueryResult(org.apache.activemq.artemis.core.server.AddressQueryResult) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ArrayList(java.util.ArrayList) VersionLoader(org.apache.activemq.artemis.utils.VersionLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CriticalAnalyzerImpl(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl) ManagementFactory(java.lang.management.ManagementFactory) BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) StringWriter(java.io.StringWriter) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl) IOException(java.io.IOException) File(java.io.File) PersistedRoles(org.apache.activemq.artemis.core.persistence.config.PersistedRoles) OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) ServiceRegistry(org.apache.activemq.artemis.core.server.ServiceRegistry) ActiveMQPluginRunnable(org.apache.activemq.artemis.core.server.plugin.ActiveMQPluginRunnable) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ReloadManagerImpl(org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl) OperationContextImpl(org.apache.activemq.artemis.core.persistence.impl.journal.OperationContextImpl) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) URL(java.net.URL) Date(java.util.Date) JournalType(org.apache.activemq.artemis.core.server.JournalType) RemoteGroupingHandler(org.apache.activemq.artemis.core.server.group.impl.RemoteGroupingHandler) CheckType(org.apache.activemq.artemis.core.security.CheckType) GroupingHandler(org.apache.activemq.artemis.core.server.group.GroupingHandler) ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) SecurityStore(org.apache.activemq.artemis.core.security.SecurityStore) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterImpl(org.apache.activemq.artemis.core.filter.impl.FilterImpl) PersistedAddressSetting(org.apache.activemq.artemis.core.persistence.config.PersistedAddressSetting) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadDumpUtil(org.apache.activemq.artemis.utils.ThreadDumpUtil) PagingStoreFactoryDatabase(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryDatabase) ResourceLimitSettings(org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings) Role(org.apache.activemq.artemis.core.security.Role) CriticalAnalyzerPolicy(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy) BindingType(org.apache.activemq.artemis.core.postoffice.BindingType) IOCriticalErrorListener(org.apache.activemq.artemis.core.io.IOCriticalErrorListener) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collection(java.util.Collection) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MemoryManager(org.apache.activemq.artemis.core.server.MemoryManager) Queue(org.apache.activemq.artemis.core.server.Queue) HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) SessionCallback(org.apache.activemq.artemis.spi.core.protocol.SessionCallback) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) CriticalComponent(org.apache.activemq.artemis.utils.critical.CriticalComponent) ReloadCallback(org.apache.activemq.artemis.core.server.reload.ReloadCallback) TimeUtils(org.apache.activemq.artemis.utils.TimeUtils) List(java.util.List) JdbcNodeManager(org.apache.activemq.artemis.core.server.impl.jdbc.JdbcNodeManager) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) PostQueueDeletionCallback(org.apache.activemq.artemis.core.server.PostQueueDeletionCallback) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) Divert(org.apache.activemq.artemis.core.server.Divert) GroupingHandlerConfiguration(org.apache.activemq.artemis.core.server.group.impl.GroupingHandlerConfiguration) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) Entry(java.util.Map.Entry) NetworkHealthCheck(org.apache.activemq.artemis.core.server.NetworkHealthCheck) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) ActivationFailureListener(org.apache.activemq.artemis.core.server.ActivationFailureListener) ActiveMQServerLogger(org.apache.activemq.artemis.core.server.ActiveMQServerLogger) FileStoreMonitor(org.apache.activemq.artemis.core.server.files.FileStoreMonitor) Filter(org.apache.activemq.artemis.core.filter.Filter) ActiveMQMessageBundle(org.apache.activemq.artemis.core.server.ActiveMQMessageBundle) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CriticalAnalyzer(org.apache.activemq.artemis.utils.critical.CriticalAnalyzer) Logger(org.jboss.logging.Logger) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) RemotingService(org.apache.activemq.artemis.core.remoting.server.RemotingService) HashMap(java.util.HashMap) PageCountPending(org.apache.activemq.artemis.core.persistence.impl.PageCountPending) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) SecurityStoreImpl(org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl) SecurityFormatter(org.apache.activemq.artemis.utils.SecurityFormatter) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) EmptyCriticalAnalyzer(org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer) CriticalAction(org.apache.activemq.artemis.utils.critical.CriticalAction) ActiveMQServerControlImpl(org.apache.activemq.artemis.core.management.impl.ActiveMQServerControlImpl) MBeanServer(javax.management.MBeanServer) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) LinkedList(java.util.LinkedList) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) FileConfigurationParser(org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser) ExecutorService(java.util.concurrent.ExecutorService) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) FileMoveManager(org.apache.activemq.artemis.core.server.files.FileMoveManager) Semaphore(java.util.concurrent.Semaphore) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException) TimeUnit(java.util.concurrent.TimeUnit) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) ServiceComponent(org.apache.activemq.artemis.core.server.ServiceComponent) JournalLoadInformation(org.apache.activemq.artemis.core.journal.JournalLoadInformation) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) 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) ActiveMQDeleteAddressException(org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SynchronousQueue(java.util.concurrent.SynchronousQueue) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 13 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class ConsumerWindowSizeTest method testNoWindowRoundRobin.

private void testNoWindowRoundRobin(final boolean largeMessages) throws Exception {
    ActiveMQServer server = createServer(false, isNetty());
    ClientSession sessionA = null;
    ClientSession sessionB = null;
    try {
        final int numberOfMessages = 100;
        server.start();
        locator.setConsumerWindowSize(-1);
        if (largeMessages) {
            locator.setMinLargeMessageSize(100);
        }
        ClientSessionFactory sf = createSessionFactory(locator);
        sessionA = sf.createSession(false, true, true);
        SimpleString ADDRESS = new SimpleString("some-queue");
        sessionA.createQueue(ADDRESS, ADDRESS, true);
        sessionB = sf.createSession(false, true, true);
        sessionA.start();
        sessionB.start();
        ClientConsumerInternal consA = (ClientConsumerInternal) sessionA.createConsumer(ADDRESS);
        ClientConsumerInternal consB = (ClientConsumerInternal) sessionB.createConsumer(ADDRESS);
        {
            // We can only guarantee round robing with WindowSize = -1, after the ServerConsumer object received
            // SessionConsumerFlowCreditMessage(-1)
            // Since that is done asynchronously we verify that the information was received before we proceed on
            // sending messages or else the distribution won't be
            // even as expected by the test
            Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
            Assert.assertEquals(1, bindings.getBindings().size());
            for (Binding binding : bindings.getBindings()) {
                Collection<Consumer> consumers = ((QueueBinding) binding).getQueue().getConsumers();
                for (Consumer consumer : consumers) {
                    ServerConsumerImpl consumerImpl = (ServerConsumerImpl) consumer;
                    long timeout = System.currentTimeMillis() + 5000;
                    while (timeout > System.currentTimeMillis() && consumerImpl.getAvailableCredits() != null) {
                        Thread.sleep(10);
                    }
                    Assert.assertNull(consumerImpl.getAvailableCredits());
                }
            }
        }
        ClientProducer prod = sessionA.createProducer(ADDRESS);
        for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = createTextMessage(sessionA, "Msg" + i);
            if (largeMessages) {
                msg.getBodyBuffer().writeBytes(new byte[600]);
            }
            prod.send(msg);
        }
        long timeout = System.currentTimeMillis() + TIMEOUT * 1000;
        boolean foundA = false;
        boolean foundB = false;
        do {
            foundA = consA.getBufferSize() == numberOfMessages / 2;
            foundB = consB.getBufferSize() == numberOfMessages / 2;
            Thread.sleep(10);
        } while ((!foundA || !foundB) && System.currentTimeMillis() < timeout);
        Assert.assertTrue("ConsumerA didn't receive the expected number of messages on buffer (consA=" + consA.getBufferSize() + ", consB=" + consB.getBufferSize() + ") foundA = " + foundA + " foundB = " + foundB, foundA);
        Assert.assertTrue("ConsumerB didn't receive the expected number of messages on buffer (consA=" + consA.getBufferSize() + ", consB=" + consB.getBufferSize() + ") foundA = " + foundA + " foundB = " + foundB, foundB);
    } finally {
        try {
            if (sessionA != null) {
                sessionA.close();
            }
            if (sessionB != null) {
                sessionB.close();
            }
        } catch (Exception ignored) {
        }
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ClientConsumerInternal(org.apache.activemq.artemis.core.client.impl.ClientConsumerInternal) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) IOException(java.io.IOException) ServerConsumerImpl(org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Consumer(org.apache.activemq.artemis.core.server.Consumer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Collection(java.util.Collection) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 14 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class JMSTopicConsumerTest method testTemporarySubscriptionDeleted.

@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
    Connection connection = createConnection();
    try {
        TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(getTopicName());
        TopicSubscriber myNonDurSub = session.createSubscriber(topic);
        assertNotNull(myNonDurSub);
        Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
        Assert.assertEquals(2, bindingsForAddress.getBindings().size());
        session.close();
        final CountDownLatch latch = new CountDownLatch(1);
        server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {

            @Override
            public void connectionClosed() {
                latch.countDown();
            }
        });
        connection.close();
        latch.await(5, TimeUnit.SECONDS);
        bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
        Assert.assertEquals(1, bindingsForAddress.getBindings().size());
    } finally {
        connection.close();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(javax.jms.Topic) CountDownLatch(java.util.concurrent.CountDownLatch) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Test(org.junit.Test)

Example 15 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class TopicCleanupTest method testWildcardSubscriber.

@Test
public void testWildcardSubscriber() throws Exception {
    ActiveMQTopic topic = (ActiveMQTopic) createTopic("topic.A");
    Connection conn = cf.createConnection();
    conn.start();
    try {
        Session consumerStarSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerStar = consumerStarSession.createConsumer(ActiveMQJMSClient.createTopic("topic.*"));
        Session consumerASession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerA = consumerASession.createConsumer(topic);
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producerA = producerSession.createProducer(topic);
        TextMessage msg1 = producerSession.createTextMessage("text");
        producerA.send(msg1);
        consumerStar.close();
        consumerA.close();
        producerA.send(msg1);
        conn.close();
        boolean foundStrayRoutingBinding = false;
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(topic.getAddress()));
        Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap();
        for (SimpleString key : routingNames.keySet()) {
            if (!key.toString().equals(topic.getAddress())) {
                foundStrayRoutingBinding = true;
                assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
            }
        }
        assertFalse(foundStrayRoutingBinding);
    } finally {
        jmsServer.stop();
        jmsServer.start();
        try {
            conn.close();
        } catch (Throwable igonred) {
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) List(java.util.List) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)35 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)24 Binding (org.apache.activemq.artemis.core.postoffice.Binding)22 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)15 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 Test (org.junit.Test)7 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Queue (org.apache.activemq.artemis.core.server.Queue)6 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)6 ArrayList (java.util.ArrayList)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 Connection (javax.jms.Connection)4 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)4 Address (org.apache.activemq.artemis.core.postoffice.Address)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 MessageConsumer (javax.jms.MessageConsumer)3