Java Code Examples for org.apache.activemq.broker.BrokerFactory#createBroker()

The following examples show how to use org.apache.activemq.broker.BrokerFactory#createBroker() . 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: ActiveMQXAConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testRollbackXaErrorCode() throws Exception {
   String brokerName = "rollbackErrorCode";
   BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
   broker.start();
   broker.waitUntilStarted();
   ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
   XAConnection connection = (XAConnection) cf.createConnection();
   connection.start();
   XASession session = connection.createXASession();
   XAResource resource = session.getXAResource();

   Xid tid = createXid();
   try {
      resource.rollback(tid);
      fail("Expected xa exception on no tx");
   } catch (XAException expected) {
      LOG.info("got expected xa", expected);
      assertEquals("no tx", XAException.XAER_NOTA, expected.errorCode);
   }
   connection.close();
   broker.stop();
}
 
Example 2
Source File: SpringPartitionBrokerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testCreatePartitionBroker() throws Exception {

      BrokerService broker = BrokerFactory.createBroker("xbean:activemq-partition.xml");
      assertEquals(1, broker.getPlugins().length);
      PartitionBrokerPlugin plugin = (PartitionBrokerPlugin) broker.getPlugins()[0];
      Partitioning config = plugin.getConfig();
      assertEquals(2, config.getBrokers().size());

      String json = "{\n" +
         "  \"by_client_id\":{\n" +
         "    \"client1\":{\"ids\":[\"broker1\"]},\n" +
         "    \"client2\":{\"ids\":[\"broker1\",\"broker2\"]}\n" +
         "  },\n" +
         "  \"brokers\":{\n" +
         "    \"broker1\":\"tcp://localhost:61616\",\n" +
         "    \"broker2\":\"tcp://localhost:61616\"\n" +
         "  }\n" +
         "}";
      Partitioning expected = Partitioning.MAPPER.readValue(json, Partitioning.class);
      assertEquals(expected.toString(), config.toString());

   }
 
Example 3
Source File: KahaDBSupportTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void create() throws Exception {
    final String path = "target/kahatest" + System.currentTimeMillis();
    final BrokerService broker = BrokerFactory.createBroker(new URI("openejb:broker:(tcp://localhost:" + NetworkUtil.getNextAvailablePort() + ")?usekahadb=true&kahadb.directory=" + path));
    try {
        assertThat(broker.getPersistenceAdapter(), instanceOf(KahaDBPersistenceAdapter.class));
        final KahaDBPersistenceAdapter adapter = KahaDBPersistenceAdapter.class.cast(broker.getPersistenceAdapter());
        assertEquals(new File(path), adapter.getDirectory());
    } finally {
        broker.stop();
    }
}
 
Example 4
Source File: BrowseDLQTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void startBroker() throws Exception {
   brokerService = BrokerFactory.createBroker("broker:()/localhost?deleteAllMessagesOnStartup=true");

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry policyEntry = new PolicyEntry();
   policyEntry.setExpireMessagesPeriod(1000);
   policyMap.setDefaultEntry(policyEntry);
   brokerService.setDestinationPolicy(policyMap);
   brokerService.start();
   brokerService.waitUntilStarted();
}
 
Example 5
Source File: BrokerPropertiesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testPropertiesFile() throws Exception {
   BrokerService broker = BrokerFactory.createBroker("properties:org/apache/activemq/config/broker.properties");

   LOG.info("Created broker: " + broker);
   assertNotNull(broker);

   assertEquals("isUseJmx()", false, broker.isUseJmx());
   assertEquals("isPersistent()", false, broker.isPersistent());
   assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
   broker.stop();
}
 
Example 6
Source File: CachedLDAPSecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Before
@Override
public void setup() throws Exception {
   System.setProperty("ldapPort", String.valueOf(getLdapServer().getPort()));

   broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-apacheds.xml");
   broker.start();
   broker.waitUntilStarted();
}
 
Example 7
Source File: DurableSubscriptionOfflineTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void createBroker(boolean deleteAllMessages) throws Exception {
   String currentTestName = getName(true);
   broker = BrokerFactory.createBroker("broker:(vm://" + currentTestName + ")");
   broker.setBrokerName(currentTestName);
   broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
   broker.getManagementContext().setCreateConnector(false);
   broker.setAdvisorySupport(false);
   broker.setKeepDurableSubsActive(keepDurableSubsActive);
   broker.addConnector("tcp://0.0.0.0:0");

   if (usePrioritySupport) {
      PolicyEntry policy = new PolicyEntry();
      policy.setPrioritizedMessages(true);
      PolicyMap policyMap = new PolicyMap();
      policyMap.setDefaultEntry(policy);
      broker.setDestinationPolicy(policyMap);
   }

   setDefaultPersistenceAdapter(broker);
   if (broker.getPersistenceAdapter() instanceof JDBCPersistenceAdapter) {
      // ensure it kicks in during tests
      ((JDBCPersistenceAdapter) broker.getPersistenceAdapter()).setCleanupPeriod(2 * 1000);
   } else if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
      // have lots of journal files
      ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).setJournalMaxFileLength(journalMaxFileLength);
   }
   broker.start();
   broker.waitUntilStarted();
}
 
