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

The following examples show how to use org.apache.activemq.broker.BrokerService#setDataDirectory() . 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: JMSEndpointSuspensionViaVFSTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private boolean startBroker() {
    try {
        log.info("JMSServerController: Preparing to start JMS Broker: ");
        broker = new BrokerService();
        // configure the broker

        broker.setBrokerName("myBroker1");
        log.info(broker.getBrokerDataDirectory());
        broker.setDataDirectory(System.getProperty(FrameworkConstants.CARBON_HOME) + File.separator + broker
                .getBrokerDataDirectory());
        broker.setTransportConnectors(getTCPConnectors());
        broker.setPersistent(true);

        broker.start();
        log.info("JMSServerController: Broker is Successfully started. continuing tests");
        return true;
    } catch (Exception e) {
        log.error("JMSServerController: There was an error starting JMS broker: ", e);
        return false;
    }
}
 
Example 2
Source File: JMSEndpointSuspensionViaVFSTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private boolean startBroker() {
    try {
        log.info("JMSServerController: Preparing to start JMS Broker: " );
        broker = new BrokerService();
        // configure the broker

        broker.setBrokerName("myBroker1");
        log.info(broker.getBrokerDataDirectory());
        broker.setDataDirectory(System.getProperty(FrameworkConstants.CARBON_HOME) +
                File.separator + broker.getBrokerDataDirectory());
        broker.setTransportConnectors(getTCPConnectors());
        broker.setPersistent(true);

        broker.start();
        log.info("JMSServerController: Broker is Successfully started. continuing tests");
        return true;
    } catch (Exception e) {
        log.error(
                "JMSServerController: There was an error starting JMS broker: ", e);
        return false;
    }
}
 
Example 3
Source File: ActiveMQTestBase.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
protected BrokerService createBroker(String name, boolean deleteMessagesOnStartup,
                                     Map<String, Integer> portMap) throws Exception {
  BrokerService brokerService = new BrokerService();
  brokerService.setBrokerName(name);
  brokerService.setDeleteAllMessagesOnStartup(deleteMessagesOnStartup);
  brokerService.setUseJmx(true);
  brokerService.getManagementContext().setCreateConnector(false);
  brokerService.setDataDirectory(DATA_PARENT_DIR + File.separator + "data" + File.separator + name);
  brokerService.setPersistent(false);
  brokerService.setSchedulerSupport(false);
  brokerService.setAdvisorySupport(false);

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

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

  addAdditionalConnectors(brokerService, portMap);

  return brokerService;
}
 
Example 4
Source File: JobSchedulerTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createBroker(boolean delete) throws Exception {
   File schedulerDirectory = new File("target/scheduler");
   if (delete) {
      IOHelper.mkdirs(schedulerDirectory);
      IOHelper.deleteChildren(schedulerDirectory);
   }

   BrokerService answer = new BrokerService();
   answer.setPersistent(isPersistent());
   answer.setDeleteAllMessagesOnStartup(true);
   answer.setDataDirectory("target");
   answer.setSchedulerDirectoryFile(schedulerDirectory);
   answer.setSchedulerSupport(true);
   answer.setUseJmx(isUseJmx());
   return answer;
}
 
Example 5
Source File: EmbeddedBroker.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
    broker.setDataDirectory("target/activemq-data");
    broker.addConnector("tcp://localhost:61616");
    broker.start();
    System.out.println("JMS broker ready ...");
    Thread.sleep(125 * 60 * 1000);
    System.out.println("JMS broker exiting");
    broker.stop();
    System.exit(0);
}
 
Example 6
Source File: JMSBroker.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set initial broker configurations.
 *
 * @throws Exception if there is an error setting TransportConnectors
 */
private void setInitialConfigurations() throws Exception {
    log.info("JMSServerController: Preparing to start JMS Broker: " + serverName);
    broker = new BrokerService();
    broker.setBrokerName(serverName);
    log.info(broker.getBrokerDataDirectory());
    broker.setDataDirectory(
            System.getProperty(FrameworkConstants.CARBON_HOME) + File.separator + broker.getBrokerDataDirectory());
    broker.setTransportConnectors(transportConnectors);
    broker.setPersistent(true);
}
 
Example 7
Source File: AmqpSubscriberTest.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private void initializeActiveMQ() {
    try {
        log.info("Initializing ActiveMQ...");
        broker = new BrokerService();
        broker.setDataDirectory(AmqpSubscriberTest.class.getResource("/").getPath() +
                File.separator + ".." + File.separator + "activemq-data");
        broker.setBrokerName("testBroker");
        broker.addConnector("tcp://localhost:61617");
    } catch (Exception e) {
        throw new RuntimeException("Could not initialize ActiveMQ", e);
    }
}
 
Example 8
Source File: MockIaasServiceTest.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private static void initializeActiveMQ() {
    try {
        log.info("Initializing ActiveMQ...");
        broker = new BrokerService();
        broker.setDataDirectory(MockIaasServiceTest.class.getResource("/").getPath() +
                File.separator + ".." + File.separator + "activemq-data");
        broker.setBrokerName("testBroker");
        broker.addConnector("tcp://localhost:61617");
    } catch (Exception e) {
        throw new RuntimeException("Could not initialize ActiveMQ", e);
    }
}
 
