What is the practical application of ActiveMQ API in springboot JMS

Jin Tian Jiu Gen Da Jia Liao Liao You Guan SpringBoot JMS API De Shi Jian Ying Yong Shi Zen Yang De , Ke Neng Hen Duo Ren Du Bu Tai Liao Jie , Wei Liao Rang Da Jia Geng Jia Liao Jie , Xiao Bian Gei Da Jia Zong Jie Liao Yi Xia Nei Rong , Xi Wang Da Jia Gen Ju Zhe Pian Wen Zhang Ke Yi You Suo Shou Huo 。

  Qian Yan

Active Shi Yi Zhong Kai Yuan De , Shi Xian Liao JMS1.1 Gui Fan De , Mian Xiang Xiao Xi (MOM) De Zhong Jian Jian , Wei Ying Yong Cheng Xu Ti Gong Gao Xiao De 、 Ke Kuo Zhan De 、 Wen Ding De He An Quan De Qi Ye Ji Xiao Xi Tong Xin 。AC-tiveMQ Shi Yong Apache Ti Gong De Shou Quan , Ren He Ren Du Ke Yi Dui Qi Shi Xian Dai Ma Jin Xing Xiu Gai 。

ActiveMQ De She Ji Mu Biao Shi Ti Gong Biao Zhun De , Mian Xiang Xiao Xi De , Neng Gou Kua Yue Duo Yu Yan He Duo Xi Tong De Ying Yong Ji Cheng Xiao Xi Tong Xin Zhong Jian Jian 。ActiveMQ Shi Xian Liao JMS Biao Zhun Bing Ti Gong Liao Hen Duo Fu Jia De Te Xing 。

1. JMS De Gai Nian ?

「 Shi Me Shi JMS Ne :」

  • JMS———JAVA Message Service

  • JAVA De Xiao Xi Fu Wu , Shi sun Gong Si Ti Gong De Jie Kou , Zhi Shi Yi Ge Gui Fan , Zhe Ge Gui Fan Jiu Lei Si Yu JDBC Shi Yi Yang De , Shi Yong De Shi Hou Shi Xu Yao Dang Qian Gui Fan De Shi Xian Chan Pin De 。

「JMS Neng Gan Shi Me Ne :」

  • Neng Gou Jiang Xin Xi Fa Bu Dao Mu De Di

  • Ke Yi Cong Mu De Di Lai Xiao Fei Zhe Ge Xiao Xi

2、 Liang Zhong Tong Xin Mo Xing

「 Dui Lie De Tong Xin Gai Nian :」

  • Te Dian : Dang Wo Men Tong Yi Ge Dui Lie You Duo Ge Xiao Fei Zhe De Shi Hou , Duo Ge Xiao Fei Zhe De Shu Ju Zhi He Cai Shi Yuan Lai Dui Lie Zhong De Suo You Shu Ju

  • Dui Lie De Tong Xin Mo Xing Zui Da De Shi Yong Chang Jing : Liu Liang De Xiao Feng , Gao Bing Fa De Chu Li

「 Zhu Ti De Tong Xin Mo Xing :」

  • Te Dian : Dang Wo Men Dui Lie You Duo Ge Xiao Fei Zhe De Shi Hou , Na Me Zhe Duo Ge Xiao Fei Zhe Xiao Fei Dao De Shu Ju Shi Yi Yang De

  • Zhu Ti Xiao Fei Zhe Tong Xin Mo Xing De Shi Yong Chang Jing : Wei Fu Wu Xia Fu Wu Zhi Jian De Yi Bu Tong Xin

3. MQ De Shi Xian Chan Pin

「 Shi Xian Chan Pin :」

  • ActiveMQ

  • RabbitMQ

  • RockerMQ

  • Kafka( Zhe Ge She Ji De Chu Zhong Shi Zuo Fen Bu Shi De Ri Zhi De , Hou Lai Yin Wei Ri Zhi You Yan Ge De Shun Xu Wen Ti , Zhe Ge Shi Hou Ren Men Jiu Yong Kafka Lai Zuo Xiao Xi Dui Lie Liao )

