Search in sources :

Example 16 with RoutingType

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

the class QueueCommandTest method testUpdateCoreQueueCannotChangeRoutingType.

@Test
public void testUpdateCoreQueueCannotChangeRoutingType() throws Exception {
    final String queueName = "updateQueue";
    final SimpleString queueNameString = new SimpleString(queueName);
    final String addressName = "address";
    final SimpleString addressSimpleString = new SimpleString(addressName);
    final int oldMaxConsumers = 10;
    final RoutingType oldRoutingType = RoutingType.MULTICAST;
    final boolean oldPurgeOnNoConsumers = false;
    final Set<RoutingType> supportedRoutingTypes = EnumSet.of(oldRoutingType);
    final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.copyOf(supportedRoutingTypes));
    server.addAddressInfo(addressInfo);
    server.createQueue(addressSimpleString, oldRoutingType, queueNameString, null, true, false, oldMaxConsumers, oldPurgeOnNoConsumers, false);
    final RoutingType newRoutingType = RoutingType.ANYCAST;
    final UpdateQueue updateQueue = new UpdateQueue();
    updateQueue.setName(queueName);
    updateQueue.setAnycast(true);
    updateQueue.setMulticast(false);
    updateQueue.setMaxConsumers(-1);
    updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
    checkExecutionFailure(updateQueue, "AMQ119211");
    final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
    assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
    assertEquals("routingType", oldRoutingType, queueQueryResult.getRoutingType());
    assertTrue("purgeOnNoConsumers", oldPurgeOnNoConsumers == queueQueryResult.isPurgeOnNoConsumers());
}
Also used : PrintStream(java.io.PrintStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) ActionContext(org.apache.activemq.artemis.cli.commands.ActionContext) UpdateQueue(org.apache.activemq.artemis.cli.commands.queue.UpdateQueue) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 17 with RoutingType

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

the class CreateQueueTest method testUnsupportedRoutingType.

@Test
public void testUnsupportedRoutingType() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
    server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
    EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST);
    sendSession.createAddress(addressA, routingTypes, false);
    try {
        sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
        fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        ActiveMQException ae = (ActiveMQException) e;
        assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
    }
    routingTypes = EnumSet.of(RoutingType.MULTICAST);
    sendSession.createAddress(addressB, routingTypes, false);
    try {
        sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);
        fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        ActiveMQException ae = (ActiveMQException) e;
        assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
    }
    sendSession.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) Test(org.junit.Test)

Example 18 with RoutingType

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

the class HangConsumerTest method testHangDuplicateQueues.

/**
 * This would recreate the scenario where a queue was duplicated
 *
 * @throws Exception
 */
