Search in sources :

Example 81 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class AMQPMessageLoadBalancingTest method setRedistributionDelay.

protected void setRedistributionDelay(final long delay) {
    AddressSettings as = new AddressSettings().setRedistributionDelay(delay);
    getServer(0).getAddressSettingsRepository().addMatch("queues.*", as);
    getServer(1).getAddressSettingsRepository().addMatch("queues.*", as);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings)

Example 82 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SessionTest method testQueueQueryNoQ.

@Test
public void testQueueQueryNoQ() throws Exception {
    server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, true, true);
    QueueQuery resp = clientSession.queueQuery(new SimpleString(queueName));
    Assert.assertFalse(resp.isExists());
    Assert.assertFalse(resp.isAutoCreateQueues());
    Assert.assertEquals(null, resp.getAddress());
    clientSession.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery) Test(org.junit.Test)

Example 83 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SlowConsumerTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    server = createServer(true, isNetty);
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setSlowConsumerCheckPeriod(1);
    addressSettings.setSlowConsumerThreshold(threshold);
    addressSettings.setSlowConsumerPolicy(SlowConsumerPolicy.KILL);
    if (isPaging) {
        addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
        addressSettings.setMaxSizeBytes(10 * 1024);
        addressSettings.setPageSizeBytes(1024);
    } else {
        addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
        addressSettings.setMaxSizeBytes(-1);
        addressSettings.setPageSizeBytes(1024);
    }
    server.start();
    server.getAddressSettingsRepository().addMatch(QUEUE.toString(), addressSettings);
    server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false).getPageSubscription().getPagingStore().startPaging();
    locator = createFactory(isNetty);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Before(org.junit.Before)

Example 84 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SlowConsumerTest method testSlowConsumerNotification.

@Test
public void testSlowConsumerNotification() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, true, true, false));
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setSlowConsumerCheckPeriod(2);
    addressSettings.setSlowConsumerThreshold(10);
    addressSettings.setSlowConsumerPolicy(SlowConsumerPolicy.NOTIFY);
    if (!isPaging) {
        addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
        addressSettings.setMaxSizeBytes(-1);
    }
    server.getAddressSettingsRepository().removeMatch(QUEUE.toString());
    server.getAddressSettingsRepository().addMatch(QUEUE.toString(), addressSettings);
    assertPaging();
    ClientProducer producer = addClientProducer(session.createProducer(QUEUE));
    final int numMessages = 25;
    for (int i = 0; i < numMessages; i++) {
        producer.send(createTextMessage(session, "m" + i));
    }
    SimpleString notifQueue = RandomUtil.randomSimpleString();
    session.createQueue(ActiveMQDefaultConfiguration.getDefaultManagementNotificationAddress(), notifQueue, null, false);
    ClientConsumer notifConsumer = session.createConsumer(notifQueue.toString(), ManagementHelper.HDR_NOTIFICATION_TYPE + "='" + CoreNotificationType.CONSUMER_SLOW + "'");
    final CountDownLatch notifLatch = new CountDownLatch(1);
    notifConsumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(ClientMessage message) {
            assertEquals(CoreNotificationType.CONSUMER_SLOW.toString(), message.getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
            assertEquals(QUEUE.toString(), message.getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
            assertEquals(Integer.valueOf(1), message.getIntProperty(ManagementHelper.HDR_CONSUMER_COUNT));
            if (isNetty) {
                assertTrue(message.getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS).toString().startsWith("/127.0.0.1"));
            } else {
                assertEquals(SimpleString.toSimpleString("invm:0"), message.getSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS));
            }
            assertNotNull(message.getSimpleStringProperty(ManagementHelper.HDR_CONNECTION_NAME));
            assertNotNull(message.getSimpleStringProperty(ManagementHelper.HDR_CONSUMER_NAME));
            assertNotNull(message.getSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME));
            try {
                message.acknowledge();
            } catch (ActiveMQException e) {
                e.printStackTrace();
            }
            notifLatch.countDown();
        }
    });
    ClientConsumer consumer = addClientConsumer(session.createConsumer(QUEUE));
    session.start();
    assertTrue(notifLatch.await(15, TimeUnit.SECONDS));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 85 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class SlowConsumerTest method testSlowWildcardConsumer.

@Test
public void testSlowWildcardConsumer() throws Exception {
    SimpleString addressAB = new SimpleString("a.b");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("a.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setSlowConsumerCheckPeriod(2);
    addressSettings.setSlowConsumerThreshold(10);
    addressSettings.setSlowConsumerPolicy(SlowConsumerPolicy.KILL);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, true, true, false));
    session.createQueue(addressAB, queueName1, null, false);
    session.createQueue(addressAC, queueName2, null, false);
    session.createQueue(address, queueName, null, false);
    ClientProducer producer = session.createProducer(addressAB);
    ClientProducer producer2 = session.createProducer(addressAC);
    final int numMessages = 20;
    for (int i = 0; i < numMessages; i++) {
        producer.send(createTextMessage(session, "m1" + i));
        producer2.send(createTextMessage(session, "m2" + i));
    }
    ClientConsumer consumer = addClientConsumer(session.createConsumer(queueName));
    session.start();
    Thread.sleep(3000);
    try {
        consumer.receiveImmediate();
        fail();
    } catch (ActiveMQObjectClosedException e) {
        assertEquals(e.getType(), ActiveMQExceptionType.OBJECT_CLOSED);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14