4、JMS Zhong Chang Jian De Ming Ci

「 Chang Jian De Ming Ci :」

  • ActiveMQConnectionFactory: Zhe Ge Shi Chuang Jian Lian Jie De Gong Chang

  • ConnectionFactory: Lian Jie De Gong Chang

  • Connection: Lian Jie JAVA Dui MQ De Yi Ge Lian Jie

  • Destination: Mu De Di

  • Sheng Chan Zhe (Producer)

  • Xiao Fei Zhe (Consumer)

  • Session: Hui Hua ( Mei Yi Ci Dui MQ De Cao Zuo Du Cheng Wei Yi Ci Hui Hua )

  • Queue: Dui Lie

  • Topic: Zhu Ti

5、 Shi Me Shi Xiao Xi Dui Lie

「 Xiao Xi Dui Lie Jian Dan De Shuo Jiu Shi Yong Lai Cun Fang Lin Shi Shu Ju De Di Fang :」

  • Sheng Chan Zhe ———–> Cun Chu Jie Zhi Shang

  • Xiao Fei Zhe ———–> Cun Chu Jie Zhi Shang

「 Xiao Xi Dui Lie Lei Si Yu Kuai Di Gong Si :」

  • Ni Ke Yi Jiang Dong Xi Jiao Gei Kuai Di Gong Si

  • Mu Biao Ren Ye Ke Yi Cong Kuai Di Gong Si Qu Qu Dong Xi

6. ActiveMQ Shi Shi Me

「 Han Yi :」

  • ActiveMQ Jiu Shi Yi Ge JMS De Shi Xian Chan Pin , Ta Neng Gou Shi Xian JMS Xia De Suo You Gong Neng

7、ActiveMQ Neng Gan Shi Me

「 Zhu Yao Zuo Yong :」

  • Liu Liang Xiao Feng Chu Li

  • Wei Fu Wu Xia Mo Kuai De Yi Bu Tong Xin

  • Chu Li Gao Bing Fa Xia De Ding Dan

  • Chu Li Di San Fang Ping Tai De Gao Bing Fa

  • Xie Zhu Xiao Xi Biao Ke Yi Wan Cheng Fen Bu Shi Shi Wu De Zui Zhong Yi Zhi Xing

8、ActiveMQ De An Zhuang

