Search in sources :

Example 81 with AddressInfo

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

the class ClientDefinedMultiConsumerTest method test2ConsumersOnSharedDurableAddressReconnect.

@Test(timeout = 60000)
public void test2ConsumersOnSharedDurableAddressReconnect() throws Exception {
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.getRoutingTypes().add(RoutingType.MULTICAST);
    server.addAddressInfo(addressInfo);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect("myClientId"));
    AmqpSession session = connection.createSession();
    Source source = createSharedSource(TerminusDurability.CONFIGURATION);
    AmqpReceiver receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    AmqpReceiver receiver2 = session.createMulticastReceiver(source, "myReceiverID", "mySub|2");
    receiver.flow(1);
    receiver2.flow(1);
    sendMessages(address.toString(), 2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    amqpMessage = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(2, ((QueueImpl) server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")).getBindable()).getConsumerCount());
    connection.close();
    connection = addConnection(client.connect("myClientId"));
    session = connection.createSession();
    assertNotNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    receiver2 = session.createMulticastReceiver(source, "myReceiverID", "mySub|2");
    receiver.close();
    assertNotNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    receiver2.close();
    // check its been deleted
    assertNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 82 with AddressInfo

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

the class AddressingTest method testMulticastRouting.

@Test
public void testMulticastRouting() throws Exception {
    SimpleString sendAddress = new SimpleString("test.address");
    List<String> testAddresses = Arrays.asList("test.address", "test.#", "test.*");
    for (String consumeAddress : testAddresses) {
        // For each address, create 2 Queues with the same address, assert both queues receive message
        AddressInfo addressInfo = new AddressInfo(new SimpleString(consumeAddress));
        addressInfo.addRoutingType(RoutingType.MULTICAST);
        server.addOrUpdateAddressInfo(addressInfo);
        Queue q1 = server.createQueue(new SimpleString(consumeAddress), RoutingType.MULTICAST, new SimpleString(consumeAddress + ".1"), null, true, false);
        Queue q2 = server.createQueue(new SimpleString(consumeAddress), RoutingType.MULTICAST, new SimpleString(consumeAddress + ".2"), null, true, false);
        ClientSession session = sessionFactory.createSession();
        session.start();
        ClientConsumer consumer1 = session.createConsumer(q1.getName());
        ClientConsumer consumer2 = session.createConsumer(q2.getName());
        ClientProducer producer = session.createProducer(sendAddress);
        ClientMessage m = session.createMessage(ClientMessage.TEXT_TYPE, true);
        m.getBodyBuffer().writeString("TestMessage");
        producer.send(m);
        assertNotNull(consumer1.receive(2000));
        assertNotNull(consumer2.receive(2000));
        q1.deleteQueue();
        q2.deleteQueue();
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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 83 with AddressInfo

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

the class AddressingTest method testEmptyRoutingTypes.

@Test
public void testEmptyRoutingTypes() throws Exception {
    server.addOrUpdateAddressInfo(new AddressInfo(SimpleString.toSimpleString("xy")));
    server.stop();
    server.start();
    server.addOrUpdateAddressInfo(new AddressInfo(SimpleString.toSimpleString("xy")));
    server.stop();
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 84 with AddressInfo

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

the class AnycastTest method setup.

@Before
public void setup() throws Exception {
    server = createServer(true);
    server.start();
    server.waitForActivation(10, TimeUnit.SECONDS);
    ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    sessionFactory = sl.createSessionFactory();
    addSessionFactory(sessionFactory);
    addressInfo = new AddressInfo(baseAddress);
    addressInfo.addRoutingType(RoutingType.ANYCAST);
    server.addOrUpdateAddressInfo(addressInfo);
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Before(org.junit.Before)

Example 85 with AddressInfo

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

the class MulticastTest method setup.

@Before
public void setup() throws Exception {
    server = createServer(true);
    server.start();
    server.waitForActivation(10, TimeUnit.SECONDS);
    ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    sessionFactory = sl.createSessionFactory();
    addSessionFactory(sessionFactory);
    addressInfo = new AddressInfo(baseAddress);
    addressInfo.addRoutingType(RoutingType.MULTICAST);
    server.addOrUpdateAddressInfo(addressInfo);
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Before(org.junit.Before)

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