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

The following examples show how to use org.apache.activemq.broker.BrokerService#setTmpDataDirectory() . 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: JMSBrokerSetup.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void run() {
    try {
        //ContainerWapper container;
        BrokerService broker = new BrokerService();
        synchronized (this) {
            broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
            broker.setTmpDataDirectory(new File("./target"));
            broker.setPopulateJMSXUserID(true);
            broker.addConnector(brokerUrl);
            broker.setUseJmx(false);
            broker.start();
            Thread.sleep(200);
            notifyAll();
        }
        synchronized (this) {
            while (!shutdownBroker) {
                wait(1000);
            }
        }
        broker.stop();
        broker = null;
    } catch (Exception e) {
        exception = e;
        e.printStackTrace();
    }
}
 
Example 2
Source File: EmbeddedJMSBrokerLauncher.java    From cxf with Apache License 2.0 6 votes vote down vote up
public final void run() {
    try {
        broker = new BrokerService();
        broker.setPersistent(false);
        broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
        broker.setTmpDataDirectory(new File("./target"));
        broker.setUseJmx(false);
        if (brokerName != null) {
            broker.setBrokerName(brokerName);
        }
        broker.addConnector(brokerUrl1);
        broker.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: TestJmsSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(StandardCharsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  basicConfig = new BasicConfig();
  credentialsConfig = new CredentialsConfig();
  messageConfig = new MessageConfig();
  jmsSourceConfig = new JmsSourceConfig();
  credentialsConfig.useCredentials = true;
  credentialsConfig.username = () -> USERNAME;
  credentialsConfig.password = () -> PASSWORD;
  jmsSourceConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY;
  jmsSourceConfig.connectionFactory = CONNECTION_FACTORY;
  jmsSourceConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME;
  jmsSourceConfig.providerURL = BROKER_BIND_URL;
  // Create a connection and start
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  connection = factory.createConnection();
  connection.start();
}
 
Example 4
Source File: TestJmsTarget.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(StandardCharsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  credentialsConfig = new CredentialsConfig();
  jmsTargetConfig = new JmsTargetConfig();
  credentialsConfig.useCredentials = true;
  credentialsConfig.username = () -> USERNAME;
  credentialsConfig.password = () -> PASSWORD;
  jmsTargetConfig.destinationName = JNDI_PREFIX + DESTINATION_NAME;
  jmsTargetConfig.initialContextFactory = INITIAL_CONTEXT_FACTORY;
  jmsTargetConfig.connectionFactory = CONNECTION_FACTORY;
  jmsTargetConfig.providerURL = BROKER_BIND_URL;
  // Create a connection and start
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  connection = factory.createConnection();
  connection.start();
}
 
Example 5
Source File: AbstractVmJMSTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void startBroker(String brokerURI) {
    broker = new BrokerService();
    broker.setPersistent(false);
    try {
        broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
        broker.setTmpDataDirectory(new File("./target"));
        broker.setUseJmx(false);
        broker.addConnector(brokerURI);
        broker.start();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
Example 6
Source File: TestIntegrationActiveMQ.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
  baseDir = Files.createTempDir();
  tmpDir = new File(baseDir, "tmp");
  dataDir = new File(baseDir, "data");
  Assert.assertTrue(tmpDir.mkdir());
  passwordFile = new File(baseDir, "password");
  Files.write(PASSWORD.getBytes(Charsets.UTF_8), passwordFile);

  broker = new BrokerService();

  broker.addConnector(BROKER_BIND_URL);
  broker.setTmpDataDirectory(tmpDir);
  broker.setDataDirectoryFile(dataDir);
  List<AuthenticationUser> users = Lists.newArrayList();
  users.add(new AuthenticationUser(USERNAME, PASSWORD, ""));
  SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(users);
  broker.setPlugins(new BrokerPlugin[]{authentication});
  broker.start();

  context = new Context();
  context.put(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
  context.put(JMSSourceConfiguration.PROVIDER_URL, BROKER_BIND_URL);
  context.put(JMSSourceConfiguration.DESTINATION_NAME, DESTINATION_NAME);
  context.put(JMSSourceConfiguration.USERNAME, USERNAME);
  context.put(JMSSourceConfiguration.PASSWORD_FILE, passwordFile.getAbsolutePath());

  events = Lists.newArrayList();
  source = new JMSSource();
  source.setName("JMSSource-" + UUID.randomUUID());
  ChannelProcessor channelProcessor = mock(ChannelProcessor.class);
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      events.addAll((List<Event>)invocation.getArguments()[0]);
      return null;
    }
  }).when(channelProcessor).processEventBatch(any(List.class));
  source.setChannelProcessor(channelProcessor);


}