In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about the practical application of SpringBoot JMS API, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Preface
Active is an open source, message-oriented middleware that implements the JMS1.1 specification and provides efficient, scalable, stable and secure enterprise message communication for applications. AC-tiveMQ uses the authorization provided by Apache, and anyone can modify its implementation code.
The design goal of ActiveMQ is to provide standard, message-oriented, integrated message communication middleware across multi-language and multi-system applications. ActiveMQ implements the JMS standard and provides many additional features.
1. The concept of JMS?
"what is JMS:"
JMS-JAVA Message Service
JAVA's message service, which is provided by sun, is just a specification, which is similar to JDBC and needs the implementation product of the current specification when used.
"what can JMS do:"
Be able to publish information to the destination
This message can be consumed from the destination.
2. Two communication models
"Communication concept of queues:"
Features: when we have multiple consumers in the same queue, the sum of the data of multiple consumers is all the data in the original queue.
The biggest applicable scenario of queue communication model: peak elimination of traffic, high concurrency processing.
"Communication model of the topic:"
Features: when there are multiple consumers in our queue, then the data consumed by multiple consumers is the same.
The applicable scenario of the subject consumer communication model: asynchronous communication between services under microservices
3. Implementation products of MQ
"realize the product:"
ActiveMQ
RabbitMQ
RockerMQ
Kafka (the original purpose of this design is to do distributed logs, but later, because of the strict order of logs, people use Kafka to do message queues.)
4. Common nouns in JMS
"Common nouns:"
ActiveMQConnectionFactory: this is the factory that creates the connection
ConnectionFactory: connected factory
Connection: a connection from JAVA to MQ
Destination: destination
Producer (Producer)
Consumer (Consumer)
Session: session (each operation on MQ is called a session)
Queue: queu
Topic: topic
5. What is a message queue
"message queues are simply places where temporary data is stored:"
Producer-> on storage media
Consumer-> on storage media
"message queues are similar to express companies:"
You can give it to the courier company.
The target person can also pick up things from the courier company.
6. What is ActiveMQ?
"meaning:"
ActiveMQ is an implementation product of JMS, which can realize all the functions under JMS.
7. What can ActiveMQ do
"main role:"
Flow peak elimination treatment
Asynchronous Communication of Module under Micro Service
Handle orders placed with high concurrency
Handle high concurrency on third-party platforms
The assistance message table can achieve the final consistency of distributed transactions.
8. Installation of ActiveMQ
"installation and configuration of ActiveMQ:"
1. Download the Linux version of ActiveMQ (the latest version is 5.13.4) https://activemq.apache.org/download.html 2, decompress and install tar-zxvf apache-activemq-5.13.4-bin.tar.gz 3, and configure (default configuration is adopted here. No need to modify) vim / usr/lical/activemq-1/conf/activemq.xml 4, start cd / usr/local/activemq-1/bin. / activemq start 5, open the management interface (the management interface can view and manage all queues and messages) after http://192.168.1.100:8161 starts successfully You can browse the default user name and password of http://localhost:8161/admin/: the admin/admin management interface uses jetty as a container. If you want to change the port of the management interface, you can edit.. / conf/jetty.xml and find the following paragraph: the user name / password is in.. / conf/jetty-realm.properties. For example, to add an administrator jimmy/123456, please refer to the following modifications: 12 3admin: admin, admin jimmy: 123456, admin user: user, user Note: there is a crater in the management interface, and there is a problem with ActiveMQ 5.13.2 compatibility with jdk1.8. If you use jdk1.8, the management interface will occasionally report an error when entering the Queues tab, but it does not affect the normal sending and receiving of messages, but cannot check the queue from the interface. If this problem occurs, you can reduce the jdk version to 1.7, and it is best to clear all the data in the data directory and restart activemq.
9. The use of API in ActiveMQ
"API for AcatveMQ uses:"
Use of queues (producers)
Package com.qy.mq.queue; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.Message; import javax.jms.*; / * * @ Auther: qianyu * @ Date: 14:12 * @ Description on 2020-11-04: producer * / public class Producer {/ / the address to be released is private static final String PATH= "tcp://10.7.182.87:61616" / / user name under ActiveMQ private static final String userName= "admin"; / / password under ActiveMQ private static final String password= "admin"; public static void main (String [] args) throws JMSException {/ / first step: create a connection factory ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory (userName, password, PATH); / / obtain a connection through this factory Connection connection = activeMQConnectionFactory.createConnection () / / step 3: open the connection connection.start () / / step 4: create this session to operate MQ / * first parameter: whether to use transaction * second parameter: client response mode * first: automatic answer * second: client manual reply * / Session session = connection.createSession (false Session.AUTO_ACKNOWLEDGE) / / the destination where the message needs to be sent (queue operates on the queue) Destination destination=session.createQueue ("wqqq"); / / producer to produce this message / / producer MessageProducer messageProducer = session.createProducer (destination); / / send a lot of messages to the message queue / / for (int iqueue)
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.