@Test
public void testHangDuplicateQueues() throws Exception {
    final Semaphore blocked = new Semaphore(1);
    final CountDownLatch latchDelete = new CountDownLatch(1);
    class MyQueueWithBlocking extends QueueImpl {

        /**
         * @param id
         * @param address
         * @param name
         * @param filter
         * @param pageSubscription
         * @param durable
         * @param temporary
         * @param scheduledExecutor
         * @param postOffice
         * @param storageManager
         * @param addressSettingsRepository
         * @param executor
         */
        MyQueueWithBlocking(final long id, final SimpleString address, final SimpleString name, final Filter filter, final SimpleString user, final PageSubscription pageSubscription, final boolean durable, final boolean temporary, final boolean autoCreated, final RoutingType deliveryMode, final Integer maxConsumers, final Boolean purgeOnNoConsumers, final ScheduledExecutorService scheduledExecutor, final PostOffice postOffice, final StorageManager storageManager, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final ArtemisExecutor executor, final ActiveMQServer server) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, deliveryMode, maxConsumers, purgeOnNoConsumers, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, null);
        }

        @Override
        public synchronized int deleteMatchingReferences(final int flushLimit, final Filter filter) throws Exception {
            latchDelete.countDown();
            blocked.acquire();
            blocked.release();
            return super.deleteMatchingReferences(flushLimit, filter);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    class LocalFactory extends QueueFactoryImpl {

        LocalFactory(final ExecutorFactory executorFactory, final ScheduledExecutorService scheduledExecutor, final HierarchicalRepository<AddressSettings> addressSettingsRepository, final StorageManager storageManager, final ActiveMQServer server) {
            super(executorFactory, scheduledExecutor, addressSettingsRepository, storageManager, server);
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            queue = new MyQueueWithBlocking(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), config.deliveryMode(), config.maxConsumers(), config.isPurgeOnNoConsumers(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }

        @Deprecated
        @Override
        public Queue createQueue(final long persistenceID, final SimpleString address, final SimpleString name, final Filter filter, final PageSubscription pageSubscription, final SimpleString user, final boolean durable, final boolean temporary, final boolean autoCreated) {
            queue = new MyQueueWithBlocking(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, RoutingType.MULTICAST, null, null, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executorFactory.getExecutor(), server);
            return queue;
        }
    }
    LocalFactory queueFactory = new LocalFactory(server.getExecutorFactory(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getStorageManager(), server);
    queueFactory.setPostOffice(server.getPostOffice());
    ((ActiveMQServerImpl) server).replaceQueueFactory(queueFactory);
    queue = server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    blocked.acquire();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ClientProducer producer = session.createProducer(QUEUE);
    producer.send(session.createMessage(true));
    session.commit();
    Thread tDelete = new Thread() {

        @Override
        public void run() {
            try {
                server.destroyQueue(QUEUE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    tDelete.start();
    Assert.assertTrue(latchDelete.await(10, TimeUnit.SECONDS));
    try {
        server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false);
    } catch (Exception expected) {
    }
    blocked.release();
    server.stop();
    tDelete.join();
    session.close();
    // a duplicate binding would impede the server from starting
    server.start();
    waitForServerToStart(server);
    server.stop();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) Semaphore(java.util.concurrent.Semaphore) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) QueueFactoryImpl(org.apache.activemq.artemis.core.server.impl.QueueFactoryImpl) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) Test(org.junit.Test)

Example 19 with RoutingType

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

the class FileConfigurationTest method verifyAddresses.

private void verifyAddresses() {
    assertEquals(3, conf.getAddressConfigurations().size());
    // Addr 1
    CoreAddressConfiguration addressConfiguration = conf.getAddressConfigurations().get(0);
    assertEquals("addr1", addressConfiguration.getName());
    Set<RoutingType> routingTypes = new HashSet<>();
    routingTypes.add(RoutingType.ANYCAST);
    assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
    assertEquals(2, addressConfiguration.getQueueConfigurations().size());
    // Addr 1 Queue 1
    CoreQueueConfiguration queueConfiguration = addressConfiguration.getQueueConfigurations().get(0);
    assertEquals("q1", queueConfiguration.getName());
    assertFalse(queueConfiguration.isDurable());
    assertEquals("color='blue'", queueConfiguration.getFilterString());
    assertEquals(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers(), queueConfiguration.getPurgeOnNoConsumers());
    assertEquals("addr1", queueConfiguration.getAddress());
    assertEquals(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(), queueConfiguration.getMaxConsumers());
    // Addr 1 Queue 2
    queueConfiguration = addressConfiguration.getQueueConfigurations().get(1);
    assertEquals("q2", queueConfiguration.getName());
    assertTrue(queueConfiguration.isDurable());
    assertEquals("color='green'", queueConfiguration.getFilterString());
    assertEquals(Queue.MAX_CONSUMERS_UNLIMITED, queueConfiguration.getMaxConsumers());
    assertFalse(queueConfiguration.getPurgeOnNoConsumers());
    assertEquals("addr1", queueConfiguration.getAddress());
    // Addr 2
    addressConfiguration = conf.getAddressConfigurations().get(1);
    assertEquals("addr2", addressConfiguration.getName());
    routingTypes = new HashSet<>();
    routingTypes.add(RoutingType.MULTICAST);
    assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
    assertEquals(2, addressConfiguration.getQueueConfigurations().size());
    // Addr 2 Queue 1
    queueConfiguration = addressConfiguration.getQueueConfigurations().get(0);
    assertEquals("q3", queueConfiguration.getName());
    assertTrue(queueConfiguration.isDurable());
    assertEquals("color='red'", queueConfiguration.getFilterString());
    assertEquals(10, queueConfiguration.getMaxConsumers());
    assertEquals(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers(), queueConfiguration.getPurgeOnNoConsumers());
    assertEquals("addr2", queueConfiguration.getAddress());
    // Addr 2 Queue 2
    queueConfiguration = addressConfiguration.getQueueConfigurations().get(1);
    assertEquals("q4", queueConfiguration.getName());
    assertTrue(queueConfiguration.isDurable());
    assertNull(queueConfiguration.getFilterString());
    assertEquals(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(), queueConfiguration.getMaxConsumers());
    assertTrue(queueConfiguration.getPurgeOnNoConsumers());
    assertEquals("addr2", queueConfiguration.getAddress());
    // Addr 3
    addressConfiguration = conf.getAddressConfigurations().get(2);
    assertEquals("addr2", addressConfiguration.getName());
    routingTypes = new HashSet<>();
    routingTypes.add(RoutingType.MULTICAST);
    routingTypes.add(RoutingType.ANYCAST);
    assertEquals(routingTypes, addressConfiguration.getRoutingTypes());
}
Also used : CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet)

Example 20 with RoutingType

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

the class MQTTTest method testAmbiguousRoutingWithMQTT.

@Test(timeout = 60 * 1000)
public void testAmbiguousRoutingWithMQTT() throws Exception {
    String anycastAddress = "foo/bar";
    EnumSet<RoutingType> routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet));
    String clientId = "testMqtt";
    Topic[] mqttSubscription = new Topic[] { new Topic(anycastAddress, QoS.AT_LEAST_ONCE) };
    MQTT mqtt = createMQTTConnection();
    mqtt.setClientId(clientId);
    BlockingConnection connection1 = mqtt.blockingConnection();
    connection1.connect();
    connection1.subscribe(mqttSubscription);
    MQTT mqtt2 = createMQTTConnection();
    mqtt2.setClientId(clientId + "2");
    BlockingConnection connection2 = mqtt2.blockingConnection();
    connection2.connect();
    connection2.subscribe(mqttSubscription);
    String message1 = "TestMessage1";
    String message2 = "TestMessage2";
    connection1.publish(anycastAddress, message1.getBytes(), QoS.AT_LEAST_ONCE, false);
    connection2.publish(anycastAddress, message2.getBytes(), QoS.AT_LEAST_ONCE, false);
    assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
    assertNotNull(connection1.receive(1000, TimeUnit.MILLISECONDS));
    assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
    assertNotNull(connection2.receive(1000, TimeUnit.MILLISECONDS));
}
Also used : MQTT(org.fusesource.mqtt.client.MQTT) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(org.fusesource.mqtt.client.Topic) BlockingConnection(org.fusesource.mqtt.client.BlockingConnection) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Aggregations

RoutingType (org.apache.activemq.artemis.api.core.RoutingType)45 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)11 HashSet (java.util.HashSet)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)7 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)6 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)6 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 Pair (org.apache.activemq.artemis.api.core.Pair)4 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)4 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)4 Filter (org.apache.activemq.artemis.core.filter.Filter)4 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)4