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)