Search in sources :

Example 6 with QueueQueryResult

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

the class FullQualifiedQueueTest method testMixedQueues.

@Test
public void testMixedQueues() throws Exception {
    server.createQueue(mixedAddress, RoutingType.MULTICAST, multicastQ1, null, true, false, -1, false, true);
    server.createQueue(mixedAddress, RoutingType.MULTICAST, multicastQ2, null, true, false, -1, false, true);
    server.createQueue(mixedAddress, RoutingType.MULTICAST, multicastQ3, null, true, false, -1, false, true);
    server.createQueue(mixedAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
    server.createQueue(mixedAddress, RoutingType.ANYCAST, anycastQ2, null, true, false, -1, false, true);
    server.createQueue(mixedAddress, RoutingType.ANYCAST, anycastQ3, null, true, false, -1, false, true);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession();
    session.start();
    // send 3 messages
    ClientProducer producer = session.createProducer(mixedAddress);
    final int num = 3;
    sendMessages(session, producer, num);
    ClientConsumer consumer1 = session.createConsumer(toFullQN(mixedAddress, anycastQ1));
    ClientConsumer consumer2 = session.createConsumer(toFullQN(mixedAddress, anycastQ2));
    ClientConsumer consumer3 = session.createConsumer(toFullQN(mixedAddress, anycastQ3));
    ClientConsumer consumer4 = session.createConsumer(toFullQN(mixedAddress, multicastQ1));
    ClientConsumer consumer5 = session.createConsumer(toFullQN(mixedAddress, multicastQ2));
    ClientConsumer consumer6 = session.createConsumer(toFullQN(mixedAddress, multicastQ3));
    session.start();
    // each anycast consumer receives one, each multicast receives three.
    ClientMessage m = consumer1.receive(2000);
    assertNotNull(m);
    System.out.println("consumer1 : " + m);
    m.acknowledge();
    m = consumer2.receive(2000);
    assertNotNull(m);
    System.out.println("consumer2 : " + m);
    m.acknowledge();
    m = consumer3.receive(2000);
    assertNotNull(m);
    System.out.println("consumer3 : " + m);
    m.acknowledge();
    for (int i = 0; i < num; i++) {
        m = consumer4.receive(2000);
        assertNotNull(m);
        System.out.println("consumer4 : " + m);
        m.acknowledge();
        m = consumer5.receive(2000);
        assertNotNull(m);
        System.out.println("consumer5 : " + m);
        m.acknowledge();
        m = consumer6.receive(2000);
        assertNotNull(m);
        System.out.println("consumer6 : " + m);
        m.acknowledge();
    }
    session.commit();
    // queues are empty now
    for (SimpleString q : new SimpleString[] { anycastQ1, anycastQ2, anycastQ3, multicastQ1, multicastQ2, multicastQ3 }) {
        QueueQueryResult query = server.queueQuery(toFullQN(mixedAddress, q));
        assertTrue(query.isExists());
        assertEquals(mixedAddress, query.getAddress());
        assertEquals(toFullQN(mixedAddress, q), query.getName());
        assertEquals(0, query.getMessageCount());
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 7 with QueueQueryResult

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

the class FullQualifiedQueueTest method testAnycastQueues.

@Test
public void testAnycastQueues() throws Exception {
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ2, null, true, false, -1, false, true);
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ3, null, true, false, -1, false, true);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession();
    session.start();
    // send 3 messages
    ClientProducer producer = session.createProducer(anycastAddress);
    sendMessages(session, producer, 3);
    ClientConsumer consumer1 = session.createConsumer(toFullQN(anycastAddress, anycastQ1));
    ClientConsumer consumer2 = session.createConsumer(toFullQN(anycastAddress, anycastQ2));
    ClientConsumer consumer3 = session.createConsumer(toFullQN(anycastAddress, anycastQ3));
    session.start();
    // each consumer receives one
    ClientMessage m = consumer1.receive(2000);
    assertNotNull(m);
    m.acknowledge();
    m = consumer2.receive(2000);
    assertNotNull(m);
    m.acknowledge();
    m = consumer3.receive(2000);
    assertNotNull(m);
    m.acknowledge();
    session.commit();
    // queues are empty now
    for (SimpleString q : new SimpleString[] { anycastQ1, anycastQ2, anycastQ3 }) {
        QueueQueryResult query = server.queueQuery(toFullQN(anycastAddress, q));
        assertTrue(query.isExists());
        assertEquals(anycastAddress, query.getAddress());
        assertEquals(toFullQN(anycastAddress, q), query.getName());
        assertEquals(0, query.getMessageCount());
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 8 with QueueQueryResult

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

the class MQTTFQQNTest method testMQTTSubNames.

@Test
public void testMQTTSubNames() throws Exception {
    final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
    initializeConnection(subscriptionProvider);
    try {
        subscriptionProvider.subscribe("foo/bah", AT_MOST_ONCE);
        Map<SimpleString, Binding> allBindings = server.getPostOffice().getAllBindings();
        assertEquals(1, allBindings.size());
        Binding b = allBindings.values().iterator().next();
        // check that query using bare queue name works as before
        QueueQueryResult result = server.queueQuery(b.getUniqueName());
        assertTrue(result.isExists());
        assertEquals(result.getAddress(), new SimpleString("foo.bah"));
        assertEquals(b.getUniqueName(), result.getName());
        // check that queue query using FQQN returns FQQN
        result = server.queueQuery(new SimpleString("foo.bah::" + b.getUniqueName()));
        assertTrue(result.isExists());
        assertEquals(new SimpleString("foo.bah"), result.getAddress());
        assertEquals(new SimpleString("foo.bah::" + b.getUniqueName()), result.getName());
    } finally {
        subscriptionProvider.disconnect();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Test(org.junit.Test)

Example 9 with QueueQueryResult

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

the class MQTTFQQNTest method testMQTTSubNamesSpecial.

@Test
public void testMQTTSubNamesSpecial() throws Exception {
    final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
    initializeConnection(subscriptionProvider);
    try {
        subscriptionProvider.subscribe("foo/bah", AT_MOST_ONCE);
        Map<SimpleString, Binding> allBindings = server.getPostOffice().getAllBindings();
        assertEquals(1, allBindings.size());
        Binding b = allBindings.values().iterator().next();
        // check ::queue
        QueueQueryResult result = server.queueQuery(new SimpleString("::" + b.getUniqueName()));
        assertTrue(result.isExists());
        assertEquals(new SimpleString("foo.bah"), result.getAddress());
        assertEquals(new SimpleString("::" + b.getUniqueName()), result.getName());
        // check queue::
        result = server.queueQuery(new SimpleString(b.getUniqueName() + "::"));
        assertFalse(result.isExists());
        // check ::
        result = server.queueQuery(new SimpleString("::"));
        assertFalse(result.isExists());
    } finally {
        subscriptionProvider.disconnect();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Test(org.junit.Test)

Example 10 with QueueQueryResult

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

the class FQQNStompTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    conn = StompClientConnectionFactory.createClientConnection(uri);
    QueueQueryResult result = server.getActiveMQServer().queueQuery(new SimpleString(getQueueName()));
    assertTrue(result.isExists());
    System.out.println("address: " + result.getAddress() + " queue " + result.getName());
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Before(org.junit.Before)

Aggregations

QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)18 Test (org.junit.Test)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Binding (org.apache.activemq.artemis.core.postoffice.Binding)5 Connection (javax.jms.Connection)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)4 PrintStream (java.io.PrintStream)3 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ActionContext (org.apache.activemq.artemis.cli.commands.ActionContext)3 UpdateQueue (org.apache.activemq.artemis.cli.commands.queue.UpdateQueue)3 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)3 Message (javax.jms.Message)2