About RABBITMQ and the integration of RABBITMQ and spring

Source: Internet
Author: User
Tags message queue rabbitmq

Https://www.cnblogs.com/s648667069/p/6401463.html


Basic Concepts RABBITMQ is a popular open source Message Queuing system, developed in Erlang language. RABBITMQ is the standard implementation of the AMQP (Advanced Message Queuing protocol). If you are unfamiliar with AMQP, it can be difficult to see RABBITMQ documents directly. But it also has only a few key concepts, which are briefly described here. The structure diagram of the RABBITMQ is as follows:

Several concept notes: Broker: The Message Queuing server entity is simply the case.
Exchange: A message switch that specifies what rules the message is routed to and to which queue.
Queue: A message queue carrier in which each message is put into one or more queues.
Binding: Bind, which is the role of binding exchange and queue according to routing rules.
Routing key: The routing keyword, exchange messages are delivered based on this keyword.
Vhost: Virtual host, a broker can open multiple vhost, as a separate user permissions.
Producer: The message producer is the program that delivers the message.
Consumer: The message consumer is the program that receives the message.
Channel: The message channels, in each connection of the client, multiple channels can be established, each channel represents a session task. The use of Message Queuing is probably as follows: (1) The client connects to the Message Queuing server and opens a channel.
(2) The client declares an exchange and sets the related properties.
(3) The client declares a queue and sets the related properties.
(4) The client uses routing key to establish a good binding relationship between Exchange and queue.
(5) Clients post messages to exchange. When Exchange receives a message, it routes messages to one or more queues based on the key of the message and the binding that has been set. There are several types of exchange, which are called direct switches that are delivered entirely according to key, for example, when the routing key is set to "ABC", the client submits a message that only the key "ABC" is set to be posted to the queue. When the key is matched with a pattern, it is called a topic switch, and the symbol "#" matches one or more words, and the symbol "*" matches exactly one word. For example, "abc.#" matches "Abc.def.ghi", "abc.*" matches only "Abc.def". There is also a need for a key, called the fanout Switch, which takes broadcast mode, when a message comes in, it is posted to all queues that are bound to the switch. RABBITMQ supports the persistence of messages, that is, data is written on disk, and for data security reasons, I think most users will choose to persist. Message Queuing persistence consists of 3 parts:
(1) Exchange persistence, specifying durable + 1 at the time of declaration
(2) Queue persistence, specify durable when declaring = 1
(3) Message persistence, specifying Delivery_mode = 2 on delivery (1 non-persistent) if both Exchange and queue are persisted, the binding between them is persistent.   If there is a persistence between Exchange and queue, a non-persisted, binding is not allowed. RABBITMQ Integration Spring 1. You need to download RABBITMQ, and Erlang is required before RABBITMQ installation because RABBITMQ is written in Erlang. (Configure environment variables after download)

1.1 Starting the RABBITMQ server

1.2 Creating a virtual host on a RABBITMQ server

1.3 Creating a user

    

1.4 Adding administrator roles to users

    

1.5 Setting the user's permissions on the virtual host

    

Set_permissions-p vhostsjj Shijunjie ". *" ". *" ". *"

1.6 Installing the Web-based management plug-in

  

Following the above configuration, you can see the information in the admin interface.

  

Attached: Some common commands of RABBITMQ

RABBITMQ installation, start-up and stop

Rabbitmq-service.bat Install
Rabbitmq-service.bat start
Rabbitmq-service.bat stop

List all queue

Rabbitmqctl list_queues

List information for a specified queue

Rabbitmqctl List_queues [the queue name] Messages_ready messages_unacknowledged

List all Exchange

Rabbitmqctl list_exchanges

List all Binding

Rabbitmqctl list_bindings

Install the Web-based management plug-in

Rabbitmq-plugins.bat Enable Rabbitmq_management

Close node
# Rabbitmqctl Stop
2. Stop RABBITMQ applications
# Rabbitmqctl Stop_app
3. Start the RABBITMQ application
# Rabbitmqctl Start_app
4. Display various information of RABBITMQ middleware
# RABBITMQCTL Status
5. Resetting the RABBITMQ node
# Rabbitmqctl Reset
# Rabbitmqctl Force_reset
Removes all data from the management database, such as configured users and virtual hosts, and removes all persisted messages from any cluster it belongs to.
The difference between the Force_reset command and reset is to unconditionally reset the node regardless of the current management database state and the configuration of the cluster. Use this last resort if there is an error in the database or cluster configuration.
Note: Reset and Force_reset will only succeed if the RABBITMQ app is stopped.
6. Circular log files
# Rabbitmqctl Rotate_logs[suffix]
7. Cluster Management
# rabbitmqctl Cluster Clusternode ...

User Management
1. Add Users
# Rabbitmqctl add_user username password
2. Delete a user
# Rabbitmqctl Delete_user username
3. Change the password
# Rabbitmqctl Change_password Username NewPassword
4. List all Users
# Rabbitmqctl List_users

Permissions Control 1. Create a virtual host
# Rabbitmqctl Add_vhost Vhostpath
2. Deleting a virtual host
# Rabbitmqctl Delete_vhost Vhostpath
3. List all virtual hosts
# Rabbitmqctl List_vhosts
4. Set User permissions
# rabbitmqctl Set_permissions [-P vhostpath] username regexp regexp regexp
5. Clear User Permissions
# rabbitmqctl Clear_permissions [-P Vhostpath] Username
6. List all permissions on the virtual host
# rabbitmqctl List_permissions [-P Vhostpath]
7. List User Rights

# Rabbitmqctl List_user_permissions username

2. Build a MAVEN project. Then we start configuring the project.

2.1 Because it is spring consolidation, we need to join spring's dependencies.

  

    <dependency> <groupId>org.springframework</groupId> <artifactid>spring -core</artifactid> <version>3.2.8.RELEASE</version> </dependency> < Dependency> <groupId>org.springframework</groupId> <artifactid>spring-webmvc& lt;/artifactid> <version>3.2.8.RELEASE</version> </dependency> <depend Ency> <groupId>org.springframework</groupId> <artifactid>spring-context</a rtifactid> <version>3.2.8.RELEASE</version> </dependency> <dependency&
            Gt 
            <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId>
            <version>3.2.8.RELEASE</version> </dependency> <dependency> <gRoupid>org.springframework</groupid> <artifactId>spring-aop</artifactId> < version>3.2.8.release</version> </dependency> <dependency> <groupid&gt ;org.springframework</groupid> <artifactId>spring-aspects</artifactId> <versi On>3.2.8.release</version> </dependency> <dependency> <groupid>org. Springframework</groupid> <artifactId>spring-tx</artifactId> <

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.