Installation configuration and testing of Apache ActiveMQ5.9 under Linux

Source: Internet
Author: User

Change is the eternal truth.


Because the company's products are made by Java, so the message queue of course also use Java, so choose Activemq is a good choice. Since engaged in the operation of the installation of software, configuration of the environment is very familiar, and the face of the Java project is a little disturbed, ACTIVEMQ should test how to write ACTIVEMQ test routines, for a person who does not often operate Java is a small challenge. This morning the testers sent over a compressed package that was used to test whether the ACTIVEMQ was working properly under windows and felt very bad. Because this program is written in two form program, each program must fill in the necessary parameters to execute, and must receive a very troublesome. At noon, research and Development said that the test environment in the ACTIVEMQ is not good use, found to be the cause of network fluctuations and delays, so the afternoon spent some time to study the ACTIVEMQ test routines, is summarized as follows.

First, installation configuration Activemq

#安装java, such as openjdk-7-jdk or openjdk-7-jre

Apt-get Install OPENJDK-7-JDK

#建议至少有1GB剩余内存 because the default activemq_opts_memory= "-xms1g-xmx1g"

Cd/tmp/wget Http://archive.apache.org/dist/activemq/apache-activemq/5.9.0/apache-activemq-5.9.0-bin.tar.gztar ZXF APACHE-ACTIVEMQ-5.9.0-BIN.TAR.GZCD Apache-activemq-5.9.0/vim BIN/ACTIVEMQ

# start ACTIVEMQ in debug mode

./BIN/ACTIVEMQ Console

# start ACTIVEMQ in normal mode

./bin/activemq Start

If you are prompted with the following information, you can remove this file from the/etc/default/activemq file configuration, or modify the 32nd line of the Bin/activemq startup script "activemq_configs="/etc/default/ ACTIVEMQ $HOME/.ACTIVEMQRC "", remove default, change to "activemq_configs=" $HOME/.activemqrc "", or you can use./ACTIVEMQ Setup [/etc/ DEFAULT/ACTIVEMQ | /$USER/.ACTIVEMQRC] command to create a ACTIVEMQ configuration file.

Info:loading '/etc/default/activemq '

info:using Java '/usr/bin/java '

Info:starting in foreground, this is just for debugging purposes (stop process by pressing CTRL + C)

./bin/activemq:422:./BIN/ACTIVEMQ:/usr/bin/java-xms1g-xmx1g-djava.util.logging.config.file=logging.properties- dhawtio.realm=activemq-dhawtio.role=admins-dhawtio.roleprincipalclasses= org.apache.activemq.jaas.groupprincipal-djava.security.auth.login.config=/tmp/apache-activemq-5.9.0/conf/ login.config -dcom.sun.management.jmxremote -djava.awt.headless=true-djava.io.tmpdir= "/tmp/ Apache-activemq-5.9.0/tmp "                -dactivemq.classpath= "/tmp/apache-activemq-5.9.0/conf;"               -dactivemq.home= "/tmp/ apache-activemq-5.9.0 "              - Dactivemq.base= "/tmp/apache-activemq-5.9.0"                -dactivemq.conf= "/tmp/apache-activemq-5.9.0/conf"               -dactivemq.data= "/tmp/apache-activemq-5.9.0/data"                                -jar "/tmp/apache-activemq-5.9.0/bin/activemq.jar" Start: Not found

If the ACTIVEMQ's working port is 61616 (TCP) after normal startup, the monitoring port is 8161 (HTTP), and ACTIVEMQ's working port also has: amqp://$HOSTNAME: 5672, stomp://$HOSTNAME : 61613, mqtt://$HOSTNAME: 1883, ws://$HOSTNAME: 61616, generally used is tcptcp://$HOSTNAME: 61616.

Then through Ps–ef | grep ACTIVEMQ | Grep–v grep and Netstat–anop | grep 61616 detects the port and the corresponding process ACTIVEMQ installation configuration is over.

Second, through the Java program Test ACTIVEMQ

First from the Internet to find the corresponding article, after all, this thing with more people, others must have written well, sure enough found a similar article "JMS Message Service ACITVEMQ configuration and Testing small example", although for the Windows platform, But Java program can be because of the existence of the JVM on the Linux platform can also be used, which wrote two Java programs, or feel trouble, so compile and run Java source code is sometimes very difficult, although it is known that the problem is classpath, but if not practiced or difficult to start. The test in the afternoon was mainly spent a lot of time on it.

How do I compile and run Java source code?

You can do this if you need to import the jar package in the source code description or add the jar package to the classpath.

Compiling Java source code: JAVAC-CP.: Activemq-all-5.9.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre App.java
Run Java class Program: JAVA-CP.: Activemq-all-5.9.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre App

