ACTIVEMQ's Hello (Java)

Source: Internet
Author: User

Message Queuing activemq, saving response time and resolving the problem of long third-party response time so that other customers can continue to access

Installing ACTIVEMQ

Apache-activemq-5.14.0-bin\apache-activemq-5.14.0\bin\win64\activemq.bat

Create a MAVEN Java project

Access path in the browser http://localhost:8161/login admin password for admin

1.pom.xml file

<dependencies>  <dependency>    <groupId>org.apache.activemq</groupId>    < Artifactid>activemq-all</artifactid>    <version>5.14.0</version></dependency>  </dependencies>  <build><plugins><plugin><groupId> Org.apache.maven.plugins</groupid><artifactid>maven-compiler-plugin</artifactid><version >2.3.2</version><configuration><source>1.7</source><target>1.7</target> </configuration></plugin></plugins></build>

  

Production tasks

public static void Main (string[] args) throws JMSException {//connection factory ConnectionFactory factory = new Activemqconnectionfacto Ry ();//Get a connection Connection connection = Factory.createconnection ();//Establish a session Sessions session = Connection.createsession ( True, Session.auto_acknowledge);//Create a Queued topic object Queue queue = Session.createqueue ("Hello"); MessageProducer producer = Session.createproducer (queue), for (int i = 0; i <; i++) {Producer.send (session.createtext Message ("ActiveMQ" +i)); Session.commit ();}

Produced 10 quests.

Consumption (processing business)

public static void Main (string[] args) throws Exception {//connection factory ConnectionFactory factory = new Activemqconnectionfactory ( );//Get a connection Connection connection = Factory.createconnection (); Connection.start ();//Set up sessions Session session = Connection.createsession (False, Session.auto_acknowledge);//Create a Queued topic object Queue queue = Session.createqueue ("Hello"); Messageconsumer producer = Session.createconsumer (queue); while (true) {//Receive message TextMessage receive = (textmessage) Producer.receive (); if (receive!=null) {System.out.println (Receive.gettext ());}}}

  

ACTIVEMQ's Hello (Java)

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.