In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you about how to deploy and use the message queue RabbitMQ. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
What is message queuing
When the message queue is taken apart, it is the message + queue. What is the message? In fact, it is the data used for communication between programs, messages are generated from producers, and after entering the queue, the designed rules are installed out of the queue and consumed by consumers. That's all.
Why message queuing is needed
Message queue, the most important is the queue, you can imagine the scene without the queue, when you go to the bank to do business, everyone does not queue up, everyone is piled together, small and powerless can not do business at all.
If there is no message queue, your system will be heavily coupled and will affect the whole body during the upgrade and maintenance.
If there is no message queue, many functions of your system are synchronized. Synchronization means that subsequent operations can only be carried out after the previous events are completed, and the front-end users will feel stuttered and have a poor experience.
If there is no message queue, the web system suddenly faces highly concurrent access requests and may crash.
With message queuing, system decoupling, asynchronous communication, traffic peaking, delay notification, final consistency guarantee, sequential messages, streaming and other requirements can be easily solved.
Common message queues
The most common message queuing products are ActiveMQ, RabbitMQ, ZeroMQ, Kafka, RocketMQ and so on.
ActiveMQ
Apache ActiveMQ is an open source message middleware developed by the Apache Software Foundation. Because ActiveMQ is a pure Java program, ActiveMQ can be executed only if the operating system supports the Java virtual machine.
Support for Java message Service (JMS) version 1.1
Spring Framework
Cluster (Clustering)
Protocol support includes: OpenWire, REST, STOMP, WS-Notification, MQTT, XMPP and AMQP
RabbitMQ
RabbitMQ implements the open source message broker software (also known as message-oriented middleware) of the Advanced message queuing Protocol (AMQP). The RabbitMQ server is written in the Erlang language that is known for its high performance, robustness, and scalability and supports all major operating systems such as Linux,Windows,MacOS. The client supports all major programming languages.
Scalability: cluster service
Message persistence: persist messages from memory to the hard disk, and then load from the hard disk to memory
ZeroMQ
ZeroMQ (also spelled 0MQ or ZMQ) is a high-performance asynchronous message library designed for scalable distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, ZeroMQ does not require a dedicated message broker (message broker) to run. The library is designed to be a common socket-style API.
ZeroMQ is jointly developed by iMatix and a community of contributors. ZeroQ supports most popular programming languages through many third-party software, from Java and Python to Erlang and Haskell.
Kafka
Kafka is an open source stream processing platform developed by the Apache Software Foundation and written by Scala and Java. The goal of the project is to provide a unified, high throughput and low latency platform for processing real-time data. Its persistence layer is essentially a "large-scale publish / subscribe message queue according to the distributed transaction log architecture", which makes it valuable as an enterprise infrastructure to handle streaming data. In addition, Kafka can connect to external systems (for data input / output) through Kafka Connect and provides a streaming library for Kafka Streams. The design is greatly affected by the transaction log.
RocketMQ
RocketMQ is a distributed messaging and streaming data platform with low latency, high performance, high reliability, trillions of capacity and flexible scalability. RocketMQ is the third generation of distributed messaging middleware opened by Alibaba in 2012. on November 21, 2016, Alibaba donated RocketMQ; to the Apache Software Foundation. On February 20 of the second year, the Apache Software Foundation announced that Apache RocketMQ became a top-level project.
The selection of message queues depends on the specific application needs. ZeroMQ is small and beautiful, RabbitMQ is large and stable, Kakfa and RocketMQ are fast and strong.
Deployment and use of RabbitMQ
Docker deployment is recommended. In the environment where Docker is installed, execute:
Docker run-d-- hostname my-rabbit-p 15672 RABBITMQ_DEFAULT_USER=user-p 15672-p 5672 RABBITMQ_DEFAULT_USER=user-e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management
Now open localhost:15672 in your browser. User name is user and password is password
Next, let's create a queue named my_app
Create an Exchange named my_exchange
Click the Exchange tab, click my_exchange to enter the details page, bind my_exchange and my_app, and set the routing key to test:
Python author producer
You can now write a producer using Python to produce a message to put into the queue and observe the changes in the Web page:
Import pikaconnection = pika.BlockingConnection (pika.ConnectionParameters ('localhost', 5672,' /', pika.PlainCredentials ('user',' password') channel = connection.channel () channel.basic_publish (exchange='my_exchange', routing_key='test', bodybuilding testings') connection.close ()
Execute the above code to put the message in the queue. Here I have executed it four times and you can see that there are four messages:
The message will remain in the queue until the consumer takes it out, and then we write a program that consumes the message.
Python Writing Consumer import pikaconnection = pika.BlockingConnection (pika.ConnectionParameters ('localhost', 5672,' /', pika.PlainCredentials ("user", "password")) channel = connection.channel () def callback (ch, method, properties, body): print (f'{body} is received') channel.basic_consume (queue= "my_app", on_message_callback=callback, auto_ack=True) channel.start_consuming ()
Execute:
At this point, the queue is empty:
This code demonstrates at a minimum how to publish a message to RabbitMQ
The above is what the editor shares with you on how to deploy and use message queuing RabbitMQ. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.