Search in sources :

Example 61 with Queue

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

the class JmsConsumerTest method defaultAutoCreatedQueueConfigTest.

@Test
public void defaultAutoCreatedQueueConfigTest() throws Exception {
    final String queueName = "q1";
    server.getAddressSettingsRepository().addMatch(queueName, new AddressSettings().setDefaultMaxConsumers(5).setDefaultPurgeOnNoConsumers(true));
    Connection connection = cf.createConnection();
    Session session = connection.createSession();
    session.createConsumer(session.createQueue(queueName));
    org.apache.activemq.artemis.core.server.Queue queue = server.locateQueue(SimpleString.toSimpleString(queueName));
    assertEquals(5, queue.getMaxConsumers());
    assertEquals(true, queue.isPurgeOnNoConsumers());
    connection.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Connection(javax.jms.Connection) Queue(org.apache.activemq.artemis.core.server.Queue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Session(javax.jms.Session) Test(org.junit.Test)

Example 62 with Queue

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

the class LoggingActiveMQServerPlugin method messageAcknowledged.

/**
 * A message has been acknowledged
 *
 * @param ref    The acked message
 * @param reason The ack reason
 * @throws ActiveMQException
 */
@Override
public void messageAcknowledged(MessageReference ref, AckReason reason) throws ActiveMQException {
    if (logAll || logDeliveringEvents) {
        // details - debug logging
        LoggingActiveMQServerPluginLogger.LOGGER.messageAcknowledgedDetails(ref, reason);
        if (LoggingActiveMQServerPluginLogger.LOGGER.isInfoEnabled()) {
            Message message = (ref == null ? null : ref.getMessage());
            Queue queue = (ref == null ? null : ref.getQueue());
            // info level logging
            LoggingActiveMQServerPluginLogger.LOGGER.messageAcknowledged((message == null ? UNAVAILABLE : Long.toString(message.getMessageID())), (ref == null ? UNAVAILABLE : ref.hasConsumerId() ? Long.toString(ref.getConsumerId()) : null), (queue == null ? UNAVAILABLE : queue.getName().toString()), reason);
        }
    }
}
Also used : Message(org.apache.activemq.artemis.api.core.Message) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 63 with Queue

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

the class AnycastRoutingWithClusterTest method testAnycastAddressOneQueueRoutingMultiNode.

/**
 * Test anycast address with single distributed queue in a 3 node cluster environment.  Messages should be
 * "round robin"'d across the each queue
 * @throws Exception
 */
@Test
public void testAnycastAddressOneQueueRoutingMultiNode() throws Exception {
    String address = "test.address";
    String queueName = "test.queue";
    String clusterAddress = "test";
    for (int i = 0; i < 3; i++) {
        setupServer(i, isFileStorage(), isNetty());
    }
    setupClusterConnection("cluster0", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2);
    startServers(0, 1, 2);
    List<Queue> queues;
    for (int i = 0; i < 3; i++) {
        createAddressInfo(i, address, RoutingType.ANYCAST, -1, false);
        setupSessionFactory(i, isNetty());
        createQueue(i, address, queueName, null, false, RoutingType.ANYCAST);
        addConsumer(i, i, queueName, null);
    }
    for (int i = 0; i < 3; i++) {
        waitForBindings(i, address, 1, 1, true);
        waitForBindings(i, address, 2, 2, false);
    }
    final int noMessages = 30;
    send(0, address, noMessages, true, null, null);
    for (int s = 0; s < 3; s++) {
        final Queue queue = servers[s].locateQueue(new SimpleString(queueName));
        Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisfied() throws Exception {
                return queue.getMessageCount() == noMessages / 3;
            }
        });
    }
    // Each consumer should receive noMessages / noServers
    for (int i = 0; i < noMessages / 3; i++) {
        for (int c = 0; c < 3; c++) {
            assertNotNull(consumers[c].consumer.receive(1000));
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Wait(org.apache.activemq.artemis.tests.util.Wait) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 64 with Queue

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

the class AnycastRoutingWithClusterTest method testAnycastAddressMultiQueuesWithFilterRoutingMultiNode.

/**
 * Test anycast address with N queues in a 3 node cluster environment.  Messages should be "round robin"'d across the
 * each queue.
 * @throws Exception
 */
@Test
public void testAnycastAddressMultiQueuesWithFilterRoutingMultiNode() throws Exception {
    String address = "test.address";
    String queueNamePrefix = "test.queue";
    String clusterAddress = "test";
    for (int i = 0; i < 3; i++) {
        setupServer(i, isFileStorage(), isNetty());
    }
    setupClusterConnection("cluster0", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", clusterAddress, MessageLoadBalancingType.STRICT, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2);
    startServers(0, 1, 2);
    List<Queue> queues;
    for (int i = 0; i < 3; i++) {
        createAddressInfo(i, address, RoutingType.ANYCAST, -1, false);
        setupSessionFactory(i, isNetty());
    }
    String filter1 = "giraffe";
    String filter2 = "platypus";
    createQueue(0, address, queueNamePrefix + 0, filter1, false, RoutingType.ANYCAST);
    createQueue(1, address, queueNamePrefix + 1, filter1, false, RoutingType.ANYCAST);
    createQueue(2, address, queueNamePrefix + 2, filter2, false, RoutingType.ANYCAST);
    for (int i = 0; i < 3; i++) {
        addConsumer(i, i, queueNamePrefix + i, null);
    }
    for (int i = 0; i < 3; i++) {
        waitForBindings(i, address, 1, 1, true);
        waitForBindings(i, address, 2, 2, false);
    }
    final int noMessages = 30;
    send(0, address, noMessages, true, filter1, null);
    // Each consumer should receive noMessages / noServers
    for (int i = 0; i < noMessages / 2; i++) {
        for (int c = 0; c < 2; c++) {
            assertNotNull(consumers[c].consumer.receive(1000));
        }
    }
    assertNull(consumers[2].consumer.receive(1000));
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 65 with Queue

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

the class SessionTest method testRollbackWithSend.

@Test
public void testRollbackWithSend() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, false, true);
    clientSession.createQueue(queueName, queueName, false);
    ClientProducer cp = clientSession.createProducer(queueName);
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
    Assert.assertEquals(0, getMessageCount(q));
    clientSession.rollback();
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    clientSession.commit();
    Assert.assertEquals(2, getMessageCount(q));
    clientSession.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

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