Activemq startup is very simple.
Such as
1. Booting from a binary release package
On Windows:
CD [ACTIVEMQ_INSTALL_DIR]BIN\ACTIVEMQ Start
2. Start from source mode
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/83/F7/wKioL1eCJReRNI5JAAA6BdItzjs378.png "title=" 111. PNG "alt=" Wkiol1ecjrerni5jaaa6bditzjs378.png "/>
Main Class:org.apache.activemq.console.Main
Arguments:start Xbean:activemq2.xml
One of the simplest configuration files for activemq2.xml content
<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:amq= "http// Activemq.apache.org/schema/core " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " Xsi:schemalocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/ beans/spring-beans-2.0.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/ schema/core/activemq-core.xsd http://activemq.apache.org/camel/schema/spring http:// Activemq.apache.org/camel/schema/spring/camel-spring.xsd "> <!-- allows us to use system properties as variables in this configuration file --> <bean class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "/> <broker xmlns= "Http://activemq.apache.org/schema/core" brokername= "localhost" datadirectory= "${activemq.basE}/data "> <!-- the transport connectors activemq will listen to --> <transportConnectors> <transportconnector name= "Openwire" uri= "tcp://localhost:61616" /> </transportConnectors> </broker></beans>
Command List
There are many commands, the start command is just one of them.
tasks: browse - Display selected messages in a specified destination. bstat - Performs a predefined Query that displays useful statistics regarding the specified broker create - creates a runnable broker instance in the specified path. decrypt - Decrypts given text encrypt - encrypts given text export - Exports a stopped brokers data files to an archive file list - lists all available brokers in the specified jmx context purge - delete selected destination ' s messages that matches the message selector query - display selected broker Component ' s attributes and statistics. start - creates and starts a broker using a configuration file, or a broker uri. stop - Stops a running broker Specified by the broker name.
Start process sequence diagram
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/83/F7/wKioL1eCJaripXE-AADY9Ae-ntM860.png "title=" 222. PNG "alt=" Wkiol1ecjaripxe-aady9ae-ntm860.png "/>
View the Main method entry by analyzing the Activemq*.jar. Navigate to Org.apache.activemq.console.Main.
By reflection, call the Main method of Shellcommand
public static final string task_default_class = " Org.apache.activemq.console.command.ShellCommand ";p Ublic void runtaskclass (list<string> Tokens) throws Throwable {... ClassLoader cl = getClassLoader (); thread.currentthread (). Setcontextclassloader (CL); // Use reflection to run the task. try { string[] args = tokens.toarray (new String[ Tokens.size ()]); class<?> task = Cl.loadclass (task_default_class); method runtask = task.getmethod ("main", new class[] { string[].class, inputstream.class, printstream.class }); Runtask.invoke (Task.newinstance (), args, system.in, system.out); } catch (invocationtargetexception e) { throw e.getcause (); }}
Step 2
Org.apache.activemq.console.command.ShellCommand:main method
Construct the run context and formatter
Public static int main (String[] args, inputstream in, printstream out) { commandcontext context = new commandcontext (); context.setformatter (New commandshelloutputformatter (out)); // convert arguments to list for easier management list< String> tokens = new arraylist<string> (Arrays.aslist (args)); shellcommand main = new shellcommand (); try { main.setcommandcontext (context); main.execute (Tokens); return 0; } catch (exception e) { Context.printexception (e); return -1; }}
Step 3:
Org.apache.activemq.console.command.ShellCommand:runTask
Find the appropriate command, process the request
Protected void runtask (List<string> tokens) throws Exception { // Process task token if (Tokens.size () > 0) { Command command=null; String taskToken = (String) tokens.remove (0); for ( command c: getcommands () ) { if ( tasktoken.equals (C.getname ()) ) {// According to the name and parameter of each command command = c; break; } &nbsP;} if ( command == null ) { if (Tasktoken.equals ("Help") { printhelp (); } else { printhelp (); } } if ( command!=null ) { command.setcommandcontext (context); command.execute (tokens); } } else { printhelp (); }}
Step 5:org.apache.activemq.console.command.startcommand:runtask
To start the broker, first determine if the parameters are Brokeruri
Protected void runtask (List<string> brokeruris) throws Exception { try { // if no config uri, use default setting if ( Brokeruris.isempty ()) { Setconfiguri (New uri (Default_config_uri)); startbroker (Getconfiguri ()); // set configuration data, if available, which in this case // would be the config uri } else { string strconfiguri; while (! Brokeruris.isempty ()) { strConfigURI = (String) brokeruris.remove (0); try { setconfiguri (New URI ( Strconfiguri)); } catch (urisyntaxexception e) { context.printexception (e); return; } startbroker (Getconfiguri ()); } } // Prevent the main thread from exiting unless it is terminated // elsewhere } catch (exception e) { context.printexception (New runtimeexception ("Failed to execute start task. Reason: " + e, e"); throw new exception (e); } // The broker start up fine. if this unblocks it ' s cause they were stopped // and this would occur because of an internal error (Like the db going offline) waitforshutdown ();}
Class diagram
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/83/F8/wKioL1eCKCOh9KG_AAA5MR9CoAA440.png "title=" Diagram.png "alt=" Wkiol1eckcoh9kg_aaa5mr9coaa440.png "/>
This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1817646
ACTIVEMQ Analysis (i) Start-up process