「ActiveMQ De An Zhuang He Pei Zhi :」

 1、 Guan  Wang  Xia  Zai Linux Ban  De ActiveMQ( Zui  Xin  Ban  Ben  Wei 5.13.4)        https://activemq.apache.org/download.html         2、 Jie  Ya  An  Zhuang        tar -zxvf apache-activemq-5.13.4-bin.tar.gz         3、 Pei  Zhi ( Zhe  Li  Cai  Yong  Mo  Ren  Pei  Zhi , Wu  Xu  Xiu  Gai )       vim /usr/lical/activemq-1/conf/activemq.xml         4、 Qi  Dong        cd /usr/local/activemq-1/bin ./activemq start        5、 Da  Kai  Guan  Li  Jie  Mian ( Guan  Li  Jie  Mian  Ke  Yi  Cha  Kan  Bing  Guan  Li  Suo  You  Dui  Lie  Ji  Xiao  Xi )          http://192.168.1.100:8161          Qi  Dong  Cheng  Gong  Hou , Ke  Yi  Zuo  Lan  http://localhost:8161/admin/         Mo  Ren  Yong  Hu  Ming 、 Mi  Ma :admin/admin         Guan  Li  Jie  Mian  Shi  Yong jetty Zuo  Rong  Qi  De , Ru  Guo  Xiang  Xiu  Gai  Guan  Li  Jie  Mian  De  Duan  Kou , Ke  Yi  Bian  Ji ../conf/jetty.xml, Zhao  Dao  Xia  Mian  Zhe  Yi  Duan :       <bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">     <!-- the default port       number for the web console -->     <property name="host" value="0.0.0.0"/>     <property name="port" value="8161"/>      </bean>         Yong  Hu  Ming / Mi  Ma  Shi  Zai  ../conf/jetty-realm.properties  Li , Bi  Ru  Yao  Zeng  Jia  Yi  Ge  Guan  Li  Yuan jimmy/123456, Ke  Can  Kao  Xia  Mian  Xiu  Gai :        1 2 3admin: admin, admin jimmy: 123456, admin user: user, user         Zhu : Guan  Li  Jie  Mian  You  Yi  Ge  Xiao  Keng ,ActiveMQ 5.13.2 Yu jdk1.8 Jian  Rong  Xing  You  Dian  Wen  Ti , Ru  Guo  Shi  Yong jdk1.8, Guan  Li  Jie  Mian  Jin  Ru Queues Biao  Qian  Ye  Shi , Ou  Er  Hui  Bao  Cuo , Dan  Shi  Bing  Bu  Ying  Xiang  Xiao  Xi  Zheng  Chang  Shou  Fa , Zhi  Shi  Wu  Fa  Cong  Jie  Mian  Shang  Cha  Kan  Dui  Lie  Qing  Kuang , Ru  Guo  Chu  Xian  Gai  Wen  Ti , Ke  Jiang jdk Ban  Ben  Jiang  Zhi 1.7, Tong  Shi  Zui  Hao  Qing  Kong data Mu  Lu  Xia  De  Suo  You  Shu  Ju , Zai  Zhong  Qi activemq Ji  Ke 。

9. ActiveMQ De API De Shi Yong

「AcatveMQ De API Shi Yong :」

  • Dui Lie De Shi Yong ( Sheng Chan Zhe )

