Java Code Examples for org.apache.activemq.artemis.core.settings.impl.AddressSettings#setMaxSizeBytes()

The following examples show how to use org.apache.activemq.artemis.core.settings.impl.AddressSettings#setMaxSizeBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArtemisBrokerBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected final ActiveMQServer createServer(final boolean realFiles,
                                            final Configuration configuration,
                                            final int pageSize,
                                            final int maxAddressSize,
                                            final AddressFullMessagePolicy fullPolicy,
                                            final Map<String, AddressSettings> settings) {
   ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration, realFiles);
   if (settings != null) {
      for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
         server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
      }
   }

   AddressSettings defaultSetting = new AddressSettings();
   defaultSetting.setPageSizeBytes(pageSize);
   defaultSetting.setMaxSizeBytes(maxAddressSize);
   defaultSetting.setAddressFullMessagePolicy(fullPolicy);

   server.getAddressSettingsRepository().addMatch("#", defaultSetting);

   return server;
}
 
Example 2
Source File: SlowConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
   super.setUp();

   server = createServer(true, isNetty);

   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setSlowConsumerCheckPeriod(checkPeriod);
   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(new QueueConfiguration(QUEUE).setRoutingType(RoutingType.ANYCAST)).getPageSubscription().getPagingStore().startPaging();

   locator = createFactory(isNetty);
}
 
Example 3
Source File: ClusteredMessageCounterTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ConfigurationImpl createBasicConfig(final int serverID) {
   ConfigurationImpl config = super.createBasicConfig(serverID);
   Map<String, AddressSettings> addrSettingsMap = config.getAddressesSettings();
   AddressSettings addrSettings = new AddressSettings();
   addrSettings.setMaxSizeBytes(10 * 1024);
   addrSettings.setPageSizeBytes(5 * 1024);
   addrSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addrSettingsMap.put("queues", addrSettings);
   if (serverID == 1) {
      config.setMessageCounterEnabled(true);
   }
   return config;
}
 
Example 4
Source File: AmqpFlowControlTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureAddressPolicy(ActiveMQServer server) {
   // For BLOCK tests
   AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch("#");
   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
   addressSettings.setMaxSizeBytes(MAX_SIZE_BYTES);
   addressSettings.setMaxSizeBytesRejectThreshold(MAX_SIZE_BYTES_REJECT_THRESHOLD);
   server.getAddressSettingsRepository().addMatch("#", addressSettings);
}
 
Example 5
Source File: MQTTTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void configureBroker() throws Exception {
   // TODO Add SSL
   super.setUp();
   server = createServerForMQTT();
   addCoreConnector();
   addMQTTConnector();
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setMaxSizeBytes(999999999);
   addressSettings.setAutoCreateQueues(true);
   addressSettings.setAutoCreateAddresses(true);
   configureBrokerSecurity(server);

   server.getAddressSettingsRepository().addMatch("#", addressSettings);
}
 
Example 6
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQServer createInVMFailoverServer(final boolean realFiles,
                                                  final Configuration configuration,
                                                  final int pageSize,
                                                  final int maxAddressSize,
                                                  final Map<String, AddressSettings> settings,
                                                  NodeManager nodeManager,
                                                  final int id) {
   ActiveMQServer server;
   ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
   configuration.setPersistenceEnabled(realFiles);
   server = addServer(new InVMNodeManagerServer(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager, nodeManager));

   try {
      server.setIdentity("Server " + id);

      for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
         server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
      }

      AddressSettings defaultSetting = new AddressSettings();
      defaultSetting.setPageSizeBytes(pageSize);
      defaultSetting.setMaxSizeBytes(maxAddressSize);

      server.getAddressSettingsRepository().addMatch("#", defaultSetting);

      return server;
   } finally {
      addServer(server);
   }
}
 
Example 7
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ActiveMQServer createColocatedInVMFailoverServer(final boolean realFiles,
                                                           final Configuration configuration,
                                                           final int pageSize,
                                                           final int maxAddressSize,
                                                           final Map<String, AddressSettings> settings,
                                                           NodeManager liveNodeManager,
                                                           NodeManager backupNodeManager,
                                                           final int id) {
   ActiveMQServer server;
   ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
   configuration.setPersistenceEnabled(realFiles);
   server = new ColocatedActiveMQServer(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager, liveNodeManager, backupNodeManager);

   try {
      server.setIdentity("Server " + id);

      for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
         server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
      }

      AddressSettings defaultSetting = new AddressSettings();
      defaultSetting.setPageSizeBytes(pageSize);
      defaultSetting.setMaxSizeBytes(maxAddressSize);

      server.getAddressSettingsRepository().addMatch("#", defaultSetting);

      return server;
   } finally {
      addServer(server);
   }
}
 
