ACTIVEMQ stand-alone installation and use

Source: Internet
Author: User
Tags message queue trim apache camel

ACTIVEMQ Single-use installation 1 Overview

ACTIVEMQ is an open-source, JMS1.1-compliant, message-oriented (MOM) middleware that provides efficient, scalable, stable, and secure enterprise-class messaging for applications. ACTIVEMQ uses the authorization provided by Apache, and anyone can modify its implementation code.

ACTIVEMQ's design goal is to provide standard, message-oriented, integrated messaging middleware across multiple language and multi-system applications. ACTIVEMQ implements the JMS standard and provides a number of additional features. These additional features include JMX management (Java Management Extensions, Java Management Extensions), master-Slave management (Master/salve, which is one of the cluster patterns, mainly in terms of reliability, when the primary intermediary (agent) fails, Then the agent replaces the primary proxy's location, does not cause the message system to be paralyzed, the message group communicates (the same set of messages is submitted only to one customer for processing), and the ordered message management (ensures that the message is received by the recipient in the order in which it was sent). Message priority (high priority messages are first delivered and processed), deferred subscription messages are received (when a subscription message is published, if the Subscriber does not open the connection, the message mediation submits the previous, unhandled message to the Subscriber when the connection is opened), the receiver is processed too slowly (can use dynamic load balancing, The majority of messages are submitted to the fast-processing receivers, mainly the PTP messages, the virtual receivers (reducing the number of connections to the mediation), the mature message persistence technology (some messages need to be persisted to the database or file system, the information is not lost when the mediation crashes), cursor operations are supported (can handle large messages), Support for message conversion, using Apache Camel can support EIP, using the form of mirror queue to easily monitor the message queue.

< /c13>2 Custom Installation 2.1 Download Address

Download website:
Http://activemq.apache.org/download-archives.html

2.2 Installation Steps

The installation steps are as follows:

1, decompression;

$ TAR-ZXVF apache-activemq-5.9.0-bin.tar.gz

2. Start:

Execute/bin directory under ACTIVEMQ

$ cd/bin

$./activemq Start &

Start MQ in the Run Bin directory

Note: If it is under Windows, direct decompression after running the bin directory Activemq.bat can

3. View the log after startup:

The previous log indicates a successful start.

Visit the ACTIVEMQ Web address and log in:

http://192.168.xxx.xxx:8161/

User/password can view/conf/jetty-realm.properties

3 Description of the configuration file

Enter into the Activemq_install_dir/config directory, there are several important documents

(1) Activemq.xml, in this file you can configure ACTIVEMQ a lot of things, such as persisting the message to the database and so on.
(2) credentials.properties, some passwords, more for the production and consumption of password authentication.
(3) The JETTY.XML,ACTIVEMQ has a built-in jetty application server.
(4) JETTY-REALM.PROPERTIES,ACTIVEMQ console login password.
 

4 Test Verification 4.1 Java Client Connections

Using ACTIVEMQ in a Java project

Importing the packages required for ACTIVEMQ in Java Engineering

The following packages are required:

Activemq-core.jar
Activeio-core.jar
Kahadb.jar (ifyou wish to use persistence if this jar package is needed for persistence)
Slf4j-api.jar
ee Jars
geronimo-spec-jms.jar
Geronimo-spec-jta.jar
Geronimo-spec-j2ee-management.jar


You can also use the default Activemq-all.jar to download the address:

Http://mvnrepository.com/artifact/org.apache.activemq/activemq-all

4.2 Producer Testing

public class Producer {private static final String Broker_url = "tcp://localhost:61616";
    private static final Boolean non_transacted = false;
    private static final int num_messages_to_send = 100;
 
    Private static final long DELAY = 100;
        public static void Main (string[] args) {String url = broker_url;
        if (Args.length > 0) {url = Args[0].trim ();
        } activemqconnectionfactoryconnectionfactory = new Activemqconnectionfactory ("admin", "admin", url);
 
        Connection Connection = null;
            try {connection = connectionfactory.createconnection ();
 
            Connection.start ();
            Session session =connection.createsession (non_transacted, Session.auto_acknowledge);
            Destination Destination =session.createqueue ("Test-queue");
 
            MessageProducer producer =session.createproducer (destination); for (int i = 0; i < num_messages_to_send; i++) {TExtmessage message =session.createtextmessage ("message#" + i);
                SYSTEM.OUT.PRINTLN ("Sending message #" + i);
                Producer.send (message);
            Thread.Sleep (DELAY);
            } producer.close ();
 
        Session.close ();
        } catch (Exception e) {System.out.println ("caught exception!");
                } finally {if (connection! = null) {try {connection.close (); 
                } catch (JMSException e) {System.out.println ("Could not close an open connection ..."); }
            }
        }
    }
}


4.3 consumer testing

public class Consumer {private static final String Broker_url = "tcp://localhost:61616";
    private static final Boolean non_transacted = false;
 
    Private static final long TIMEOUT = 20000;
        public static void Main (string[] args) {String url = broker_url;
        if (Args.length > 0) {url = Args[0].trim ();
        } System.out.println ("\nwaiting to receive messages ... would timeout after" + timeout/1000 + "s");
        Activemqconnectionfactoryconnectionfactory = new Activemqconnectionfactory ("admin", "admin", url);
 
        Connection Connection = null;
            try {connection =connectionfactory.createconnection ();
 
            Connection.start ();
            Session session =connection.createsession (non_transacted, Session.auto_acknowledge);
            Destination Destination =session.createqueue ("Test-queue");
 
            Messageconsumer consumer =session.createconsumer (destination);
      int i = 0;      while (true) {message message =consumer.receive (TIMEOUT); if (message = null) {if (message instanceof textmessage) {String Text = (Te
                        xtmessage) message). GetText (); System.out.println ("Got" + i++ + ".
                    Message: "+ text");
                }} else {break;
            }} consumer.close ();
 
        Session.close ();
        } catch (Exception e) {System.out.println ("caught exception!");
                } finally {if (connection! = null) {try {connection.close (); 
                } catch (JMSException e) {System.out.println ("Could not close an open connection ..."); }
            }
        }
    }
}



4.4 Data View

To log into the MQ View interface:

http://192.168.xxx.xxx:8161/


View ACTIVEMQ =>localhost=queue After login to view data sent by the producer

The following figure:


When the consumer finishes, the queue data is empty when viewing the interface;

The following figure:


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.