Example 8
Source File: DurableSubProcessMultiRestartTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void startBroker(boolean deleteAllMessages) throws Exception {
   if (broker != null)
      return;

   broker = BrokerFactory.createBroker("broker:(vm://" + getName() + ")");
   broker.setBrokerName(getName());
   broker.setAdvisorySupport(false);
   broker.setDeleteAllMessagesOnStartup(deleteAllMessages);

   broker.setKeepDurableSubsActive(true);

   File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
   if (deleteAllMessages)
      delete(kahadbData);

   broker.setPersistent(true);
   KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
   kahadb.setDirectory(kahadbData);
   kahadb.setJournalMaxFileLength(20 * 1024);
   broker.setPersistenceAdapter(kahadb);

   broker.addConnector("tcp://localhost:61656");

   broker.getSystemUsage().getMemoryUsage().setLimit(256 * 1024 * 1024);
   broker.getSystemUsage().getTempUsage().setLimit(256 * 1024 * 1024);
   broker.getSystemUsage().getStoreUsage().setLimit(256 * 1024 * 1024);

   broker.start();
}
 
Example 9
Source File: DurableUnsubscribeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void createBroker() throws Exception {
   broker = BrokerFactory.createBroker("broker:(vm://localhost)");
   //broker.setPersistent(false);
   broker.setUseJmx(true);
   broker.setBrokerName(getName());
   broker.deleteAllMessages();
   broker.start();

   connection = createConnection();
}
 
Example 10
Source File: DefaultStoreBrokerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   return BrokerFactory.createBroker(new URI("broker://()/localhost?deleteAllMessagesOnStartup=true"));
}
 
Example 11
Source File: RetroactiveConsumerTestWithSimpleMessageListTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   String uri = getBrokerXml();
   LOG.info("Loading broker configuration from the classpath with URI: " + uri);
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
 
Example 12
Source File: ActiveMQAdmin.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker() throws Exception {
    return BrokerFactory.createBroker(
        new URI("broker://()/localhost?persistent=false&useJmx=false&schedulerSupport=false"));
}
 
Example 13
Source File: AdvisoryNetworkBridgeTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void createBroker2() throws Exception {
   broker2 = BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/network/reconnect-broker2.xml"));
   broker2.start();
   broker2.waitUntilStarted();
}
 
Example 14
Source File: ActiveMQXAConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testReadonlyNoLeak() throws Exception {
   final String brokerName = "readOnlyNoLeak";
   BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
   broker.setPersistent(false);
   broker.start();
   ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getConnectUri() + ")");
   cf1.setStatsEnabled(true);
   ActiveMQXAConnection xaConnection = (ActiveMQXAConnection) cf1.createConnection();
   xaConnection.start();
   XASession session = xaConnection.createXASession();
   XAResource resource = session.getXAResource();
   Xid tid = createXid();
   resource.start(tid, XAResource.TMNOFLAGS);
   session.close();
   resource.end(tid, XAResource.TMSUCCESS);
   resource.commit(tid, true);

   //not apply to artemis
   //assertTransactionGoneFromBroker(tid);
   //assertTransactionGoneFromConnection(brokerName, xaConnection.getClientID(), xaConnection.getConnectionInfo().getConnectionId(), tid);
   assertSessionGone(xaConnection, session);
   assertTransactionGoneFromFailoverState(xaConnection, tid);

   // two phase
   session = xaConnection.createXASession();
   resource = session.getXAResource();
   tid = createXid();
   resource.start(tid, XAResource.TMNOFLAGS);
   session.close();
   resource.end(tid, XAResource.TMSUCCESS);
   assertEquals(XAResource.XA_RDONLY, resource.prepare(tid));

   // no need for a commit on read only
   //assertTransactionGoneFromBroker(tid);
   //assertTransactionGoneFromConnection(brokerName, xaConnection.getClientID(), xaConnection.getConnectionInfo().getConnectionId(), tid);
   assertSessionGone(xaConnection, session);
   assertTransactionGoneFromFailoverState(xaConnection, tid);

   xaConnection.close();
   broker.stop();

}
 
Example 15
Source File: DoSTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker(String uri) throws Exception {
   LOG.info("Loading broker configuration from the classpath with URI: " + uri);
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
 
Example 16
Source File: JDBCPersistenceAdapterXBeanConfigTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   String uri = "org/apache/activemq/xbean/jdbc-persistence-adapter-test.xml";
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
 
Example 17
Source File: ManagementContextXBeanConfigTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   String uri = "org/apache/activemq/xbean/management-context-test.xml";
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
 
Example 18
Source File: SimpleAuthenticationPluginTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker(String uri) throws Exception {
   LOG.info("Loading broker configuration from the classpath with URI: " + uri);
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}
 
Example 19
Source File: NetworkReconnectTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createSecondBroker() throws Exception {
   return BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/network/reconnect-broker2.xml"));
}
 
Example 20
Source File: XBeanSecurityWithGuestNoCredentialsOnlyTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createBroker(String uri) throws Exception {
   LOG.info("Loading broker configuration from the classpath with URI: " + uri);
   return BrokerFactory.createBroker(new URI("xbean:" + uri));
}