Example 9
Source File: DestinationsPluginTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker() {
   BrokerService broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(true);
   broker.setPlugins(new BrokerPlugin[]{new DestinationsPlugin()});
   broker.setDataDirectory("target/test");
   return broker;
}
 
Example 10
Source File: KahaDBSchedulerIndexRebuildTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(JobSchedulerStoreImpl scheduler) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setJobSchedulerStore(scheduler);
   answer.setPersistent(true);
   answer.setDataDirectory(storeDir.getAbsolutePath());
   answer.setSchedulerSupport(true);
   answer.setUseJmx(false);
   return answer;
}
 
Example 11
Source File: KahaDBSchedulerMissingJournalLogsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void createBroker(JobSchedulerStoreImpl scheduler) throws Exception {
   broker = new BrokerService();
   broker.setJobSchedulerStore(scheduler);
   broker.setPersistent(true);
   broker.setDataDirectory(storeDir.getAbsolutePath());
   broker.setSchedulerSupport(true);
   broker.setUseJmx(false);
}
 
Example 12
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 13
Source File: JobSchedulerBrokerShutdownTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   File schedulerDirectory = new File("target/scheduler");

   IOHelper.mkdirs(schedulerDirectory);
   IOHelper.deleteChildren(schedulerDirectory);

   BrokerService broker = super.createBroker();
   broker.setSchedulerSupport(true);
   broker.setDataDirectory("target");
   broker.setSchedulerDirectoryFile(schedulerDirectory);
   broker.getSystemUsage().getStoreUsage().setLimit(1 * 512);
   broker.deleteAllMessages();
   return broker;
}
 
Example 14
Source File: SchedulerDBVersionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(JobSchedulerStoreImpl scheduler) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setJobSchedulerStore(scheduler);
   answer.setPersistent(true);
   answer.setDataDirectory("target");
   answer.setSchedulerSupport(true);
   answer.setUseJmx(false);
   return answer;
}
 
Example 15
Source File: EmbeddedBroker.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
    broker.setDataDirectory("target/activemq-data");
    broker.addConnector("tcp://localhost:61616");
    broker.start();
    System.out.println("JMS broker ready ...");
    Thread.sleep(125 * 60 * 1000);
    System.out.println("JMS broker exiting");
    broker.stop();
    System.exit(0);
}
 
Example 16
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 17
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 18
Source File: JMSBroker.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set initial broker configurations.
 *
 * @throws Exception if there is an error setting TransportConnectors
 */
private void setInitialConfigurations() throws Exception {
    log.info("JMSServerController: Preparing to start JMS Broker: " + serverName);
    broker = new BrokerService();
    broker.setBrokerName(serverName);
    log.info(broker.getBrokerDataDirectory());
    broker.setDataDirectory(System.getProperty(FrameworkConstants.CARBON_HOME) + File.separator
            + broker.getBrokerDataDirectory());
    broker.setTransportConnectors(transportConnectors);
    broker.setPersistent(true);
}
 
Example 19
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;
    }
 
Example 20
Source File: MiniBrokerConfiguration.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
/**
 * Configure the provider
 * @param provider the provider to configure
 */
public void configure(ActiveMqProvider provider) {
    logger.info("Configuring the provider");
    provider.setUri(CONNECTOR);


    /*
      Configure the broker to use the Maven's target directory (ie.:
      ${basedir}/target/test-classes) as the data directory for the
      broker. Therefore, it is cleaned whenever 'mvn clean' is run.
     */
    BrokerService brokerService = provider.getBroker();
    String path;
    URL url = this.getClass().getResource("/");

    /*
      Check if we are running it in within the jar, in which case we
      won't be able to use its location ...
     */

    if (url == null) {
        /*
         ... and, if that's the case, we use the OS temporary directory
         for the data directory
         */
        path = FileUtils.getTempDirectoryPath();
    }
    else {
        path = url.getPath();
    }

    brokerService.setDataDirectory(path);
    brokerService.setPersistent(false);

    try {
        logger.info("Adding MQTT connector");
        TransportConnector mqttConnector = new TransportConnector();

        mqttConnector.setUri(new URI("mqtt://localhost:1883"));
        mqttConnector.setName("mqtt");
        brokerService.addConnector(mqttConnector);


        logger.info("Adding AMQP connector");
        TransportConnector amqpConnector = new TransportConnector();
        amqpConnector.setUri(new URI("amqp://localhost:5672"));
        amqpConnector.setName("amqp");
        brokerService.addConnector(amqpConnector);

        TransportConnector defaultConnector = new TransportConnector();

        defaultConnector.setUri(new URI(CONNECTOR));
        defaultConnector.setName("default");
        brokerService.addConnector(defaultConnector);
    } catch (Exception e) {
        throw new RuntimeException("Unable to add a connector for the "
                + "service: " + e.getMessage(), e);
    }
}