In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you a simple introduction and use of ActiveMQ. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
What is message middleware
As the name implies, message middleware is implemented to transfer messages between two systems or two clients.
What is ActiveMQ
ActiveMQ is an open source implementation of message middleware based on JMS (Java Message Servie) specification. The design goal of ActiveMQ is to provide standard, message-oriented, and integrated message communication middleware across multi-language and multi-system applications.
When do you need to use ActiveMQ
ActiveMQ is often used to decouple the application from the system business, push asynchronous messages, increase system concurrency and improve user experience. For example, in my use at work, when it is a time-consuming and asynchronous remote unlocking operation
How to use ActiveMQ
Data transfer flow of 1.AcitveMQ
Two message passing types of 2.ActiveMQ
(1) Point-to-point transmission, that is, a producer corresponds to a consumer, the producer pushes data to the broke, and the data is stored in a queue in broke, when the consumer accepts the data in the queue.
(2) Transmission based on publish / subscribe mode, that is, to receive corresponding data according to subscription topics, a producer can push data to multiple consumers, which is similar to the implementation of MQTT protocol, and those interested in MQTT protocol can jump to https://www.cnblogs.com/xiguadadage/p/11216463.html.
Due to the difference between the two types of message delivery, point-to-point transport consumers can receive the data pushed by the producer before the connection, while consumers based on publish / subscribe mode can only receive the data pushed by the producer after the connection.
Installation and startup of 3.ActiveMQ
(1) download the corresponding server version on the official website
(2) enter the apache-activemq-5.15.9/bin directory after decompression
(3) execute. / activemq start to start ActiveMQ
(4) enter the server ip:8161 started by ActiveMQ in the browser to enter the web interface. Click Manage ActiveMQ broker to view the status of message push. The default account password is admin,admin.
(5) start error analysis
Go to the / root/apache-activemq-5.15.9/data directory to view the activemq.log file and modify it according to the error message, such as the port number is occupied, etc.
Code testing of 4.ActiveMQ
(1) build a maven project and introduce dependencies
Org.apache.activemq activemq-all 5.9.0
(2) producer category
/ * * @ Description producer * @ Date 2019-7-20 * @ Created by yqh * / public class MyProducer {private static final String ACTIVEMQ_URL = "tcp://192.168.168.242:61616"; public static void main (String [] args) throws JMSException {/ / create connection factory ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory (ACTIVEMQ_URL); / / create connection Connection connection = activeMQConnectionFactory.createConnection () / / Open the connection connection.start (); / / create a session Session session = connection.createSession (false, Session.AUTO_ACKNOWLEDGE); / / create a queue target and identify the queue name, and consumers receive data Destination destination = session.createQueue ("myQueue") based on the queue name; / / create a producer MessageProducer producer = session.createProducer (destination) / / push 10 text message data for (int I = 1; I) to the queue
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.