Java MOM programming practice
Apache ActiveMQ is an open source message broker written in Java together with a full Java Message Service (JMS) client. It provides "Enterprise Features" which in this case means fostering the communication from more than one client or server. Supported clients include Java via JMS 1.1 as well as several other "cross language" clients. The communication is managed with features such as computer clustering and ability to use any database as a JMS persistence provider besides virtual memory, cache, and journal persistency.
Wikipedia: Apache ActiveMQ
????: Apache ActiveMQ
Official download address: http://activemq.apache.org/download.html
- Download activeMQ
- Add
activemq\bin\win64
oractivemq\bin\win32
to system path according to your system version, so that you can open activemq by just typing activemq into shell no matter which path it is now. - Open activemq
- If you have did previous step, just open cmd and type
activemq
- If not, change directory to
activemq\bin\win64
oractivemq\bin\win32
and then typeactivemq
- If you have did previous step, just open cmd and type
- Test
- In the default configuration, open
http://localhost:8161
in browser and you will see a welwcome to Apache ActiveMQ page which means your activemq works properly. - Open
http://localhost:8161/admin
with useradmin
and passwordadmin
, you will get a visualized background management system for activemq.
- In the default configuration, open
The basic message queue practice.
- Place Publisher.java in publisher host
- Place
activemq\active-all-XXXX.jar
in publisher host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 14 in publisher.java
// Message broker address tcp://ip:port private final String brokerURL = "tcp://localhost:61616";
- Compile it
javac Publisher.java
- Run it
java Publisher
- Place SyncConsumer.java in receiver host
- Place
activemq\active-all-XXXX.jar
in receiver host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 15 in SyncConsumer.java
// Message broker address tcp://ip:port String brokerURL = "tcp://localhost:61616";
- Compile it
javac SyncConsumer.java
- Run it
java SyncConsumer
- Place AsyncConsumer in receiver host
- Place
activemq\active-all-XXXX.jar
in receiver host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 17 in AsyncConsumer\AsyncConsumer.java
// Message broker address tcp://ip:port String brokerURL = "tcp://localhost:61616";
- Compile them
javac AsyncConsumer\*.java
- Run it
java AsyncConsumer.AsyncConsumer
The basic topic mode practoce.
- Place Publisher.java in publisher host
- Place
activemq\active-all-XXXX.jar
in publisher host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 14 in publisher.java
// Message broker address tcp://ip:port private final String brokerURL = "tcp://localhost:61616";
- Compile it
javac Publisher.java
- Run it
java Publisher
- Place AsyncConsumer in receiver host
- Place
activemq\active-all-XXXX.jar
in receiver host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 15 in AsyncConsumer.java
// Message broker address tcp://ip:port String brokerURL = "tcp://localhost:61616";
- Compile them
javac *.java
- Run it
java AsyncConsumer
- Place RandomSignalGenerator in publisher host
- Place
activemq\active-all-XXXX.jar
in publisher host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 16 in RandomSignalGenerator.java
// Message broker address tcp://ip:port private final String brokerURL = "tcp://localhost:61616";
- Compile it
javac RandomSignalGenerator.java
- Run it
java RandomSignalGenerator
- Note: signal obeys a given normal distribution, you can change it by changing it's mean and variance, line 73 and line 75 in RandomSignalGenerator.java
// mean of normal distribution double mean = 10; // variance of normal distribution double variance = 4;
- Place SignalAnalysis in receiver host
- Place
activemq\active-all-XXXX.jar
in receiver host - Add active-all-XXXX.jar to project dependence or to classpath
- Change brokerURL to activemq server' ip and port, line 20 in stage.Main.java
// Message broker address tcp://ip:port private final String brokerURL = "tcp://localhost:61616";
- Compile them
javac -encoding utf-8 analysis\*.java javac -encoding utf-8 view\*.java javac -encoding utf-8 stage\*.java
- Run it and you will see the UI window
java stage.Main