org.apache.activemq.artemis.core.settings.impl.AddressSettings Java Examples

The following examples show how to use org.apache.activemq.artemis.core.settings.impl.AddressSettings. 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: QueueImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Deprecated
public QueueImpl(final long id,
                  final SimpleString address,
                  final SimpleString name,
                  final Filter filter,
                  final SimpleString user,
                  final boolean durable,
                  final boolean temporary,
                  final boolean autoCreated,
                  final ScheduledExecutorService scheduledExecutor,
                  final PostOffice postOffice,
                  final StorageManager storageManager,
                  final HierarchicalRepository<AddressSettings> addressSettingsRepository,
                  final ArtemisExecutor executor,
                  final ActiveMQServer server,
                  final QueueFactory factory) {
   this(id, address, name, filter, null, null, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
 
Example #2
Source File: LVQTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   server = addServer(ActiveMQServers.newActiveMQServer(createDefaultNettyConfig(), true));
   // start the server
   server.start();

   server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings().setDefaultLastValueQueue(true));
   // then we create a client as normalServer
   ServerLocator locator = createNettyNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);

   ClientSessionFactory sf = createSessionFactory(locator);
   clientSession = addClientSession(sf.createSession(false, true, true));
   clientSessionTxReceives = addClientSession(sf.createSession(false, true, false));
   clientSessionTxSends = addClientSession(sf.createSession(false, false, true));
   clientSession.createQueue(new QueueConfiguration(qName1).setAddress(address));
}
 
Example #3
Source File: PrintData.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) {
   ActiveMQThreadFactory daemonFactory = new ActiveMQThreadFactory("cli", true, PrintData.class.getClassLoader());
   final ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, daemonFactory);
   final ExecutorService executor = Executors.newFixedThreadPool(10, daemonFactory);
   ExecutorFactory execfactory = new ExecutorFactory() {
      @Override
      public ArtemisExecutor getExecutor() {
         return ArtemisExecutor.delegate(executor);
      }
   };
   try {

      final StorageManager sm = new NullStorageManager();
      PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null);
      HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>();
      addressSettingsRepository.setDefault(new AddressSettings());
      PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);

      printPages(describeJournal, sm, manager, out, safe);
   } catch (Exception e) {
      e.printStackTrace();
   } finally {
      executor.shutdownNow();
      scheduled.shutdownNow();
   }
}
 
Example #4
Source File: ConsumerWindowSizeTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumerWindowSizeAddressSettings() throws Exception {
   ActiveMQServer messagingService = createServer(false, isNetty());

   final int defaultConsumerWindowSize = 1024 * 5;
   final AddressSettings settings = new AddressSettings();
   settings.setDefaultConsumerWindowSize(defaultConsumerWindowSize);
   messagingService.getConfiguration()
         .getAddressesSettings().put(queueA.toString(), settings);

   messagingService.start();
   messagingService.createQueue(new QueueConfiguration(queueA).setRoutingType(RoutingType.ANYCAST));

   ClientSessionFactory cf = createSessionFactory(locator);
   ClientSession session = cf.createSession(false, true, true);
   ClientConsumerImpl consumer = (ClientConsumerImpl) session.createConsumer(queueA);

   session.start();

   assertEquals(defaultConsumerWindowSize / 2, consumer.getClientWindowSize());
}
 
Example #5
Source File: EmbeddedTestServer.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
   log.debug("\nStarting EmbeddedTestServer");
   if (activeMQServer == null) {
      Configuration configuration = new ConfigurationImpl().setPersistenceEnabled(false).setSecurityEnabled(false).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName()));

      activeMQServer = ActiveMQServers.newActiveMQServer(configuration);
      // set DLA and expiry to avoid spamming the log with warnings
      activeMQServer.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDeadLetterAddress(SimpleString.toSimpleString("DLA")).setExpiryAddress(SimpleString.toSimpleString("Expiry")));

      activeMQServer.start();
   }
   tjws.start();
   manager.setConfiguration(config);
   manager.start();
   tjws.getDeployment().getRegistry().addSingletonResource(manager.getQueueManager().getDestination());
   tjws.getDeployment().getRegistry().addSingletonResource(manager.getTopicManager().getDestination());

}
 
Example #6
Source File: ClusteredResetMockTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ActiveMQServerControlImpl registerServer(PostOffice postOffice,
                                                SecurityStore securityStore,
                                                StorageManager storageManager,
                                                Configuration configuration,
                                                HierarchicalRepository<AddressSettings> addressSettingsRepository,
                                                HierarchicalRepository<Set<Role>> securityRepository,
                                                ResourceManager resourceManager,
                                                RemotingService remotingService,
                                                ActiveMQServer messagingServer,
                                                QueueFactory queueFactory,
                                                ScheduledExecutorService scheduledThreadPool,
                                                PagingManager pagingManager,
                                                boolean backup) throws Exception {
   return null;
}
 
Example #7
Source File: ExpiryRunnerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   ConfigurationImpl configuration = (ConfigurationImpl) createDefaultInVMConfig().setMessageExpiryScanPeriod(1000);
   server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
   // start the server
   server.start();
   // then we create a client as normal
   locator = createInVMNonHALocator().setBlockOnAcknowledge(true);

   ClientSessionFactory sessionFactory = createSessionFactory(locator);

   clientSession = sessionFactory.createSession(false, true, true);
   clientSession.createQueue(new QueueConfiguration(qName).setDurable(false));
   expiryAddress = new SimpleString("EA");
   expiryQueue = new SimpleString("expiryQ");
   AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
   server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
   server.getAddressSettingsRepository().addMatch(qName2.toString(), addressSettings);
   clientSession.createQueue(new QueueConfiguration(expiryQueue).setAddress(expiryAddress).setDurable(false));
}
 
Example #8
Source File: QueueImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void configureSlowConsumerReaper(final AddressSettings settings) {
   if (settings == null || settings.getSlowConsumerThreshold() == AddressSettings.DEFAULT_SLOW_CONSUMER_THRESHOLD) {
      if (slowConsumerReaperFuture != null) {
         slowConsumerReaperFuture.cancel(false);
         slowConsumerReaperFuture = null;
         slowConsumerReaperRunnable = null;
         if (logger.isDebugEnabled()) {
            logger.debug("Cancelled slow-consumer-reaper thread for queue \"" + getName() + "\"");
         }
      }
   } else {
      if (slowConsumerReaperRunnable == null) {
         scheduleSlowConsumerReaper(settings);
      } else if (slowConsumerReaperRunnable.checkPeriod != settings.getSlowConsumerCheckPeriod() || slowConsumerReaperRunnable.threshold != settings.getSlowConsumerThreshold() || !slowConsumerReaperRunnable.policy.equals(settings.getSlowConsumerPolicy())) {
         if (slowConsumerReaperFuture != null) {
            slowConsumerReaperFuture.cancel(false);
            slowConsumerReaperFuture = null;
         }
         scheduleSlowConsumerReaper(settings);
      }
   }
}
 
Example #9
Source File: QueueControlTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDeadLetterAddress() throws Exception {
   SimpleString address = RandomUtil.randomSimpleString();
   SimpleString queue = RandomUtil.randomSimpleString();
   final SimpleString deadLetterAddress = RandomUtil.randomSimpleString();

   session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable));

   QueueControl queueControl = createManagementControl(address, queue);
   Assert.assertNull(queueControl.getDeadLetterAddress());

   server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() {
      private static final long serialVersionUID = -4919035864731465338L;

      @Override
      public SimpleString getDeadLetterAddress() {
         return deadLetterAddress;
      }
   });

   Assert.assertEquals(deadLetterAddress.toString(), queueControl.getDeadLetterAddress());

   session.deleteQueue(queue);
}
 
Example #10
Source File: AmqpLargeMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSendAMQPReceiveCore() throws Exception {
   server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));

   int nMsgs = 200;

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   try {
      sendMessages(nMsgs, connection);

      int count = getMessageCount(server.getPostOffice(), testQueueName);
      assertEquals(nMsgs, count);

      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
      receiveJMS(nMsgs, factory);
   } finally {
      connection.close();
   }
}
 
Example #11
Source File: MessageExpirationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessagesExpiredNoBindings() throws Exception {
   SimpleString address = RandomUtil.randomSimpleString();
   SimpleString queue = RandomUtil.randomSimpleString();
   SimpleString expiryAddress = RandomUtil.randomSimpleString();

   AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
   server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);

   session.createQueue(new QueueConfiguration(queue).setAddress(address));

   Assert.assertEquals(0, server.locateQueue(queue).getMessagesExpired());

   ClientProducer producer = session.createProducer(address);
   ClientMessage message = session.createMessage(true);
   message.setExpiration(System.currentTimeMillis() + EXPIRATION);
   producer.send(message);

   Assert.assertTrue(Wait.waitFor(() -> server.locateQueue(queue).getMessagesExpired() == 1, 2000, 100));

   assertEquals(0, server.locateQueue(queue).getMessageCount());
   assertEquals(0, server.locateQueue(queue).getDeliveringCount());

   session.deleteQueue(queue);
}
 
Example #12
Source File: AddressQueryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddressQueryDefaultsOnAutoCreatedAddress() throws Exception {
   SimpleString addressName = SimpleString.toSimpleString(UUID.randomUUID().toString());
   server.getAddressSettingsRepository().addMatch(addressName.toString(), new AddressSettings());
   ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0");
   JMSContext c = cf.createContext();
   c.createProducer().send(c.createTopic(addressName.toString()), c.createMessage());
   AddressQueryResult addressQueryResult = server.addressQuery(addressName);
   assertTrue(addressQueryResult.isExists());
   assertFalse(addressQueryResult.getRoutingTypes().contains(RoutingType.ANYCAST));
   assertTrue(addressQueryResult.getRoutingTypes().contains(RoutingType.MULTICAST));
   assertEquals(addressName, addressQueryResult.getName());
   assertTrue(addressQueryResult.isAutoCreateAddresses());
   assertEquals(-1, addressQueryResult.getDefaultMaxConsumers());
   assertTrue(addressQueryResult.isAutoCreated());
   assertFalse(addressQueryResult.isDefaultPurgeOnNoConsumers());
}
 
Example #13
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected ActiveMQServer createServer(final boolean realFiles,
                                      final Configuration configuration,
                                      final int pageSize,
                                      final long maxAddressSize,
                                      final Map<String, AddressSettings> settings) {
   ActiveMQServer server = addServer(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().setPageSizeBytes(pageSize).setMaxSizeBytes(maxAddressSize).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);

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

   return server;
}
 
Example #14
Source File: NewDeadLetterAddressTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendToDLAWhenNoRoute() throws Exception {
   SimpleString dla = new SimpleString("DLA");
   SimpleString address = new SimpleString("empty_address");
   AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dla).setSendToDLAOnNoRoute(true);
   server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
   SimpleString dlq = new SimpleString("DLQ1");
   clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false));
   ClientProducer producer = clientSession.createProducer(address);
   producer.send(createTextMessage(clientSession, "heyho!"));
   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(dlq);
   ClientMessage m = clientConsumer.receive(500);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
 
Example #15
Source File: AutoCreateJmsDestinationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test (timeout = 30000)
// QueueAutoCreationTest was created to validate auto-creation of queues
// and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
public void testAutoCreateOnAddressOnly() throws Exception {

   server.getAddressSettingsRepository().clear();
   AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(false);
   server.getAddressSettingsRepository().addMatch("#", settings);

   ConnectionFactory factory = new ActiveMQConnectionFactory();
   try (Connection connection = factory.createConnection()) {
      SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
      instanceLog.debug("Address is " + addressName);
      javax.jms.Queue queue = new ActiveMQQueue(addressName.toString());
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(null);
      try {
         producer.send(queue, session.createTextMessage("hello"));
         Assert.fail("Expected to throw exception here");
      } catch (JMSException expected) {
      }
      Assert.assertFalse(((ActiveMQDestination) queue).isCreated());
   }

}
 
