concept BrokerFactory in category activemq

This is an excerpt from Manning's book ActiveMQ in Action.
Next, we’ll describe how you can configure your broker using custom configuration XML files. We’ll use the BrokerFactory class to achieve this and you’ll learn how you can use regular configuration files to embed the broker in your Java applications. After this section you’ll be able to embed ActiveMQ with any configuration in your Java applications.
The BrokerFactory class is a utility that makes it easy to create a broker instance simply using an ActiveMQ URI. Depending on the broker URI scheme, the BrokerFactory locates the appropriate factory and uses it to create an instance of the BrokerService class. The most widely used factory is the XBeanBrokerFactory class and is configured by simply passing the XBean-style of URI. An example of an XBean broker URI is shown next:
xbean:/path/to/activemq.xmlThis example URI tells the BrokerFactory to use the XBeanBrokerFactory and the path following the colon to create the broker instance.
Now, let’s look at the following listing. The BrokerFactory can instantiate the BrokerService class using the standard ActiveMQ XML configuration file as shown.
Listing 7.4. Using the BrokerFactory with an XML configuration
public class Factory { public static void main(String[] args) throws Exception { System.setProperty("activemq.base", System.getProperty("user.dir")); String configUri = "xbean:target/classes/org/apache/activemqhttps://livebook.manning.com/book/ch6/activemq-simple.xml" URI brokerUri = new URI(configUri); BrokerService broker = BrokerFactory.createBroker(brokerUri); broker.start(); System.out.println(); System.out.println("Press any key to stop the broker"); System.out.println(); System.in.read(); } }