ActiveMQ deployment and send Receive Message

Source: Internet
Author: User

This article turns from: http://blog.csdn.net/leadergg/article/details/8771218


Directory (?) [+]

ActiveMQ deploy and send Receive message one, download

Download Address: http://activemq.apache.org/The version I use here is the current latest 5.8.0.

The download version has Windows and Linux two versions and is divided into 32-bit and 64-bit. Choose to download according to your needs. second, the installation

I download here for the 32-bit version of Windows (Apache-activemq-5.8.0-bin.zip), download directly to the directory to be installed or in the direct decompression to the current directory can also be completed after the installation of the decompression.

After extracting the directory as shown above, it contains the samples and documentation, and all the jar packages.

third, the Operation

Go to the Bin directory (apache-activemq-5.8.0\bin), double-click Activemq.bat, will run, run the screenshot as follows:


This means that ACTIVEMQ is already running, of course, the normal production environment can be set to run as a service in the background, and started with the system started. Four, test

ACTIVEMQ has a set of management system, access to http://localhost:8161/admin/, will appear need to enter a username and Password page as follows:


The default username and password are admin and enter the main interface:


In this interface, we can manage the queue and some of its features, and for the following to continue, we create a queue and a topic here.


Click the queues on the directory to enter the Create Queue page, enter the queue name, click Create the following creates the G2queue queue.


This can also not be created manually, at the sender specified a queue or topic name, will automatically create a queues, such as the above Choice.queue and firstqueue are all I test the program, the program specified in the queue name, automatically created.

The same way to create a topic, as follows:


v. Send a message

To create a new project, I am here to create the WebProject name called ACTIVEMQ, introducing the ACTIVEMQ jar package, the entire engineering structure as follows:


This code is directly copy from the Internet, just slightly modified:

[Java]  View plain copy import java.util.random;       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.session;   import  javax.jms.textmessage;       import org.apache.activemq.activemqconnectionfactory;        public class sendmessage {        private static final string url =  "tcp://localhost:61616";        private static final String QUEUE_NAME =  "G2queue";            public void sendmessage ()  throwsjmsexception  {          // jms  client to jmsprovider  connection            Connection connection = null;           try {              //  Connect factory,jms  Use it to create connections               //  Constructs the ConnectionFactory instance object, here uses the ACTIVEMQ realization jar               connectionfactory connectionfactory = newactivemqconnectionfactory (URL);               connection =  (Connection) Connectionfactory.createconnection ();               //  Start Connection                Connection.start ();   &NBSp;          //session: Threads that send or receive messages                //  Get session               Session session =  (session)   Connection.createsession (false,                      session.auto_acknowledge);               //  destination of messages, messages sent to that queue                destination destination = session.createqueue (QUEUE_NAME);               //messageproducer: Message sender (producer)                //  Create message sender                 messageproducer producer =session.createproducer (destination);               //  settings are persisted                //deliverymode.non_persistent: Non-persistent                //deliverymode.persistent: Persistence                producer.setdeliverymode (DeliveryMode.PERSISTENT);                

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.