Search in sources :

Example 96 with ClientSessionFactory

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

the class DivertTest method testSingleExclusiveNonMatchingAndNonExclusiveDiverts.

// If no exclusive diverts match then non exclusive ones should be called
@Test
public void testSingleExclusiveNonMatchingAndNonExclusiveDiverts() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    final String filter = "animal='antelope'";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress1).setExclusive(true).setFilterString(filter);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert2").setRoutingName("divert2").setAddress(testAddress).setForwardingAddress(forwardAddress2);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert3").setRoutingName("divert3").setAddress(testAddress).setForwardingAddress(forwardAddress3);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(forwardAddress2), RoutingType.MULTICAST, queueName2, null, false);
    session.createQueue(new SimpleString(forwardAddress3), RoutingType.MULTICAST, queueName3, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName4, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putStringProperty(new SimpleString("animal"), new SimpleString("giraffe"));
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    // for (int i = 0; i < numMessages; i++)
    // {
    // ClientMessage message = consumer1.receive(200);
    // 
    // assertNotNull(message);
    // 
    // assertEquals((Integer)i, (Integer)message.getProperty(propKey));
    // 
    // message.acknowledge();
    // }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer3.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer3.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer4.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer4.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putStringProperty(new SimpleString("animal"), new SimpleString("antelope"));
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    Assert.assertNull(consumer2.receiveImmediate());
    Assert.assertNull(consumer3.receiveImmediate());
    Assert.assertNull(consumer4.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 97 with ClientSessionFactory

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

the class DivertTest method testDeployDivertsSameUniqueName.

@Test
public void testDeployDivertsSameUniqueName() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("thename1").setAddress(testAddress).setForwardingAddress(forwardAddress1);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert1").setRoutingName("thename2").setAddress(testAddress).setForwardingAddress(forwardAddress2);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert2").setRoutingName("thename3").setAddress(testAddress).setForwardingAddress(forwardAddress3);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    // Only the first and third should be deployed
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(forwardAddress2), RoutingType.MULTICAST, queueName2, null, false);
    session.createQueue(new SimpleString(forwardAddress3), RoutingType.MULTICAST, queueName3, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName4, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    Assert.assertNull(consumer2.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer3.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer3.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer4.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer4.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 98 with ClientSessionFactory

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

the class CoreClientOverHttpTest method testCoreHttpClientIdle.

@Test
public void testCoreHttpClientIdle() throws Exception {
    locator.setConnectionTTL(500);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    Thread.sleep(500 * 5);
    session.close();
}
Also used : 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) Test(org.junit.Test)

Example 99 with ClientSessionFactory

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

the class CoreClientOverHttpTest method testCoreHttpClient8kPlus.

// https://issues.jboss.org/browse/JBPAPP-5542
@Test
public void testCoreHttpClient8kPlus() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 100;
    String[] content = new String[numMessages];
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        content[i] = this.getFixedSizeString(((i % 5) + 1) * 1024 * 8);
        message.getBodyBuffer().writeString(content[i]);
        producer.send(message);
    }
    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message2 = consumer.receive();
        Assert.assertEquals(content[i], message2.getBodyBuffer().readString());
        message2.acknowledge();
    }
    session.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 100 with ClientSessionFactory

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

the class CoreClientOverHttpTest method testCoreHttpClient.

@Test
public void testCoreHttpClient() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        message.getBodyBuffer().writeString("CoreClientOverHttpTest");
        producer.send(message);
    }
    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message2 = consumer.receive();
        Assert.assertEquals("CoreClientOverHttpTest", message2.getBodyBuffer().readString());
        message2.acknowledge();
    }
    session.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)601 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)518 Test (org.junit.Test)464 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)395 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)372 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)350 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)277 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)254 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)206 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)108 Configuration (org.apache.activemq.artemis.core.config.Configuration)78 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)65 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)63 CountDownLatch (java.util.concurrent.CountDownLatch)54 Queue (org.apache.activemq.artemis.core.server.Queue)49 ArrayList (java.util.ArrayList)44 HashMap (java.util.HashMap)43 HashSet (java.util.HashSet)42 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)42 Message (org.apache.activemq.artemis.api.core.Message)41