本文整理汇总了Java中org.apache.activemq.broker.BrokerFactory类的典型用法代码示例。如果您正苦于以下问题:Java BrokerFactory类的具体用法?Java BrokerFactory怎么用?Java BrokerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BrokerFactory类属于org.apache.activemq.broker包,在下文中一共展示了BrokerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRollbackXaErrorCode
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
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();
}
示例2: testCreatePartitionBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
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());
}
示例3: createBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
private void createBroker(boolean delete) throws Exception {
broker = BrokerFactory.createBroker("broker:(vm://localhost)");
broker.setKeepDurableSubsActive(true);
broker.setPersistent(true);
broker.setDeleteAllMessagesOnStartup(delete);
KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
kahadb.setDirectory(new File("activemq-data/" + getName() + "-kahadb"));
kahadb.setJournalMaxFileLength(500 * 1024);
broker.setPersistenceAdapter(kahadb);
broker.setBrokerName(getName());
// only if we pre-create the destinations
broker.setDestinations(new ActiveMQDestination[]{topic});
broker.start();
broker.waitUntilStarted();
connection = createConnection();
}
示例4: startBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
private void startBroker(boolean deleteAllMessages) throws Exception {
if (broker != null)
return;
broker = BrokerFactory.createBroker("broker:(vm://localhost)");
broker.setBrokerName(getName());
broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
if (PERSISTENT_BROKER) {
broker.setPersistent(true);
KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
persistenceAdapter.setDirectory(new File("activemq-data/" + getName()));
broker.setPersistenceAdapter(persistenceAdapter);
} else
broker.setPersistent(false);
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();
}
示例5: startBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
private void startBroker(boolean deleteMessages) throws Exception {
broker = BrokerFactory.createBroker("broker:(vm://" + getName() + ")");
broker.setUseJmx(true);
broker.getManagementContext().setCreateConnector(false);
broker.setBrokerName(getName());
broker.setPersistent(true);
KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
persistenceAdapter.setDirectory(new File("activemq-data/" + getName()));
broker.setPersistenceAdapter(persistenceAdapter);
if (deleteMessages) {
broker.setDeleteAllMessagesOnStartup(true);
}
broker.setKeepDurableSubsActive(true);
broker.start();
broker.waitUntilStarted();
connection = createConnection();
}
示例6: createBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
protected BrokerService createBroker() throws JMSException {
BrokerService broker = null;
try {
broker = BrokerFactory.createBroker(new URI("broker://()/localhost"));
broker.setBrokerName("DefaultBroker");
broker.addConnector("tcp://localhost:9100");
broker.setUseShutdownHook(false);
broker.start();
} catch (Exception e) {
e.printStackTrace();
}
return broker;
}
示例7: initialize
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Override
public void initialize() {
super.initialize();
try {
if (_config == null) {
_broker = new BrokerService();
_broker.setStartAsync(true);
_broker.setBrokerName("default");
_broker.setUseJmx(false);
_broker.setPersistent(false);
_broker.setDataDirectoryFile(new File(System.getProperty("java.io.tmpdir"), "activemq-data"));
_broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
_broker.setUseShutdownHook(false);
} else {
_broker = BrokerFactory.createBroker(_config);
}
_broker.start();
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例8: createBroker
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Override
// TODO throw corresponding exceptions, not just Exception instances.
protected BrokerService createBroker(ServletContext sc) throws Exception {
// Initialize Web environment to make Spring resolve external
// properties.
StandardServletEnvironment standardServletEnvironment = new ReversePropertySourcesStandardServletEnvironment();
WebApplicationContextUtils.initServletPropertySources(standardServletEnvironment.getPropertySources(), sc);
URI configURI = new URI(standardServletEnvironment.getProperty(BROKER_URI_PROP));
LOG.info("Loading message broker from: " + configURI);
return BrokerFactory.createBroker(configURI);
}
示例9: execute
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
public void execute() throws Exception {
if (config == null) {
throw new Exception("required --config option missing");
}
if (file == null) {
throw new Exception("required --file option missing");
}
System.out.println("Loading: " + config);
BrokerFactory.setStartDefault(false); // to avoid the broker auto-starting..
BrokerService broker = BrokerFactory.createBroker(config);
BrokerFactory.resetStartDefault();
PersistenceAdapter store = broker.getPersistenceAdapter();
System.out.println("Starting: " + store);
store.start();
try {
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file));
try {
export(store, fos);
} finally {
fos.close();
}
} finally {
store.stop();
}
}
示例10: setup
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception {
System.setProperty("ldapPort", String.valueOf(getLdapServer().getPort()));
broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-ldap.xml");
broker.start();
broker.waitUntilStarted();
}
示例11: setup
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception {
System.setProperty("ldapPort", String.valueOf(getLdapServer().getPort()));
broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-apacheds-legacy.xml");
broker.start();
broker.waitUntilStarted();
}
示例12: setup
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@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();
}
示例13: setup
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception {
System.setProperty("ldapPort", String.valueOf(getLdapServer().getPort()));
broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-ldap-auth.xml");
broker.start();
broker.waitUntilStarted();
}
示例14: setUp
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
System.setProperty("java.security.auth.login.config", "src/test/resources/login.config");
broker1 = BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/security/broker1.xml"));
broker2 = BrokerFactory.createBroker(new URI("xbean:org/apache/activemq/security/broker2.xml"));
broker1.waitUntilStarted();
broker2.waitUntilStarted();
Thread.sleep(2000);
}
示例15: testCloseSendConnection
import org.apache.activemq.broker.BrokerFactory; //导入依赖的package包/类
public void testCloseSendConnection() throws Exception {
String brokerName = "closeSend";
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();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
connection.close();
//comment out this check as it doesn't apply to artemis
//assertTransactionGoneFromBroker(tid);
broker.stop();
}