You can fully configure an embedded broker through application code, as shown in Example 1.6.
Example 1.6. Configuring an Embedded Broker in Code
BrokerService broker = new BrokerService();
broker.setBrokerName("broker1");
broker.setUseShutdownHook(false);
//Add plugin
broker.setPlugins(new BrokerPlugin[]{new JaasAuthenticationPlugin()});
//Add a network connection
NetworkConnector connector = answer.addNetworkConnector("static://"+"tcp://broker2:61616");
connector.setDuplex(true);
broker.addConnector("tcp://localhost:61616");
broker.start();![]() | Note |
|---|---|
Always add plug-ins before connectors, otherwise the plug-ins will not be initialized. |
You can use the BrokerFactory class to create and configure
a broker using the following syntax:
BrokerService broker = BrokerFactory.createBroker(new URI(URI));
The available values of the URI are:
Table 1.2. Available URI Values for BrokerFactory Class
| URI scheme | Example | Description |
|---|---|---|
| xbean: |
xbean:activemq.xml | Searches the classpath for an XML document (activemq.xml) with the given URI, which is then used
as the XML Configuration |
| file: | file:brokers/conf/activemq.xml | Loads the given file as the XML Configuration |
| broker: | broker:tcp://localhost:61616 | Configures the broker using URI Configuration |