package com.qy.mq.queue;  import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.Message;  import javax.jms.*;  /**  * @Auther: qianyu  * @Date: 2020/11/04 14:12  * @Description: Sheng  Chan  Zhe   */ public class Producer {      // Zhun  Bei  Fa  Bu  De  Zhe  Ge  Di  Zhi      private  static final String PATH="tcp://10.7.182.87:61616";     //ActiveMQ Xia  De  Yong  Hu  Ming      private static final String userName="admin";     //ActiveMQ Xia  De  Mi  Ma      private static final String password="admin";      public static void main(String[] args) throws JMSException {         // Di  Yi  Bu : Chuang  Jian  Lian  Jie  De  Gong  Chang          ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(userName, password, PATH);         // Tong  Guo  Zhe  Ge  Gong  Chang  Huo  Qu  Lian  Jie          Connection connection = activeMQConnectionFactory.createConnection();         // Di  San  Bu : Da  Kai  Zhe  Ge  Lian  Jie          connection.start();         // Di  Si  Bu : Chuang  Jian  Cao  Zuo MQ De  Zhe  Ge  Hui  Hua          /**          *  Di  Yi  Ge  Can  Shu : Shi  Fou  Shi  Yong  Shi  Wu           *  Di  Er  Ge  Can  Shu : Ke  Hu  Duan  De  Ying  Da  Mo  Shi           *      Di  Yi  Zhong : Zi  Dong  Ying  Da           *      Di  Er  Zhong : Ke  Hu  Duan  Shou  Dong  Ying  Da           */         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);         // Xu  Yao  Fa  Song  Xiao  Xi  De  Mu  De  Di (queue Cao  Zuo  De  Shi  Dui  Lie )         Destination destination=session.createQueue("wqqq");         // Sheng  Chan  Zhe  Lai  Sheng  Chan  Zhe  Ge  Xiao  Xi          // Yao  You  Sheng  Chan  Zhe          MessageProducer messageProducer = session.createProducer(destination);          // Fa  Song  Hen  Duo  De  Xiao  Xi  Dao  Xiao  Xi  Dui  Lie  Zhong  Qu  //        for (int i=0;i<100;i++){             // Xu  Yao  Zhun  Bei  Fa  Song  De  Xiao  Xi  //            TextMessage textMessage = session.createTextMessage(" Wo  Shi  Qian  Yu :"+i);             // Yan  Jiu  Xiao  Xi  De  Lei  Xing             /*  BytesMessage bytesMessage = session.createBytesMessage();             bytesMessage.setByteProperty("www",new Byte("123"));              // Jie  Xia  Lai  Jiu  Ke  Yi  Fa  Song  Xiao  Xi  Liao              messageProducer.send(bytesMessage);*/          // Chuang  Jian map Lei  Xing  De message         /*MapMessage mapMessage = session.createMapMessage();         mapMessage.setInt("www1",123);          messageProducer.send(mapMessage);*/          ObjectMessage objectMessage = session.createObjectMessage(new User(1, "qianyu", "123"));         messageProducer.send(objectMessage);  //        }     }  }
  • Dui Lie De Shi Yong ( Xiao Fei Zhe )

package com.qy.mq.queue;  import org.apache.activemq.ActiveMQConnectionFactory;  import javax.jms.*; import java.io.Serializable;  /**  * @Auther: qianyu  * @Date: 2020/11/04 14:13  * @Description: Xiao  Fei  Zhe   */ public class Consumer {      // Zhun  Bei  Fa  Bu  De  Zhe  Ge  Di  Zhi      private  static final String PATH="tcp://10.7.182.87:61616";     //ActiveMQ Xia  De  Yong  Hu  Ming      private static final String userName="admin";     //ActiveMQ Xia  De  Mi  Ma      private static final String password="admin";      public static void main(String[] args) throws JMSException {         // Di  Yi  Bu : Chuang  Jian  Lian  Jie  De  Gong  Chang          ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(userName, password, PATH);         // Tong  Guo  Zhe  Ge  Gong  Chang  Huo  Qu  Lian  Jie          Connection connection = activeMQConnectionFactory.createConnection();         // Di  San  Bu : Da  Kai  Zhe  Ge  Lian  Jie          connection.start();         // Di  Si  Bu : Chuang  Jian  Cao  Zuo MQ De  Zhe  Ge  Hui  Hua          /**          *  Di  Yi  Ge  Can  Shu : Shi  Fou  Shi  Yong  Shi  Wu           *  Di  Er  Ge  Can  Shu : Ke  Hu  Duan  De  Ying  Da  Mo  Shi           *      Di  Yi  Zhong : Zi  Dong  Ying  Da           *      Di  Er  Zhong : Ke  Hu  Duan  Shou  Dong  Ying  Da           */         Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);         // Xu  Yao  Fa  Song  Xiao  Xi  De  Mu  De  Di (queue Cao  Zuo  De  Shi  Dui  Lie )         Destination destination=session.createQueue("wqqq");         // Chuang  Jian  Wo  Men  De  Xiao  Fei  Zhe  Liao          MessageConsumer messageConsumer = session.createConsumer(destination);         // Jie  Xia  Lai  Jiu  Ke  Yi  Jie  Shou  Wo  Men  De  Xiao  Xi  Liao          //Message message = messageConsumer.receive();          // Jie  Shou  Xiao  Xi  Bing  Zhi  Ding  Zhe  Ge  Chao  Shi  De  Shi  Jian  //      Message message = messageConsumer.receive(5000);          // Jie  Shou  Xiao  Xi  Mei  You  Jiu  Bu  Deng  Dai  Liao   Zhi  Jie over Liao    Bu  Jie  Shou  Liao  //      Message message = messageConsumer.receiveNoWait();          // Gei  Ding  Dang  Qian  De  Lu  Jing  She  Zhi  Jian  Ting  Qi          messageConsumer.setMessageListener(new MessageListener() {             @Override             public void onMessage(Message message) {                 /* BytesMessage bytesMessage= (BytesMessage) message;                  try {                     System.out.println(" Huo  Qu  Dao  De  Shu  Ju  Shi :"+bytesMessage.getByteProperty("www"));                 } catch (JMSException e) {                     e.printStackTrace();                 }*/                  /*MapMessage mapMessage= (MapMessage) message;                  try {                     System.out.println(" Huo  Qu  Dao  De  Shu  Ju  Shi :"+mapMessage.getInt("www1"));                 } catch (JMSException e) {                     e.printStackTrace();                 }*/                 // Ce  Shi  Dui  Xiang  Lei  Xing  De  Xiao  Xi  De  Fa  Song  He  Jie  Shou                 ObjectMessage objectMessage= (ObjectMessage) message;                 try {                     User user = (User) objectMessage.getObject();                      System.out.println(" Jie  Shou  Dao  De  Shu  Ju  Shi :"+user);                 } catch (JMSException e) {                     e.printStackTrace();                 }                 /*  // Wo  Men  Zhi  Dao  Shi  Yi  Ge  Zi  Fu  Chuan  Lei  Xing  De  Xiao  Xi                  TextMessage textMessage= (TextMessage) message;                 // Jie  Xia  Lai  Jiu  Ke  Yi  Da  Yin  Zhe  Ge  Xiao  Xi  Liao                  try {                     System.out.println(" Xiao  Fei  Zhe 1--- Jie  Shou  Dao  De  Xiao  Xi  Shi :"+textMessage.getText());                 } catch (JMSException e) {                     e.printStackTrace();                 }*/                  try {                     // Zhe  Ju  Hua  Jiu  Biao  Shi  De  Shi  Ke  Hu  Duan  Lai  Shou  Dong  De  Jin  Xing  Ying  Da                      message.acknowledge();                 } catch (JMSException e) {                     e.printStackTrace();                 }              }         });     } }
  • Zhu Ti Mo Xing De Sheng Chan Zhe

package com.qy.mq.topic;  import org.apache.activemq.ActiveMQConnectionFactory;  import javax.jms.*;  /**  * @Auther: qianyu  * @Date: 2020/11/04 15:17  * @Description:  */ public class Producer {     // Zhun  Bei  Fa  Bu  De  Zhe  Ge  Di  Zhi      private  static final String PATH="tcp://10.7.182.87:61616";     //ActiveMQ Xia  De  Yong  Hu  Ming      private static final String userName="admin";     //ActiveMQ Xia  De  Mi  Ma      private static final String password="admin";      public static void main(String[] args) throws JMSException {         // Di  Yi  Bu : Chuang  Jian  Lian  Jie  De  Gong  Chang          ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(userName, password, PATH);         // Tong  Guo  Zhe  Ge  Gong  Chang  Huo  Qu  Lian  Jie          Connection connection = activeMQConnectionFactory.createConnection();         // Di  San  Bu : Da  Kai  Zhe  Ge  Lian  Jie          connection.start();         // Di  Si  Bu : Chuang  Jian  Cao  Zuo MQ De  Zhe  Ge  Hui  Hua          /**          *  Di  Yi  Ge  Can  Shu : Shi  Fou  Shi  Yong  Shi  Wu           *  Di  Er  Ge  Can  Shu : Ke  Hu  Duan  De  Ying  Da  Mo  Shi           *      Di  Yi  Zhong : Zi  Dong  Ying  Da           *      Di  Er  Zhong : Ke  Hu  Duan  Shou  Dong  Ying  Da           */         Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);         // Xu  Yao  Fa  Song  Xiao  Xi  De  Mu  De  Di ( Xia  Mian  Chuang  Jian  De  Jiu  Ying  Gai  Shi  Zhu  Ti  Mo  Xing  De  Di  Zhi )         Destination destination=session.createTopic("topic222");         // Sheng  Chan  Zhe  Lai  Sheng  Chan  Zhe  Ge  Xiao  Xi          // Yao  You  Sheng  Chan  Zhe          MessageProducer messageProducer = session.createProducer(destination);          // Fa  Song  Hen  Duo  De  Xiao  Xi  Dao  Xiao  Xi  Dui  Lie  Zhong  Qu          for (int i=0;i<100;i++){             // Xu  Yao  Zhun  Bei  Fa  Song  De  Xiao  Xi              TextMessage textMessage = session.createTextMessage(" Wo  Shi  Qian  Yu :"+i);             // Jie  Xia  Lai  Jiu  Ke  Yi  Fa  Song  Xiao  Xi  Liao              messageProducer.send(textMessage);         }     } }
  • Zhu Ti Mo Xing De Xiao Fei Zhe

package com.qy.mq.topic;  import org.apache.activemq.ActiveMQConnectionFactory;  import javax.jms.*;  /**  * @Auther: qianyu  * @Date: 2020/11/04 15:19  * @Description:  */ public class Consumer {      // Zhun  Bei  Fa  Bu  De  Zhe  Ge  Di  Zhi      private  static final String PATH="tcp://10.7.182.87:61616";     //ActiveMQ Xia  De  Yong  Hu  Ming      private static final String userName="admin";     //ActiveMQ Xia  De  Mi  Ma      private static final String password="admin";      public static void main(String[] args) throws JMSException {         // Di  Yi  Bu : Chuang  Jian  Lian  Jie  De  Gong  Chang          ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(userName, password, PATH);         // Tong  Guo  Zhe  Ge  Gong  Chang  Huo  Qu  Lian  Jie          Connection connection = activeMQConnectionFactory.createConnection();         // Di  San  Bu : Da  Kai  Zhe  Ge  Lian  Jie          connection.start();         // Di  Si  Bu : Chuang  Jian  Cao  Zuo MQ De  Zhe  Ge  Hui  Hua          /**          *  Di  Yi  Ge  Can  Shu : Shi  Fou  Shi  Yong  Shi  Wu           *  Di  Er  Ge  Can  Shu : Ke  Hu  Duan  De  Ying  Da  Mo  Shi           *      Di  Yi  Zhong : Zi  Dong  Ying  Da           *      Di  Er  Zhong : Ke  Hu  Duan  Shou  Dong  Ying  Da           */         Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);         // Xu  Yao  Fa  Song  Xiao  Xi  De  Mu  De  Di (queue Cao  Zuo  De  Shi  Dui  Lie )         Destination destination=session.createTopic("topic222");         // Chuang  Jian  Wo  Men  De  Xiao  Fei  Zhe  Liao          MessageConsumer messageConsumer = session.createConsumer(destination);         // Jie  Xia  Lai  Jiu  Ke  Yi  Jie  Shou  Wo  Men  De  Xiao  Xi  Liao           // Gei  Ding  Dang  Qian  De  Lu  Jing  She  Zhi  Jian  Ting  Qi          messageConsumer.setMessageListener(new MessageListener() {             @Override             public void onMessage(Message message) {                  // Wo  Men  Zhi  Dao  Shi  Yi  Ge  Zi  Fu  Chuan  Lei  Xing  De  Xiao  Xi                  TextMessage textMessage= (TextMessage) message;                 // Jie  Xia  Lai  Jiu  Ke  Yi  Da  Yin  Zhe  Ge  Xiao  Xi  Liao                  try {                     System.out.println(" Xiao  Fei  Zhe 1--- Jie  Shou  Dao  De  Xiao  Xi  Shi :"+textMessage.getText());                 } catch (JMSException e) {                     e.printStackTrace();                 }                  try {                     message.acknowledge();                 } catch (JMSException e) {                     e.printStackTrace();                 }              }         });     } }

Kan Wan Shang Shu Nei Rong , Ni Men Dui SpringBoot JMS API De Shi Jian Ying Yong Shi Zen Yang De You Jin Yi Bu De Liao Jie Ma ? Ru Guo Huan Xiang Liao Jie Geng Duo Zhi Shi Huo Zhe Xiang Guan Nei Rong , Qing Guan Zhu Tumi Yun Xing Ye Zi Xun Pin Dao , Gan Xie Da Jia De Zhi Chi 。

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment