Java Code Examples for org.apache.activemq.broker.BrokerService#setDeleteAllMessagesOnStartup()

The following examples show how to use org.apache.activemq.broker.BrokerService#setDeleteAllMessagesOnStartup() . 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: JdbcDurableSubDupTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
   exceptions.clear();
   for (int i = 0; i < MAX_MESSAGES; i++) {
      dupChecker[i] = 0;
   }
   broker = new BrokerService();
   broker.setAdvisorySupport(false);
   broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
   PolicyEntry policyEntry = new PolicyEntry();
   policyEntry.setMaxAuditDepth(3000);
   policyEntry.setMaxPageSize(150);
   policyEntry.setPrioritizedMessages(true);
   PolicyMap policyMap = new PolicyMap();
   policyMap.setDefaultEntry(policyEntry);
   broker.setDestinationPolicy(policyMap);

   broker.addConnector("tcp://localhost:0");
   broker.setDeleteAllMessagesOnStartup(true);
   broker.start();
   broker.waitUntilStarted();
   url = broker.getTransportConnectors().get(0).getConnectUri().toString() + "?" + urlOptions;
}
 
Example 2
Source File: ExpiredMessagesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private BrokerService createBroker(boolean deleteAllMessages, long expireMessagesPeriod) throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName("localhost");
   broker.setDestinations(new ActiveMQDestination[]{destination});
   broker.setPersistenceAdapter(new MemoryPersistenceAdapter());

   PolicyEntry defaultPolicy = new PolicyEntry();
   if (useVMCursor) {
      defaultPolicy.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
   }
   defaultPolicy.setExpireMessagesPeriod(expireMessagesPeriod);
   defaultPolicy.setMaxExpirePageSize(1200);
   PolicyMap policyMap = new PolicyMap();
   policyMap.setDefaultEntry(defaultPolicy);
   broker.setDestinationPolicy(policyMap);
   broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
   broker.addConnector("tcp://localhost:0");
   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example 3
Source File: kahaDbJdbcLeaseQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void createMaster() throws Exception {
   master = new BrokerService();
   master.setBrokerName("master");
   master.addConnector(MASTER_URL);
   master.setUseJmx(false);
   master.setPersistent(true);
   master.setDeleteAllMessagesOnStartup(true);
   KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) master.getPersistenceAdapter();
   LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
   leaseDatabaseLocker.setCreateTablesOnStartup(true);
   leaseDatabaseLocker.setDataSource(getExistingDataSource());
   leaseDatabaseLocker.setStatements(new Statements());
   kahaDBPersistenceAdapter.setLocker(leaseDatabaseLocker);
   configureLocker(kahaDBPersistenceAdapter);
   configureBroker(master);
   master.start();
}
 
Example 4
Source File: AdvisoryTempDestinationTests.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void configureBroker(BrokerService answer) throws Exception {
   answer.setPersistent(false);
   ConstantPendingMessageLimitStrategy strategy = new ConstantPendingMessageLimitStrategy();
   strategy.setLimit(10);
   PolicyEntry tempQueueEntry = createPolicyEntry(strategy);
   tempQueueEntry.setTempQueue(true);
   PolicyEntry tempTopicEntry = createPolicyEntry(strategy);
   tempTopicEntry.setTempTopic(true);

   PolicyMap pMap = new PolicyMap();
   final List<PolicyEntry> policyEntries = new ArrayList<>();
   policyEntries.add(tempQueueEntry);
   policyEntries.add(tempTopicEntry);
   pMap.setPolicyEntries(policyEntries);

   answer.setDestinationPolicy(pMap);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}
 
Example 5
Source File: NumberOfDestinationsTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void configureBroker(BrokerService answer) throws Exception {
   File dataFileDir = new File("target/test-amq-data/perfTest/kahadb");

   KahaDBPersistenceAdapter kaha = new KahaDBPersistenceAdapter();
   kaha.setDirectory(dataFileDir);
   //answer.setUseJmx(false);

   // The setEnableJournalDiskSyncs(false) setting is a little dangerous right now, as I have not verified
   // what happens if the index is updated but a journal update is lost.
   // Index is going to be in consistent, but can it be repaired?
   //kaha.setEnableJournalDiskSyncs(false);
   // Using a bigger journal file size makes he take fewer spikes as it is not switching files as often.
   //kaha.setJournalMaxFileLength(1024*100);

   // small batch means more frequent and smaller writes
   //kaha.setIndexWriteBatchSize(100);
   // do the index write in a separate thread
   //kaha.setEnableIndexWriteAsync(true);

   answer.setPersistenceAdapter(kaha);
   answer.setAdvisorySupport(false);
   answer.setEnableStatistics(false);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}
 
Example 6
Source File: TopicSubscriptionSlowConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName("localhost");
   broker.setUseJmx(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.addConnector("vm://localhost");

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setAdvisoryForSlowConsumers(true);

   policyMap.setDefaultEntry(defaultEntry);

   broker.setDestinationPolicy(policyMap);
   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example 7
Source File: ConcurrentProducerQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService brokerService = new BrokerService();
   brokerService.setEnableStatistics(false);
   brokerService.addConnector("tcp://0.0.0.0:0");
   brokerService.setDeleteAllMessagesOnStartup(true);

   PolicyEntry policy = new PolicyEntry();
   policy.setPrioritizedMessages(true);
   policy.setMaxPageSize(500);

   PolicyMap policyMap = new PolicyMap();
   policyMap.setDefaultEntry(policy);
   brokerService.setDestinationPolicy(policyMap);
   setDefaultPersistenceAdapter(brokerService);

   return brokerService;
}
 
Example 8
Source File: JmsApplicationTest.java    From examples with Apache License 2.0 5 votes vote down vote up
/**
 * Start the embedded Active MQ broker for our test.
 *
 * @throws Exception
 */
private void startEmbeddedActiveMQBroker() throws Exception
{
  broker = new BrokerService();
  String brokerName = "ActiveMQOutputOperator-broker";
  broker.setBrokerName(brokerName);
  broker.getPersistenceAdapter().setDirectory(new File("target/activemq-data/" +
    broker.getBrokerName() + '/' +
    org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter.class.getSimpleName()).getAbsoluteFile());
  broker.addConnector("tcp://localhost:61616?broker.persistent=false");
  broker.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 1024);  // 1GB
  broker.getSystemUsage().getTempUsage().setLimit(100 * 1024 * 1024);    // 100MB
  broker.setDeleteAllMessagesOnStartup(true);
  broker.start();
}
 
Example 9
Source File: BacklogNetworkCrossTalkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker(String brokerName) throws Exception {
   BrokerService broker = new BrokerService();
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setPersistent(true);
   broker.setUseJmx(false);
   broker.setBrokerName(brokerName);
   broker.addConnector(new URI(AUTO_ASSIGN_TRANSPORT));
   brokers.put(brokerName, new BrokerItem(broker));

   return broker;
}
 
Example 10
Source File: LostScheduledMessagesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void startBroker() throws Exception {
   broker = new BrokerService();
   broker.setSchedulerSupport(true);
   broker.setPersistent(true);
   broker.setDeleteAllMessagesOnStartup(false);
   broker.setDataDirectory("target");
   broker.setSchedulerDirectoryFile(schedulerDirectory);
   broker.setDataDirectoryFile(messageDirectory);
   broker.setUseJmx(false);
   broker.addConnector("vm://localhost");
   broker.start();
}
 
Example 11
Source File: MQTTNetworkOfBrokersFailoverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService broker = super.createBroker();
   broker.setPersistent(true);
   broker.setBrokerName("local");
   broker.setDataDirectory("target/activemq-data");
   broker.setDeleteAllMessagesOnStartup(true);
   TransportConnector tc = broker.addConnector(getDefaultMQTTTransportConnectorUri());
   localBrokerMQTTPort = tc.getConnectUri().getPort();
   return broker;
}
 
Example 12
Source File: MQTTNetworkOfBrokersFailoverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createRemoteBroker(PersistenceAdapter persistenceAdapter) throws Exception {
   BrokerService broker = super.createRemoteBroker(persistenceAdapter);
   broker.setPersistent(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setDataDirectory("target/activemq-data");
   TransportConnector tc = broker.addConnector(getDefaultMQTTTransportConnectorUri());
   remoteBrokerMQTTPort = tc.getConnectUri().getPort();
   return broker;
}
 
Example 13
Source File: KahaDBDurableTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer, String uri) throws Exception {
   //AMQPersistenceAdapterFactory persistenceFactory = new AMQPersistenceAdapterFactory();
   //persistenceFactory.setMaxFileLength(1024*16);
   //persistenceFactory.setPersistentIndex(true);
   //persistenceFactory.setCleanupInterval(10000);
   //answer.setPersistenceFactory(persistenceFactory);
   answer.setDeleteAllMessagesOnStartup(true);
   answer.addConnector(uri);
   answer.setUseShutdownHook(false);
   answer.setEnableStatistics(false);
}
 