-CP equals-classpath, the following must add the Java JRE comes with the Lib location, Ubuntu is/USR/LIB/JVM/JAVA-7-OPENJDK-AMD64/JRE, other systems are similar, if the jar package in the current directory, Then the current directory "." and jar package file absolute paths are added to Classpath, followed by the. java file name of the class name command.

If. Java has "package com.jms;" Such a line, that also need to do extra action (here to taunt developers, the cheap is sentimental, test routines to others dig pits), in the. java file directory, the next time you create the COM/JMS directory, and then put the. java files under the JMS directory, the following actions ("package COM.JMS; " As an example):

Mkdir-p com/jms mv App.java com/jms javac-cp.: Activemq-all-5.9.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre COM/JMS /app.java java-cp.: Activemq-all-5.9.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre com.jms.App

Personal guess directory separators in Java as "." , estimating is one of the reasons why it is a transplant.

It says "There are two Java programs in it, and it's still a problem" because the JMS messaging service ACITVEMQ configuration and testing small example In the original sample, there are two. java files, two directories are required to store the two. java files, otherwise, when a. java file is compiled, the following will produce some dependent. class files, depending on the contents of the import package in the compiled. java file, so once two. java files are required Using the same dependent. class file will cause a compilation conflict, prompting "bad class file ... Remove or make sure it appears in the correct subdirectory of the classpath. So I wrote these two. java files into one, and now paste them as follows (save them as Jmstestactivemq.java):

package com.jms;// refer: // refer: import  org.apache.activemq.activemqconnection; import org.apache.activemq.activemqconnectionfactory;  import javax.jms.connection;import javax.jms.connectionfactory;import javax.jms.deliverymode; import javax.jms.destination;import javax.jms.exceptionlistener;import javax.jms.jmsexception; import javax.jms.message;import javax.jms.messageconsumer;import javax.jms.messageproducer; import javax.jms.session;import javax.jms.textmessage;public class jmstestactivemq {          public static void main (String[]  args)  throws JMSException {                  ConnectionFactory connectionFactory = new  Activemqconnectionfactory (       &NBsp;                          ActiveMQConnection.DEFAULT_USER,                                   ActiveMQConnection.DEFAULT_PASSWORD,                                    "tcp://58.67.199.171:61616");                   Connection connection = connectionfactory.createconnection ();                  connection.start ();          &Nbsp;       session session = connection.createsession ( Boolean.true, session.auto_acknowledge);                  destination destination = session.createqueue (" Jmstestqueue ");                  messageproducer producer = session.createproducer (destination);                  producer.setdeliverymode ( Deliverymode.non_persistent);                  textmessage message = session.createtextmessage ("Hello world!");                   SYSTEM.OUT.PRINTLN ("Send message: hello world! ");                   Producer.send (message);                  // session.commit ();                 session.close ();                  connection.close ();                 connectionfactory connectionfactory2 = new  activemqconnectionfactory (                          ActiveMQConnection.DEFAULT_USER,                           activemqconnection.default_password,                           "tcp://58.67.199.171:61616");                   Connection connection2 = connectionfactory2.createconnection ();                  connection2.start ();                  session session2  = connection2.createsession (Boolean.true, session.auto_acknowledge);                  destination destination2  = session2.createqueue ("Jmstestqueue");                   messageconsumer consumer = session2.createconsumer (Destination2);                  while  (True)  {                           TextMessage message2 =  (TextMessage)   Consumer.receive (;              )            if  (null != message2)                                    system.out.println ("Received message:"  + message2.gettext ());                          else                                   break;                  }                  consumer.close ();                 session2.close ();                  connection2.close ();          } }

If a message is sent and the message is received, it is successful and the result is as follows:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M02/70/99/wKioL1W59iGBKR1SAAMLc-SwQlQ968.jpg" height= "233" />

The example of configuration and testing of the JMS messaging service Acitvemq is mentioned in the original, "ACTIVEMQ official also has a HelloWorld case, http://activemq.apache.org/hello-world.html", This example is an example of activemq4, Activemq5 's example in http://activemq.apache.org/version-5-hello-world.html, the official example passed JAVAC-CP.: Activemq-all-5.9.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre App.java after the direct execution of JAVA-CP.: activemq-all-5.9.0.jar:/usr/ Lib/jvm/java-7-openjdk-amd64/jre app can be run, more convenient, the results (if successful) are as follows:

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/70/99/wKioL1W59iGCPzHrAAT-XBZ5Obc702.jpg" height= "531" />

Reference:

JMS Messaging Service ACITVEMQ configuration and testing small example http://flyer2010.iteye.com/blog/662047

Apache ActiveMQ? --Version 4 Hello world:http://activemq.apache.org/hello-world.html

Apache ActiveMQ? --Version 5 Hello world:http://activemq.apache.org/version-5-hello-world.html

--end--

This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1680244

Installation configuration and testing of Apache ActiveMQ5.9 under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.