Example 8
Source File: AddressSettingsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleMerge() {
   AddressSettings addressSettings = new AddressSettings();
   AddressSettings addressSettingsToMerge = new AddressSettings();
   SimpleString DLQ = new SimpleString("testDLQ");
   SimpleString exp = new SimpleString("testExpiryQueue");
   addressSettingsToMerge.setDeadLetterAddress(DLQ);
   addressSettingsToMerge.setExpiryAddress(exp);
   addressSettingsToMerge.setMaxDeliveryAttempts(1000);
   addressSettingsToMerge.setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP);
   addressSettingsToMerge.setMaxSizeBytes(1001);
   addressSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
   addressSettingsToMerge.setRedeliveryDelay(1003);
   addressSettingsToMerge.setPageSizeBytes(1004);
   addressSettingsToMerge.setMaxSizeBytesRejectThreshold(10 * 1024);

   addressSettings.merge(addressSettingsToMerge);
   Assert.assertEquals(addressSettings.getDeadLetterAddress(), DLQ);
   Assert.assertEquals(addressSettings.getExpiryAddress(), exp);
   Assert.assertEquals(addressSettings.getMaxDeliveryAttempts(), 1000);
   Assert.assertEquals(addressSettings.getMaxSizeBytes(), 1001);
   Assert.assertEquals(addressSettings.getMessageCounterHistoryDayLimit(), 1002);
   Assert.assertEquals(addressSettings.getRedeliveryDelay(), 1003);
   Assert.assertEquals(addressSettings.getPageSizeBytes(), 1004);
   Assert.assertEquals(AddressFullMessagePolicy.DROP, addressSettings.getAddressFullMessagePolicy());
   Assert.assertEquals(addressSettings.getMaxSizeBytesRejectThreshold(), 10 * 1024);
}
 
Example 9
Source File: AddressSettingsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleMerge() {
   AddressSettings addressSettings = new AddressSettings();
   AddressSettings addressSettingsToMerge = new AddressSettings();
   SimpleString DLQ = new SimpleString("testDLQ");
   SimpleString exp = new SimpleString("testExpiryQueue");
   addressSettingsToMerge.setDeadLetterAddress(DLQ);
   addressSettingsToMerge.setExpiryAddress(exp);
   addressSettingsToMerge.setMaxDeliveryAttempts(1000);
   addressSettingsToMerge.setMaxSizeBytes(1001);
   addressSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
   addressSettingsToMerge.setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP);
   addressSettingsToMerge.setMaxSizeBytesRejectThreshold(10 * 1024);
   addressSettings.merge(addressSettingsToMerge);

   AddressSettings addressSettingsToMerge2 = new AddressSettings();
   SimpleString exp2 = new SimpleString("testExpiryQueue2");
   addressSettingsToMerge2.setExpiryAddress(exp2);
   addressSettingsToMerge2.setMaxSizeBytes(2001);
   addressSettingsToMerge2.setRedeliveryDelay(2003);
   addressSettingsToMerge2.setRedeliveryMultiplier(2.5);
   addressSettings.merge(addressSettingsToMerge2);

   Assert.assertEquals(addressSettings.getDeadLetterAddress(), DLQ);
   Assert.assertEquals(addressSettings.getExpiryAddress(), exp);
   Assert.assertEquals(addressSettings.getMaxDeliveryAttempts(), 1000);
   Assert.assertEquals(addressSettings.getMaxSizeBytes(), 1001);
   Assert.assertEquals(addressSettings.getMessageCounterHistoryDayLimit(), 1002);
   Assert.assertEquals(addressSettings.getRedeliveryDelay(), 2003);
   Assert.assertEquals(addressSettings.getRedeliveryMultiplier(), 2.5, 0.000001);
   Assert.assertEquals(AddressFullMessagePolicy.DROP, addressSettings.getAddressFullMessagePolicy());
   Assert.assertEquals(addressSettings.getMaxSizeBytesRejectThreshold(), 10 * 1024);
}
 
