> Download
To ACTIVEMQ official website, find the download point.
Current
Official website for http://activemq.apache.org/
Linux version of the download point is: http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz
> Start
Download to this machine and unzip
wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz
tar-xf./ Apache-activemq-5.11.1-bin.tar.gz
Boot (of course, because it relies on Java, if you don't have Java installed, it will remind you, haha)
CD./apache-activemq-5.11.1-bin/bin
./activemq start
> Test startup success or failure
ACTIVEMQ the default listening to port 61616, check this port to see if it starts successfully.
Netstat-an|grep 61616
If all goes well, you will see the following log
[Nicchagil@localhost bin]$./activemq start info:loading '/home/nicchagil/app/apache-activemq-5.11.1/bin/env ' INFO: Using java '/home/nicchagil/app/jdk1.7.0_71//bin/java ' info:starting-inspect logfiles specified in logging.properties and Log4j.prop Erties to get details Info:pidfile created: '/home/nicchagil/app/apache -activemq-5.11.1/data/activem Q.pid ' (PID ' 4858 ') [Nicchagil@localhost bin]$ [nicchagil@ localhost bin]$ [nicchagil@localhost bin]$ [nicchagil@localhost bin]$ Netstat-an | grep 61616 TCP 0 0::: 61616:::* LIST EN [Nicchagil@localhost bin]$
By the way, log on to the admin page to see if there are any problems with wood:
url:http://10.0.0.109:8161/admin/
Acc/pwd:admin/admin
> Try basic Messaging Features
Next, use a simple point-to-point test message to send and receive messages.
Introduction Package: Activemq-client-5.11.1.jar Geronimo-j2ee-management_1.1_spec-1.0.1.jar Geronimo-jms_1.1_spec-1.1.1.jar Hawtbuf-1.11.jar Slf4j-api-1.7.10.jar
Message sending
Package com.nicchagil.activemq.study.No001 point of points;
Import javax.jms.Connection;
Import Javax.jms.ConnectionFactory;
Import Javax.jms.DeliveryMode;
Import javax.jms.Destination;
Import javax.jms.JMSException;
Import Javax.jms.MessageProducer;
Import Javax.jms.ObjectMessage;
Import javax.jms.Session;
Import org.apache.activemq.ActiveMQConnection;
Import Org.apache.activemq.ActiveMQConnectionFactory; public class Sender {public static void main (string[] args) throws JMSException {connectionfactory fact Ory = new Activemqconnectionfactory (Activemqconnection.default_user, Activemqconnection.default_password, "tcp://
10.0.0.109:61616 ");
Connection Connection = Factory.createconnection ();
Connection.start ();
Session session = Connection.createsession (Boolean.true, Session.auto_acknowledge);
Destination Destination = Session.createqueue ("Testqueue");
MessageProducer producer = Session.createproducer (destination); Producer.setdeLiverymode (deliverymode.non_persistent);
ObjectMessage message = session.createobjectmessage ("Hello World ...");
Producer.send (message);
Session.commit ();
SYSTEM.OUT.PRINTLN ("Sent ..."); }
}
Message reception
Package com.nicchagil.activemq.study.No001 point of points;
Import javax.jms.Connection;
Import Javax.jms.ConnectionFactory;
Import javax.jms.Destination;
Import javax.jms.JMSException;
Import Javax.jms.MessageConsumer;
Import Javax.jms.ObjectMessage;
Import javax.jms.Session;
Import org.apache.activemq.ActiveMQConnection;
Import Org.apache.activemq.ActiveMQConnectionFactory; public class Receiver {public static void main (string[] args) throws JMSException {ConnectionFactory factor y = new Activemqconnectionfactory (Activemqconnection.default_user, Activemqconnection.default_password, "
tcp://10.0.0.109:61616 ");
Connection Connection = Factory.createconnection ();
Connection.start ();
Session session = Connection.createsession (Boolean.true, Session.auto_acknowledge);
Destination Destination = Session.createqueue ("Testqueue");
Messageconsumer consumer = session.createconsumer (destination); ObjectMessage message =(objectmessage) consumer.receive ();
if (message!= null) {String messagestring = (string) message.getobject ();
System.out.println ("Receive:" + messagestring); }
}
}
See console print out: Receive:hello world ..., know to receive the message, the inside flow face ah ah ah ah ...
> Close
Query process ID (PID) to prevent its process:
Ps-ef | grep activemq
kill-9 pid
Run sender again, she can't connect, hahaha haha
Exception in thread "main" javax.jms.JMSException:Could don't connect to broker url:tcp://10.0.0.109:61616. Reason:java.net.ConnectException:Connection Refused:connect
Well, the basic set-up is over.
> Thorns
In the process, there is a small problem, is that I started with JDK1.6 to run, reported the common unsupported Major.minor version 51.0
For this issue, this post has a very good reference meaning:
Http://www.cnblogs.com/chinafine/articles/1935748.html
Find a class in the jar and execute the following command to find out minor version, major version:
Javap-verbose YourClassName
Or view the meta-inf\manifest in the jar directly. Mf.
Then compare the JDK version in the post and replace it with JDK1.7 OK.