Example 14
Source File: ConsumeUncompressedCompressedMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(boolean delete) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setPersistent(false);
   answer.setDeleteAllMessagesOnStartup(true);
   answer.setSchedulerSupport(false);
   answer.setUseJmx(true);
   TransportConnector connector = answer.addConnector("tcp://localhost:0");
   tcpUri = connector.getConnectUri();
   return answer;
}
 
Example 15
Source File: CursorQueueStoreTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer) throws Exception {
   PolicyEntry policy = new PolicyEntry();
   policy.setPendingQueuePolicy(new StorePendingQueueMessageStoragePolicy());
   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);
   answer.setDestinationPolicy(pMap);
   answer.setDeleteAllMessagesOnStartup(true);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}
 
Example 16
Source File: PooledConnectionSessionCleanupTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected String createBroker() throws Exception {
       brokerService = new BrokerService();
       brokerService.setDeleteAllMessagesOnStartup(true);
       brokerService.setPersistent(false);
       brokerService.setUseJmx(true);
       brokerService.getManagementContext().setCreateConnector(false);
       brokerService.getManagementContext().setCreateMBeanServer(false);
       brokerService.setAdvisorySupport(false);
       brokerService.setSchedulerSupport(false);
       brokerService.start();
       brokerService.waitUntilStarted();

       return brokerService.getVmConnectorURI().toString();
   }
 
Example 17
Source File: TwoBrokerQueueClientsReconnectTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testDuplicateSendWithNoAuditEnqueueCountStat() throws Exception {
   broker1 = "BrokerA";
   broker2 = "BrokerB";

   NetworkConnector networkConnector = bridgeBrokers(broker1, broker2);

   final AtomicBoolean first = new AtomicBoolean();
   final CountDownLatch gotMessageLatch = new CountDownLatch(1);

   BrokerService brokerService = brokers.get(broker2).broker;
   brokerService.setPersistent(true);
   brokerService.setDeleteAllMessagesOnStartup(true);
   // disable concurrent dispatch otherwise store duplicate suppression will be skipped b/c cursor audit is already
   // disabled so verification of stats will fail - ie: duplicate will be dispatched
   ((KahaDBPersistenceAdapter) brokerService.getPersistenceAdapter()).setConcurrentStoreAndDispatchQueues(false);
   brokerService.setPlugins(new BrokerPlugin[]{new BrokerPluginSupport() {
      @Override
      public void send(final ProducerBrokerExchange producerExchange,
                       org.apache.activemq.command.Message messageSend) throws Exception {
         super.send(producerExchange, messageSend);
         if (first.compareAndSet(false, true)) {
            producerExchange.getConnectionContext().setDontSendReponse(true);
            new Thread() {
               @Override
               public void run() {
                  try {
                     LOG.info("Waiting for recepit");
                     assertTrue("message received on time", gotMessageLatch.await(60, TimeUnit.SECONDS));
                     LOG.info("Stopping connection post send and receive and multiple producers");
                     producerExchange.getConnectionContext().getConnection().stop();
                  } catch (Exception e) {
                     e.printStackTrace();
                  }
               }
            }.start();
         }
      }
   }});

   // Create queue
   ActiveMQDestination dest = createDestination("TEST.FOO", false);

   // statically include our destination
   networkConnector.addStaticallyIncludedDestination(dest);

   // Run brokers
   startAllBrokers();

   waitForBridgeFormation();

   sendMessages("BrokerA", dest, 1);

   // wait for broker2 to get the initial forward
   Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         return brokers.get(broker2).broker.getAdminView().getTotalMessageCount() == 1;
      }
   });

   // message still pending on broker1
   assertEquals("messages message still there", 1, brokers.get(broker1).broker.getAdminView().getTotalMessageCount());

   // allow the bridge to be shutdown and restarted
   gotMessageLatch.countDown();

   // verify message is forwarded after restart
   assertTrue("no messages enqueued on origin", Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         return 0 == brokers.get(broker1).broker.getAdminView().getTotalMessageCount();
      }
   }));

   assertEquals("one messages pending", 1, brokers.get(broker2).broker.getAdminView().getTotalMessageCount());
   assertEquals("one messages enqueued", 1, brokers.get(broker2).broker.getDestination(dest).getDestinationStatistics().getEnqueues().getCount());
}
 