Example 10
Source File: AddressSettingsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleMergeAll() {
   AddressSettings addressSettings = new AddressSettings();
   AddressSettings addressSettingsToMerge = new AddressSettings();
   SimpleString DLQ = new SimpleString("testDLQ");
   SimpleString exp = new SimpleString("testExpiryQueue");
   addressSettingsToMerge.setDeadLetterAddress(DLQ);
   addressSettingsToMerge.setExpiryAddress(exp);
   addressSettingsToMerge.setMaxSizeBytes(1001);
   addressSettingsToMerge.setRedeliveryDelay(1003);
   addressSettingsToMerge.setRedeliveryMultiplier(1.0);
   addressSettingsToMerge.setAddressFullMessagePolicy(AddressFullMessagePolicy.DROP);
   addressSettings.merge(addressSettingsToMerge);

   AddressSettings addressSettingsToMerge2 = new AddressSettings();
   SimpleString exp2 = new SimpleString("testExpiryQueue2");
   SimpleString DLQ2 = new SimpleString("testDlq2");
   addressSettingsToMerge2.setExpiryAddress(exp2);
   addressSettingsToMerge2.setDeadLetterAddress(DLQ2);
   addressSettingsToMerge2.setMaxDeliveryAttempts(2000);
   addressSettingsToMerge2.setMaxSizeBytes(2001);
   addressSettingsToMerge2.setMessageCounterHistoryDayLimit(2002);
   addressSettingsToMerge2.setRedeliveryDelay(2003);
   addressSettingsToMerge2.setRedeliveryMultiplier(2.0);
   addressSettingsToMerge2.setMaxRedeliveryDelay(5000);
   addressSettingsToMerge.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.merge(addressSettingsToMerge2);

   Assert.assertEquals(addressSettings.getDeadLetterAddress(), DLQ);
   Assert.assertEquals(addressSettings.getExpiryAddress(), exp);
   Assert.assertEquals(addressSettings.getMaxDeliveryAttempts(), 2000);
   Assert.assertEquals(addressSettings.getMaxSizeBytes(), 1001);
   Assert.assertEquals(addressSettings.getMessageCounterHistoryDayLimit(), 2002);
   Assert.assertEquals(addressSettings.getRedeliveryDelay(), 1003);
   Assert.assertEquals(addressSettings.getRedeliveryMultiplier(), 1.0, 0.000001);
   Assert.assertEquals(addressSettings.getMaxRedeliveryDelay(), 5000);
   Assert.assertEquals(AddressFullMessagePolicy.DROP, addressSettings.getAddressFullMessagePolicy());
}
 
Example 11
Source File: Async.java    From javalite with Apache License 2.0 5 votes vote down vote up
private void configurePaging() {
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    addressSettings.setMaxSizeBytes(30 * 1024 * 1024L);
    addressSettings.setPageSizeBytes(10 * 1024 * 1024);
    addressSettings.setPageCacheMaxSize(20);
    config.getAddressesSettings().put("jms.queue.*", addressSettings);
}
 
Example 12
Source File: SlowConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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(new QueueConfiguration(notifQueue).setAddress(ActiveMQDefaultConfiguration.getDefaultManagementNotificationAddress()).setDurable(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));
}
 
Example 13
Source File: TwoWayTwoNodeClusterTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testClusterRestartWithConfigChanged() throws Exception {
   Configuration config0 = servers[0].getConfiguration();
   Configuration config1 = servers[1].getConfiguration();

   configureBeforeStart(config0, config1);
   startServers(0, 1);

   setupSessionFactory(0, isNetty());
   setupSessionFactory(1, isNetty());

   createQueue(0, "queues", "queue0", null, true);
   createQueue(1, "queues", "queue0", null, true);

   waitForBindings(0, "queues", 1, 0, true);
   waitForBindings(1, "queues", 1, 0, true);

   waitForBindings(0, "queues", 1, 0, false);
   waitForBindings(1, "queues", 1, 0, false);

   ClientSessionFactory sf0 = sfs[0];
   ClientSession session0 = sf0.createSession(false, false);
   ClientProducer producer = session0.createProducer("queues");
   final int numSent = 200;
   for (int i = 0; i < numSent; i++) {
      ClientMessage msg = createTextMessage(session0, true, 5000);
      producer.send(msg);
      if (i % 50 == 0) {
         session0.commit();
      }
   }
   session0.commit();
   session0.close();

   while (true) {
      long msgCount0 = getMessageCount(servers[0], "queues");
      long msgCount1 = getMessageCount(servers[1], "queues");

      if (msgCount0 + msgCount1 >= numSent) {
         break;
      }
      Thread.sleep(100);
   }

   Queue queue0 = servers[0].locateQueue(new SimpleString("queue0"));
   assertTrue(queue0.getPageSubscription().isPaging());

   closeAllSessionFactories();
   stopServers(0, 1);

   AddressSettings addressSettings0 = config0.getAddressesSettings().get("#");
   AddressSettings addressSettings1 = config1.getAddressesSettings().get("#");

   addressSettings0.setMaxSizeBytes(-1);
   addressSettings1.setMaxSizeBytes(-1);

   startServers(0, 1);

   waitForBindings(0, "queues", 1, 0, true);
   waitForBindings(1, "queues", 1, 0, true);

   waitForBindings(0, "queues", 1, 0, false);
   waitForBindings(1, "queues", 1, 0, false);

   setupSessionFactory(0, isNetty());
   addConsumer(0, 0, "queue0", null);

   waitForBindings(0, "queues", 1, 1, true);

   for (int i = 0; i < numSent; i++) {
      ClientMessage m = consumers[0].consumer.receive(5000);
      assertNotNull("failed to receive message " + i, m);
   }
}
 
Example 14
Source File: AmqpFlowControlFailTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private static void configureAddressPolicy(final ActiveMQServer server) {
   AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch("#");
   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.FAIL);
   addressSettings.setMaxSizeBytes(1000);
   server.getAddressSettingsRepository().addMatch("#", addressSettings);
}