I. Overview and INTRODUCTION
ActiveMQ is an open source server for Apache, the most popular, powerful instant messaging and integration model. ActiveMQ is a JMS provider implementation that fully supports the JMS1.1 and the Java EE 1.4 specification. Provides client support across languages and protocols, with easy to use in full support for JMS 1.1 and 1.4 using the Java EE Enterprise Integration model and many advanced features.
second, the characteristics
1, multiple languages and protocols to write the client. Languages: Java, C, C + +, C #, Ruby, Perl, Python, PHP. Application protocol: Openwire, Stomp REST, WS Notification, XMPP, AMQP
2, fully support JMS1.1 and the Java EE 1.4 specification (persistent, XA messages, transactions)
3, spring support, ACTIVEMQ can easily be embedded in the use of spring system, but also support the characteristics of Spring2.0
4, through the common Java EE server (such as Geronimo, JBoss 4, GlassFish, WebLogic) test, which through the JCA 1.5 resource adaptors configuration, Allows ACTIVEMQ to automatically deploy to any compatible Java 1.4 Business Server
5. Support multiple transfer protocols: IN-VM, TCP, SSL, NIO, UDP, JGroups, JXTA
6, support to provide high-speed message persistence through JDBC and journal
7, from the design to ensure the high-performance cluster, client-server, peer-to-peer
8. Support Ajax
9. Support for integration with axis
10, it is easy to call the embedded JMS provider, test
Third, installation
Development environment:
System:windows
jdk:1.6+
Ide:eclipse
Apache ActiveMQ 5.8
Email:hoojo_@126.com
Blog:http://blog.csdn.net/ibm_hoojo
http://hoojo.cnblogs.com/
1, download activemq, download address: Http://www.apache.org/dyn/closer.cgi?path=/activemq/apache-activemq/5.8.0/apache-activemq-5.8.0-bin.zip
2, decompression Apache-activemq-5.8.0.zip can complete the installation of ACTIVEMQ
3. After extracting the directory structure as follows
+bin (under Windows Bat and Unix/linux below SH) Start the ACTIVEMQ start-up service right here.
+conf (ACTIVEMQ configuration directory, containing the most basic ACTIVEMQ configuration files)
+data (default is empty)
+docs (no documents in Index,replease version)
+example (several examples)
+lib (Lib used by Activemq)
+webapps (System Administrator console code)
+webapps-demo (System sample Code)
-activemq-all-5.8.0.jar (binary of ACTIVEMQ)
-user-guide.html (Deployment Guidelines)
-license.txt
-notice.txt
-readme.txt
Other documents do not believe that the introduction of the Java should know what to do with.
You can go to the bin directory, use Activemq.bat double-click to Start (Windows users can choose the number of system bits, if you are Linux, you use the command line to send to start), if all goes well, you will see a message similar to the following:
If you see this, then congratulations on your success. If you start to see the exception information:
caused by:java.io.IOException:Failed to bind to server socket:tcp://0.0.0.0:61616?maximumconnections=1000& wireformat.maxframesize=104857600 due to:java.net.SocketException:Unrecognized Windows Sockets error:0: Jvm_bind |
Then I tell you, unfortunately, your port is occupied. Next you probably want to know which program is taking up your port and kill the process or service. Or you are trying to modify the default port of Activemq 61616 (the default port used by ACTIVEMQ is 61616), and in most cases 61616 ports are Internet Connection sharing (ICS), the Windows service , you can start activemq by just stopping it.
4, start successfully can access the Administrator interface: http://localhost:8161/admin, the default user name and password admin/admin. If you want to change your username and password, you can change it in conf/jetty-realm.properties.
In the navigation menu, queues is the queue mode message. Topics is a topic-mode message. Subscribers message Subscription monitoring query. Connections can view the number of links, respectively, to see XMPP, SSL, Stomp, Openwire, WS, and network links. Network is the number of Internet link monitoring. Send sends the message data.
5. Run Demo sample, enter Activemq.bat Xbean in DOS console: /conf/activemq-demo.xml can start the demo sample. The official user-guide.html access in the Web console is prompt for input: Activemq.bat console xbean:conf/activemq-demo.xml, which I did not succeed in this way.
Of course you can also use absolute file directory mode: Activemq.bat xbean:file:d:/mq/conf/activemq-demo.xml
If the hint conf/activemq-demo.xml not found, you can try to change the next path, that is, remove the ".." Above. The sample can be accessed through http://localhost:8161/demo/.
Iv. Examples of messages
1, the ACTIVITEMQ message has 3 forms
JMS Public |
Point-to-point fields |
Publish/Subscribe domain |
ConnectionFactory |
Queueconnectionfactory |
Topicconnectionfactory |
Connection |
Queueconnection |
Topicconnection |
Destination |
Queue |
Topic |
Session |
Queuesession |
Topicsession |
MessageProducer |
Queuesender |
Topicpublisher |
Messageconsumer |
QueueReceiver |
TopicSubscriber |
(1), point-to-point mode (point-to-point)
The point-to-point message is sent mainly on the message queue,sender,reciever, the messages Queue stores the information, the Sneder sends the message, and the receive receives the message. The point is sender. The client sends a message queue, and receiver Cliernt receives messages from the queue and "sends messages accepted" to Quere, confirming that the message is received. The message sending client has no time dependency on the receiving client, and the sending client can send information to the queue at any time without needing to know whether the receiving client is running
(2), Publish/Subscribe method (Publish/subscriber Messaging)
How the Publish/subscribe method is used for multi-receive clients. As a way to publish a subscription, there may be multiple receive clients, and there is a time-dependent dependency on the receiving client and the sending client. A receiving end can only receive information that he sends after the client is created. As a subscriber, there are two ways to receive messages, the destination receive method, and the OnMessage method that implements the message listener interface.
2, ACTIVITEMQ receive and send message basic flow
basic steps to send a message:
(1), create a connection using the factory class JMS ConnectionFactory
(2), use the Management object JMS ConnectionFactory to establish the connection connection, and start
(3), using Connection connection to establish session sessions
(4), using session sessions and managing objects destination Create message producer Messagesender
(5), send message using message producer Messagesender
to receive messages from a message receiver from JMS
(1), create a connection using the factory class JMS ConnectionFactory
(2), use the Management object JMS ConnectionFactory to establish the connection connection, and start
(3), using Connection connection to establish session sessions
(4), using session sessions and managing objects destination Create message Recipients Messagereceiver
(5), using the message recipient Messagereceiver to accept the message, The MessageListener interface needs to be bound to the Messagereceiver message receiver with Setmessagelistener the MessageListener interface must be implemented, and the OnMessage event method needs to be defined.
Five, code example
At the beginning of the code, we'll build a project to add the following jar package to this project
After you add the jar package, you can begin the actual code work.
1. Send receive Message using JMS mode
Message sender
Package COM.HOO.MQ.JMS;
Import javax.jms.Connection;
Import Javax.jms.ConnectionFactory;
Import Javax.jms.DeliveryMode;
Import javax.jms.Destination;
Import Javax.jms.MessageProducer;
Import javax.jms.Session;
Import Javax.jms.TextMessage;
Import org.apache.activemq.ActiveMQConnection;
Import Org.apache.activemq.ActiveMQConnectionFactory;
/**
* <b>function:</b> Message Sender
* @author Hoojo
* @createDate 2013-6-19 11:26:43
* @file Messagesender.java
* @package COM.HOO.MQ.JMS
* @project ActiveMQ-5.8
* @blog Http://blog.csdn.net/IBM_hoojo
* @email hoojo_@126.com
* @version 1.0
*/
public class Messagesender {
Number of sends
public static final int send_num = 5;
TCP Address
public static final String Broker_url = "tcp://localhost:61616";
Target, create http://localhost:8161/admin/queues.jsp in the ACTIVEMQ Administrator console
public static final String DESTINATION = "Hoo.mq.queue";