Example 18
Source File: LoadTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected void configureBroker(BrokerService answer, String uri) throws Exception {
   answer.setDeleteAllMessagesOnStartup(true);
   answer.addConnector(uri);
   answer.setUseShutdownHook(false);
}
 
Example 19
Source File: ConcurrentProducerDurableConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService brokerService = new BrokerService();
   brokerService.setEnableStatistics(false);
   brokerService.addConnector("tcp://0.0.0.0:0");
   brokerService.setDeleteAllMessagesOnStartup(true);

   PolicyEntry policy = new PolicyEntry();
   policy.setPrioritizedMessages(true);
   policy.setMaxPageSize(500);

   StorePendingDurableSubscriberMessageStoragePolicy durableSubPending = new StorePendingDurableSubscriberMessageStoragePolicy();
   durableSubPending.setImmediatePriorityDispatch(true);
   durableSubPending.setUseCache(true);
   policy.setPendingDurableSubscriberPolicy(durableSubPending);

   PolicyMap policyMap = new PolicyMap();
   policyMap.setDefaultEntry(policy);
   brokerService.setDestinationPolicy(policyMap);

   //        if (false) {
   //            // external mysql works a lot faster
   //            //
   //            JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
   //            BasicDataSource ds = new BasicDataSource();
   //            com.mysql.jdbc.Driver d = new com.mysql.jdbc.Driver();
   //            ds.setDriverClassName("com.mysql.jdbc.Driver");
   //            ds.setUrl("jdbc:mysql://localhost/activemq?relaxAutoCommit=true");
   //            ds.setMaxActive(200);
   //            ds.setUsername("root");
   //            ds.setPassword("");
   //            ds.setPoolPreparedStatements(true);
   //            jdbc.setDataSource(ds);
   //            brokerService.setPersistenceAdapter(jdbc);

         /* add mysql bits to the pom in the testing dependencies
                 <dependency>
                     <groupId>mysql</groupId>
                     <artifactId>mysql-connector-java</artifactId>
                     <version>5.1.10</version>
                     <scope>test</scope>
                 </dependency>
                 <dependency>
                     <groupId>commons-dbcp</groupId>
                     <artifactId>commons-dbcp</artifactId>
                     <version>1.2.2</version>
                     <scope>test</scope>
                 </dependency>
          */
   //        } else {
   setPersistenceAdapter(brokerService, persistenceAdapterChoice);
   //        }
   return brokerService;
}
 
Example 20
Source File: QpidJmsTestSupport.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker(String name, boolean deleteAllMessages, Map<String, Integer> portMap) throws Exception {

        BrokerService brokerService = new BrokerService();
        brokerService.setBrokerName(name);
        brokerService.setPersistent(isPersistent());
        brokerService.setSchedulerSupport(isSchedulerSupport());
        brokerService.setAdvisorySupport(isAdvisorySupport());
        brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
        brokerService.setUseJmx(true);
        brokerService.getManagementContext().setCreateConnector(false);
        brokerService.setDataDirectory("target/" + name);
        brokerService.setKeepDurableSubsActive(false);

        if (isPersistent()) {
            KahaDBStore kaha = new KahaDBStore();
            kaha.setDirectory(new File(KAHADB_DIRECTORY + "/" + name));
            kaha.setConcurrentStoreAndDispatchQueues(isConcurrentStoreAndDispatchQueues());
            kaha.setConcurrentStoreAndDispatchTopics(isConcurrentStoreAndDispatchTopics());
            kaha.setCheckpointInterval(TimeUnit.MINUTES.toMillis(5));
            brokerService.setPersistenceAdapter(kaha);
        }

        configureBrokerPolicies(brokerService);

        ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>();
        BrokerPlugin authenticationPlugin = configureAuthentication();
        if (authenticationPlugin != null) {
            plugins.add(authenticationPlugin);
        }

        BrokerPlugin authorizationPlugin = configureAuthorization();
        if (authorizationPlugin != null) {
            plugins.add(authorizationPlugin);
        }

        addAdditionalBrokerPlugins(plugins);

        if (!plugins.isEmpty()) {
            BrokerPlugin[] array = new BrokerPlugin[plugins.size()];
            brokerService.setPlugins(plugins.toArray(array));
        }

        addAdditionalConnectors(brokerService, portMap);

        return brokerService;
    }