Search in sources :

Example 41 with AddressInfo

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

the class AddressingTest method testAnycastRoutingRoundRobin.

@Test
public void testAnycastRoutingRoundRobin() throws Exception {
    SimpleString address = new SimpleString("test.address");
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.addRoutingType(RoutingType.ANYCAST);
    server.addOrUpdateAddressInfo(addressInfo);
    Queue q1 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".1"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
    Queue q2 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".2"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
    Queue q3 = server.createQueue(address, RoutingType.ANYCAST, address.concat(".3"), null, true, false, Queue.MAX_CONSUMERS_UNLIMITED, false, true);
    ClientSession session = sessionFactory.createSession();
    session.start();
    ClientProducer producer = session.createProducer(address);
    ClientConsumer consumer1 = session.createConsumer(q1.getName());
    ClientConsumer consumer2 = session.createConsumer(q2.getName());
    ClientConsumer consumer3 = session.createConsumer(q3.getName());
    List<ClientConsumer> consumers = new ArrayList<>(Arrays.asList(new ClientConsumer[] { consumer1, consumer2, consumer3 }));
    List<String> messages = new ArrayList<>();
    messages.add("Message1");
    messages.add("Message2");
    messages.add("Message3");
    ClientMessage clientMessage;
    for (String message : messages) {
        clientMessage = session.createMessage(true);
        clientMessage.getBodyBuffer().writeString(message);
        producer.send(clientMessage);
    }
    String m;
    for (ClientConsumer consumer : consumers) {
        clientMessage = consumer.receive(1000);
        m = clientMessage.getBodyBuffer().readString();
        messages.remove(m);
    }
    assertTrue(messages.isEmpty());
    // Check we don't receive more messages
    int count = 0;
    for (ClientConsumer consumer : consumers) {
        count = (consumer.receive(1000) == null) ? count : count + 1;
    }
    assertEquals(0, count);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 42 with AddressInfo

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

the class AmqpClientTestSupport method createAddressAndQueues.

protected void createAddressAndQueues(ActiveMQServer server) throws Exception {
    // Default Queue
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getQueueName()), RoutingType.ANYCAST));
    server.createQueue(SimpleString.toSimpleString(getQueueName()), RoutingType.ANYCAST, SimpleString.toSimpleString(getQueueName()), null, true, false, -1, false, true);
    // Default DLQ
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getDeadLetterAddress()), RoutingType.ANYCAST));
    server.createQueue(SimpleString.toSimpleString(getDeadLetterAddress()), RoutingType.ANYCAST, SimpleString.toSimpleString(getDeadLetterAddress()), null, true, false, -1, false, true);
    // Default Topic
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getTopicName()), RoutingType.MULTICAST));
    server.createQueue(SimpleString.toSimpleString(getTopicName()), RoutingType.MULTICAST, SimpleString.toSimpleString(getTopicName()), null, true, false, -1, false, true);
    // Additional Test Queues
    for (int i = 0; i < getPrecreatedQueueSize(); ++i) {
        server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(getQueueName(i)), RoutingType.ANYCAST));
        server.createQueue(SimpleString.toSimpleString(getQueueName(i)), RoutingType.ANYCAST, SimpleString.toSimpleString(getQueueName(i)), null, true, false, -1, false, true);
    }
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 43 with AddressInfo

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

the class AmqpPurgeOnNoConsumersTest method testQueueReceiverReadMessage.

@Test(timeout = 60000)
public void testQueueReceiverReadMessage() throws Exception {
    AmqpConnection connection = null;
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    AmqpClient client = createAmqpClient();
    connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final AmqpReceiver receiver = session.createReceiver(queue);
    QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    assertEquals(0, queueView.getMessageCount());
    sendMessages(queue, 5, null, true);
    Wait.assertEquals(5, queueView::getMessageCount);
    receiver.flow(5);
    for (int i = 0; i < 4; i++) {
        try {
            AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
            receive.accept();
            assertNotNull(receive);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        receiver.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Wait.assertEquals(0, queueView::getMessageCount);
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
    connection.close();
    server.stop();
    server.start();
    queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) IOException(java.io.IOException) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 44 with AddressInfo

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

the class AmqpPurgeOnNoConsumersTest method testPurgeQueueCoreRollback.

// I'm adding the core test here to compare semantics between AMQP and core on this test.
@Test(timeout = 60000)
public void testPurgeQueueCoreRollback() throws Exception {
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:5672");
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(session.createQueue("purgeQueue"));
    javax.jms.Queue jmsQueue = session.createQueue(queue);
    MessageConsumer consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 10; i++) {
        Message message = session.createTextMessage("hello " + i);
        producer.send(message);
    }
    session.commit();
    QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
    Wait.assertEquals(10, queueView::getMessageCount);
    connection.start();
    for (int i = 0; i < 10; i++) {
        TextMessage txt = (TextMessage) consumer.receive(1000);
        assertNotNull(txt);
        assertEquals("hello " + i, txt.getText());
    }
    consumer.close();
    session.rollback();
    connection.close();
    Wait.assertEquals(0, queueView::getMessageCount);
    server.stop();
    server.start();
    queueView = (QueueImpl) getProxyToQueue(queue);
    assertEquals(0, queueView.getMessageCount());
    assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 45 with AddressInfo

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

the class AmqpReceiverTest method testClientIdIsSetInSubscriptionList.

@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    connection.setContainerId("testClient");
    connection.connect();
    try {
        AmqpSession session = connection.createSession();
        Source source = new Source();
        source.setDurable(TerminusDurability.UNSETTLED_STATE);
        source.setCapabilities(Symbol.getSymbol("topic"));
        source.setAddress("mytopic");
        session.createReceiver(source, "testSub");
        SimpleString fo = new SimpleString("testClient.testSub:mytopic");
        assertNotNull(server.locateQueue(fo));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) JMSException(javax.jms.JMSException) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Aggregations

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11