Example #16
Source File: MqttClusterRemoteSubscribeTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void setupServers(String TOPIC) throws Exception {
   WildcardConfiguration wildcardConfiguration = createWildCardConfiguration();
   CoreAddressConfiguration coreAddressConfiguration = createAddressConfiguration(TOPIC);
   AddressSettings addressSettings = createAddressSettings();


   setupServer(0, false, isNetty());
   servers[0].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
   servers[0].getConfiguration().addAddressConfiguration(coreAddressConfiguration);
   servers[0].getConfiguration().addAddressesSetting("#", addressSettings);
   setupServer(1, false, isNetty());
   servers[1].getConfiguration().setWildCardConfiguration(wildcardConfiguration);
   servers[1].getConfiguration().addAddressConfiguration(coreAddressConfiguration);
   servers[1].getConfiguration().addAddressesSetting("#", addressSettings);

   setupClusterConnection("cluster0", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
   setupClusterConnection("cluster1", "", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
}
 
Example #17
Source File: DeadLetterAddressTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSendToMultipleQueues() throws Exception {
   SimpleString dla = new SimpleString("DLA");
   SimpleString qName = new SimpleString("q1");
   AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
   server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
   SimpleString dlq = new SimpleString("DLQ1");
   SimpleString dlq2 = new SimpleString("DLQ2");
   clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(dlq2).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(qName).setDurable(false));
   ClientProducer producer = clientSession.createProducer(qName);
   producer.send(createTextMessage(clientSession, "heyho!"));
   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(qName);
   ClientMessage m = clientConsumer.receive(500);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   // force a cancel
   clientSession.rollback();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(dlq);
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(dlq2);
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   clientConsumer.close();
}
 
Example #18
Source File: DeadLetterAddressTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testLargeMessageFileLeak() throws Exception {
   OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();

   // only run this on *nix systems which will have the com.sun.management.UnixOperatingSystemMXBean (needed to check open file count)
   Assume.assumeTrue(os instanceof UnixOperatingSystemMXBean);

   long fdBaseline = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
   final int SIZE = 2 * 1024;
   SimpleString dla = new SimpleString("DLA");
   SimpleString qName = new SimpleString("q1");
   SimpleString adName = new SimpleString("ad1");

   AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
   server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
   SimpleString dlq = new SimpleString("DLQ1");
   clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(qName).setAddress(adName).setDurable(false));
   for (int i = 0; i < 10; i++) {
      ClientProducer producer = clientSession.createProducer(adName);
      ClientMessage clientFile = clientSession.createMessage(true);
      clientFile.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
      producer.send(clientFile);
      clientSession.start();
      ClientConsumer clientConsumer = clientSession.createConsumer(qName);
      ClientMessage m = clientConsumer.receive(500);
      m.acknowledge();
      Assert.assertNotNull(m);

      // force a cancel
      clientSession.rollback();
      m = clientConsumer.receiveImmediate();
      Assert.assertNull(m);
      clientConsumer.close();
   }
   assertTrue("File descriptors are leaking", ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount() - fdBaseline <= 0);
}
 
Example #19
Source File: ActiveMQTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected final ActiveMQServer createServer(final boolean realFiles,
                                            final Configuration configuration,
                                            final int pageSize,
                                            final long maxAddressSize,
                                            final Map<String, AddressSettings> settings,
                                            StoreConfiguration.StoreType storeType) {
   if (storeType == StoreConfiguration.StoreType.DATABASE) {
      setDBStoreType(configuration);
   }
   return createServer(realFiles, configuration, pageSize, maxAddressSize, settings);
}
 
Example #20
Source File: AmqpLargeMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testMessageWithAmqpValueAndEmptyBinaryPreservesBody() throws Exception {
   server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   try {
      AmqpSession session = connection.createSession();
      AmqpSender sender = session.createSender(getTestName());

      AmqpMessage message = createAmqpLargeMessageWithNoBody();

      message.getWrappedMessage().setBody(new AmqpValue(new Binary(new byte[0])));

      sender.send(message);
      sender.close();

      AmqpReceiver receiver = session.createReceiver(getTestName());
      receiver.flow(1);

      AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
      assertNotNull("failed to read large AMQP message", received);
      MessageImpl wrapped = (MessageImpl) received.getWrappedMessage();

      assertTrue(wrapped.getBody() instanceof AmqpValue);
      AmqpValue body = (AmqpValue) wrapped.getBody();
      assertTrue(body.getValue() instanceof Binary);
      Binary payload = (Binary) body.getValue();
      assertEquals(0, payload.getLength());

      received.accept();
      session.close();
   } finally {
      connection.close();
   }
}
 
Example #21
Source File: QueueImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private SimpleString expiryAddressFromAddressSettings(MessageReference ref) {
   SimpleString messageAddress = extractAddress(ref.getMessage());
   SimpleString expiryAddress = null;

   if (messageAddress != null) {
      AddressSettings addressSettings = addressSettingsRepository.getMatch(messageAddress.toString());

      expiryAddress = addressSettings.getExpiryAddress();
   }

   return expiryAddress;
}
 
Example #22
Source File: Async.java    From javalite with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the server.
 */
public void start(){

    try {
        artemisServer = new EmbeddedActiveMQ();
        artemisServer.setConfiguration(config);
        artemisServer.start();

        //somehow this only works after start of the server, lol.
        artemisServer.getActiveMQServer().getAddressSettingsRepository()
                .addMatch("#", new AddressSettings()
                .setAutoCreateQueues(false)
                .setAutoCreateAddresses(false)
                .setAutoDeleteQueues(false)
                .setAutoDeleteAddresses(false));

        Wait.waitFor(() -> artemisServer.getActiveMQServer().isStarted());

        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://0");

        consumerConnection = connectionFactory.createConnection();
        receiverSessionPool = new SessionPool("Consumer", consumerConnection);

        producerConnection = connectionFactory.createConnection();
        senderSessionPool = new SessionPool("Producer", producerConnection);
        configureListeners(injector, queueConfigsList);
        started = true;
    } catch (Exception e) {
        throw new AsyncException(e);
    }
}
 
Example #23
Source File: ScaleDownTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPaging() throws Exception {
   final int CHUNK_SIZE = 50;
   int messageCount = 0;
   final String addressName = "testAddress";
   final String queueName = "testQueue";

   createQueue(0, addressName, queueName, null, false);
   createQueue(1, addressName, queueName, null, false);

   ClientSessionFactory sf = sfs[0];
   ClientSession session = addClientSession(sf.createSession(false, false));
   ClientProducer producer = addClientProducer(session.createProducer(addressName));

   AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(10 * 1024).setMaxSizeBytes(20 * 1024);
   servers[0].getAddressSettingsRepository().addMatch("#", defaultSetting);

   while (!servers[0].getPagingManager().getPageStore(new SimpleString(addressName)).isPaging()) {
      for (int i = 0; i < CHUNK_SIZE; i++) {
         ClientMessage message = session.createMessage(true);
         message.getBodyBuffer().writeBytes(new byte[1024]);
         producer.send(message);
         messageCount++;
      }
      session.commit();
   }

   servers[0].stop();

   addConsumer(0, 1, queueName, null);
   for (int i = 0; i < messageCount; i++) {
      Assert.assertNotNull(consumers[0].getConsumer().receive(250));
   }

   Assert.assertNull(consumers[0].getConsumer().receive(250));
   removeConsumer(0);
}
 
Example #24
Source File: AutoDeleteDistributedTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void setupServers() throws Exception {
   setupServer(0, isFileStorage(), isNetty());
   setupServer(1, isFileStorage(), isNetty());
   setupServer(2, isFileStorage(), isNetty());
   servers[0].getConfiguration().addAddressesSetting("*", new AddressSettings().setAutoCreateAddresses(true) //
      .setAutoCreateQueues(true) //
      .setAutoDeleteAddresses(true) //
      .setAutoDeleteQueues(true) //  --> this causes IllegalStateExceptions
      .setDefaultPurgeOnNoConsumers(true));
}
 
Example #25
Source File: JMSLVQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void addConfiguration(ActiveMQServer server) {
   server.getConfiguration().setPersistenceEnabled(false);
   server.getConfiguration().setMessageExpiryScanPeriod(1000);
   server.getAddressSettingsRepository().addMatch(NORMAL_QUEUE_NAME, new AddressSettings());
   server.getAddressSettingsRepository().addMatch(LVQ_QUEUE_NAME, new AddressSettings().setDefaultLastValueQueue(true));
   server.getAddressSettingsRepository().addMatch(LVQ_CUSTOM_KEY_QUEUE_NAME, new AddressSettings().setDefaultLastValueQueue(true).setDefaultLastValueKey(SimpleString.toSimpleString(CUSTOM_KEY)));
}
 
Example #26
Source File: AutoCreateDeadLetterResourcesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void testAutoCreatedDeadLetterFilter(RoutingType routingType) throws Exception {
   final int ITERATIONS = 100;
   final int MESSAGE_COUNT = 10;

   for (int i = 0; i < ITERATIONS; i++) {
      SimpleString address = RandomUtil.randomSimpleString();
      SimpleString queue = RandomUtil.randomSimpleString();
      server.createQueue(new QueueConfiguration(queue).setAddress(address).setRoutingType(routingType));
      ServerLocator locator = createInVMNonHALocator();
      ClientSessionFactory cf = createSessionFactory(locator);
      ClientSession s = addClientSession(cf.createSession(true, false));
      ClientProducer p = s.createProducer(address);
      for (int j = 0; j < MESSAGE_COUNT; j++) {
         p.send(s.createMessage(true).setRoutingType(routingType));
      }
      p.close();
      ClientConsumer consumer = s.createConsumer(queue);
      s.start();
      for (int j = 0; j < MESSAGE_COUNT; j++) {
         ClientMessage message = consumer.receive();
         assertNotNull(message);
         message.acknowledge();
      }
      s.rollback();
      Queue dlq = server.locateQueue(AddressSettings.DEFAULT_DEAD_LETTER_QUEUE_PREFIX.concat(address).concat(AddressSettings.DEFAULT_DEAD_LETTER_QUEUE_SUFFIX));
      assertNotNull(dlq);
      Wait.assertEquals(MESSAGE_COUNT, dlq::getMessageCount);
   }

   assertEquals(ITERATIONS, server.getPostOffice().getBindingsForAddress(dla).getBindings().size());
}
 
Example #27
Source File: DeadLetterAddressTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSend2times() throws Exception {
   SimpleString dla = new SimpleString("DLA");
   SimpleString qName = new SimpleString("q1");
   AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(2).setDeadLetterAddress(dla);
   server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
   SimpleString dlq = new SimpleString("DLQ1");
   clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(qName).setDurable(false));
   ClientProducer producer = clientSession.createProducer(qName);
   producer.send(createTextMessage(clientSession, "heyho!"));
   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(qName);
   ClientMessage m = clientConsumer.receive(5000);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   // force a cancel
   clientSession.rollback();
   clientSession.start();
   m = clientConsumer.receive(5000);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   // force a cancel
   clientSession.rollback();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(dlq);
   m = clientConsumer.receive(5000);
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
 
Example #28
Source File: ActiveMQServerImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Deprecated
@Override
public Queue createQueue(final SimpleString address,
                         final RoutingType routingType,
                         final SimpleString queueName,
                         final SimpleString filterString,
                         final SimpleString user,
                         final boolean durable,
                         final boolean temporary,
                         final boolean ignoreIfExists,
                         final boolean transientQueue,
                         final boolean autoCreated,
                         final int maxConsumers,
                         final boolean purgeOnNoConsumers,
                         final boolean exclusive,
                         final boolean groupRebalance,
                         final int groupBuckets,
                         final boolean lastValue,
                         final SimpleString lastValueKey,
                         final boolean nonDestructive,
                         final int consumersBeforeDispatch,
                         final long delayBeforeDispatch,
                         final boolean autoDelete,
                         final long autoDeleteDelay,
                         final long autoDeleteMessageCount,
                         final boolean autoCreateAddress) throws Exception {
   AddressSettings as = getAddressSettingsRepository().getMatch(address == null ? queueName.toString() : address.toString());
   return createQueue(new AddressInfo(address).addRoutingType(routingType), queueName, filterString, user, durable, temporary, ignoreIfExists, transientQueue, autoCreated, maxConsumers, purgeOnNoConsumers, exclusive, groupRebalance, groupBuckets, as.getDefaultGroupFirstKey(), lastValue, lastValueKey, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, autoDelete, autoDeleteDelay, autoDeleteMessageCount, autoCreateAddress, false, as.getDefaultRingSize());
}
 
Example #29
Source File: QueueImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Deprecated
public QueueImpl(final long id,
                 final SimpleString address,
                 final SimpleString name,
                 final Filter filter,
                 final PagingStore pagingStore,
                 final PageSubscription pageSubscription,
                 final SimpleString user,
                 final boolean durable,
                 final boolean temporary,
                 final boolean autoCreated,
                 final RoutingType routingType,
                 final Integer maxConsumers,
                 final Boolean exclusive,
                 final Boolean groupRebalance,
                 final Integer groupBuckets,
                 final Boolean nonDestructive,
                 final Integer consumersBeforeDispatch,
                 final Long delayBeforeDispatch,
                 final Boolean purgeOnNoConsumers,
                 final Boolean autoDelete,
                 final Long autoDeleteDelay,
                 final Long autoDeleteMessageCount,
                 final boolean configurationManaged,
                 final ScheduledExecutorService scheduledExecutor,
                 final PostOffice postOffice,
                 final StorageManager storageManager,
                 final HierarchicalRepository<AddressSettings> addressSettingsRepository,
                 final ArtemisExecutor executor,
                 final ActiveMQServer server,
                 final QueueFactory factory) {
   this(id, address, name, filter, pagingStore, pageSubscription, user, durable, temporary, autoCreated, routingType, maxConsumers, exclusive, groupRebalance, groupBuckets, null, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, purgeOnNoConsumers, autoDelete, autoDeleteDelay, autoDeleteMessageCount, configurationManaged, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, server, factory);
}
 
Example #30
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());
}