RabbitMq installation tutorial (super detailed) and use

Table of contents

Installation Preparation Tool

Installation steps (graphic)

Use the Management HTTP API provided by RabbitMQ


Introduction to RabbitMq


Installation preparation tools
Installation steps (graphics)
Introduction to RabbitMq
1.1 Introduction to message queue middleware
Message queue middleware is an important component in a distributed system. It mainly solves problems such as application coupling, asynchronous messages, and traffic cutting to achieve high performance and high availability. Scalability and eventual consistency [architecture] ActiveMQ (safety), RabbitMQ, ZeroMQ, Kafka (big data), MetaMQ, and RocketMQ are commonly used
message queues. The following introduces the common usage scenarios of message queues in practical applications: asynchronous processing, Four scenarios of application decoupling, traffic cutting and message communication
1.2 What is RabbitMQ
RabbitMQ is an open source implementation of AMQP developed by Erlang language.
AMQP: Advanced Message Queue, Advanced Message Queuing Protocol. It is an open standard of the application layer protocol, designed for message-oriented middleware, and the client and message middleware based on this protocol can transfer messages without being restricted by conditions such as products and development languages.
RabbitMQ originally originated in the financial system and is used to store and forward messages in a distributed system. It performs well in terms of ease of use, scalability, and high availability. The specific features include:
1. Reliability (Reliability)
RabbitMQ uses some mechanisms to ensure reliability, such as persistence, transmission confirmation, and release confirmation. 2. Flexible Routing (Flexible Routing)
Before the message enters the queue, the message is routed through the Exchange. For typical routing functions, RabbitMQ already provides some built-in Exchange implementations. For more complex routing functions, multiple Exchanges can be bound together, and one's own Exchange can also be realized through the plug-in mechanism.
3. Message clustering (Clustering)
Multiple RabbitMQ servers can form a cluster to form a logical Broker
4. Highly Available Queues (Highly Available Queues)
queues can be mirrored on machines in the cluster, so that the queues are still available when some nodes fail.
5. Multi-protocol
RabbitMQ supports multiple message queuing protocols, such as STOMP, MQTT and so on.
6. Many Clients
RabbitMQ supports almost all common languages, such as Java, .NET, Ruby and so on.
7. Management UI (Management UI)
RabbitMQ provides an easy-to-use user interface that enables users to monitor and manage many aspects of the message broker.
8. Tracing mechanism (Tracing)
If the message is abnormal, RabbitMQ provides a message tracking mechanism, and the user can find out what happened.
9. Plug-in mechanism (Plugin System)
RabbitMQ provides many plug-ins to expand in many ways, and you can also write your own plug-ins.

Installation Preparation Tool


1. Download Eralng, the link below has provided otp_win64_20.2.exe
link: https://pan.baidu.com/s/1ha-OGMa9AGZFamELP_b48w.
Extraction code: 3gpa
2. Download rabbitmq, the link below has provided rabbitmq-server-3.7 .4.exe
link: https://pan.baidu.com/s/1kGMjBc_H1QWRPEs8dRYaHA .
Extraction code: vzar

Installation steps (graphic)


1. The first step:
install otp_win64_20.2.exe
right click to run as administrator

insert image description here

Then keep clicking on the next step for foolish installation
2. Step 2:
Install rabbitmq-server-3.7.4.exe
Double-click the file rabbitmq-server-3.7.4.exe, foolish installation, (be careful not to install in the directory! After installation, rabbitMQ exists in the window service, and it is in the startup state.)
Then install the management interface (plug-in)

Enter the sbin directory of the rabbitMQ installation directory,
click the path box above, enter cmd, and press the Enter keyinsert image description hereinsert image description here

insert image description here

3. Enter the command and click Enter

rabbitmq-plugins enable rabbitmq_management

insert image description here
Step 3:
1. Restart the service, double-click rabbitmq-server.bat (you may need to wait for a while after double-clicking)

insert image description here
2. Open the browser, enter http://127.0.0.1:15672 in the address bar, and you can see the login page of the management interface

insert image description here

Enter the user name and password, both for guest to enter the main interface:

insert image description here

The top navigation is: overview, connections, channels, switches, queues, user management

The above is the overall installation process
—————————————————
Copyright statement: This article is an original article by CSDN blogger "Ordinary Netizen", following the CC 4.0 BY-SA copyright agreement, please attach The link to the source of the original text and this statement.
Original link: https://blog.csdn.net/shuux666/article/details/124337419

Use the Management HTTP API provided by RabbitMQ

To use the Management HTTP API provided by RabbitMQ, you need to enable the plug-in in RabbitMQ first, and then manage the RabbitMQ server through the HTTP RESTful interface. Here is a simple example:

  1. Enable the RabbitMQ Management plugin

In the sbin directory under the RabbitMQ installation directory, run the command: rabbitmq-plugins enable rabbitmq_managementto enable the RabbitMQ Management plug-in.

  1. Access the web management interface of the RabbitMQ Management plugin

Enter in the browser http://localhost:15672/, the default account and password are guestand , respectively guest, and log in to the web management interface of the RabbitMQ Management plug-in.

  1. Create virtual hosts, switches and queues

In the web management interface of the RabbitMQ Management plug-in, click Administratiorthe interface under the theme, select Add a virtual hostthe page, and create a new virtual host.

Under ExchangesSubject, create a new exchange, choose its type and name. It will be used to receive messages from the producer and deliver them to the queue according to the routing key.

Under Queuesthe topic, create a new queue, select the queue name and bind it with the routing key of an exchange.

  1. Call the RabbitMQ Management API interface

In a Java program, you can use RestTemplatethe classes provided by RabbitMQ to send RESTful API requests to access the API interface of RabbitMQ. The specific implementation is as follows:

//创建一个RestTemplate对象
RestTemplate restTemplate = new RestTemplate();

//设置RabbitMQ Management API地址
String apiUrl = "http://localhost:15672/api/";

//设置请求头(身份验证)
HttpHeaders headers = new HttpHeaders();
String authString = "guest:guest";
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
headers.set("Authorization", "Basic " + authStringEnc);

//设置请求体(消息内容)
JSONObject message = new JSONObject();
message.put("key", "value");

//发送HTTP POST请求
HttpEntity<String> request = new HttpEntity<String>(message.toJSONString(), headers);
String response = restTemplate.postForObject(apiUrl + "exchanges/vhostName/exchangeName/publish", request, String.class);

//请求成功
System.out.println(response);

 In the above code, you need to set the address of the RabbitMQ Management API and send an HTTP POST request to it to send the message. Among them, you need to set the authentication information in the request header (HTTP Header), and set the message content in the request body (HTTP Body). After the request is successful, a response from the RabbitMQ server will be received. It should be noted that the vhostName and exchangeName variables in the above code need to be replaced with the actual virtual host and switch names.

Guess you like

Origin blog.csdn.net/qq_22905801/article/details/129872626