RabbitMQ installation configuration and basic use based on the EasyNetQ driver, rabbitmqeasynetq

Source: Internet
Author: User

RabbitMQ installation configuration and basic use based on the EasyNetQ driver, rabbitmqeasynetq

I. Basic Concepts and Principles of RabbitMQ

1. AMQP, Advanced Message Queuing Protocol, is an open standard for application layer protocols and is designed for Message-oriented middleware.

2. RabbitMQ is an open-source AMQP implementation. The server side is written in Erlang.

3. Channel

Channel is the most important interface for us to deal with RabbitMQ. Most of our business operations are completed in the Channel interface, including defining Queue, defining Exchange, binding Queue and Exchange, and publishing messages.

4. exchange (the producer sends the message to Exchange (the switch), and Exchange routes the message to one or more Queue (or discard ), the Exchange types commonly used by RabbitMQ are fanout, direct, topic, and headers)

5. Queue (internal object of RabbitMQ, used to store messages)

6. basic working principle

Client (producer) send Message --> Exchange (the switch saves messages to the corresponding queue through different types) --> Queue

The client (consumer) uses subscription to consume messages in the queue.

The above basic concepts are detailed from the basic concepts of RabbitMQ.

 

IIInstall RabbitMQ in Windows

1. Download and install erlang (I use otp_win64_19.3)

Http://www.erlang.org/downloads (32 to 64 bit depending on the operating system)

2. Download and install rabbitmq-server (I am using the rabbitmq-server-3.6.10 Version)

Http://www.rabbitmq.com/install-windows.html

After the installation is complete, you can see it in the mounted directory.

Next, enable the doscommand.

A. cd to sbin directory, my installation directory is D: \ RabbitMQServer \ rabbitmq_server-3.6.10 \ sbin, input D: Press enter, cd RabbitMQServer \ rabbitmq_server-3.6.10 \ sbin

 

B. Run the following command to check whether the installation is successful:Rabbitmqctl status

C. Install the management plug-in command:Rabbitmq-plugins enable rabbitmq_management

The installation is successful. Enter http: // 127.0.0.1: 15672/in the browser/

 

It is a little excited to enter the guest account guest password guest and log in successfully.

The guest account is an administrator account. You can add Exchanges, Queues, and Admin accounts. However, we generally do not use the guest account, and continue to use commands to add accounts and permissions.

D: Add a user:Rabbitmqctl. bat add_user username password

 

E: add the "super administrator" role:Rabbitmqctl. bat set_user_tags username administrator

 

Mymq account is also a super administrator. Can access virtual hosts: No access. You Can see that No virtual machine Can be accessed. Then add the virtual machine.

F: Add a virtual machine:Rabbitmqctl add_vhost vhostName

The myvhost virtual machine does not have Users. Next, bind an account to the virtual machine.

G: Set Virtual Machine and user permissions:Rabbitmqctl set_permissions-p Virtual Machine name account name ".*"".*"".*"

 

H: In my habit, I usually Delete the guest account:Rabbitmqctl. bat delete_user username

Now, log on to the Management page again, and everything is normal. Next we will start to practice.

 

3.And EasyNetQ

A. Install EasyNetQ in the project

EasyNetQ depends on RabbitMQ. Client, so it will be installed in the project together.

B.PublishAndSubscribe

Publish a message in Publish

 

Model has a Queue feature that defines the Queue name and Exchange name. Then, use the Publish method to push Msg to the specified queue through the switch specified by the Model.

Run the code to see the MQ Management page.

You have created the TestQueue. Exchange, Type: topic, Features: D specified by the Model.D: DurableThe default vswitch isPersistence.

Because you have not subscribed to a message, you cannot see the corresponding queue in Queues.

Subscribe to messages

Why set a while (true) in the subscription code? It is to simulate the console program as a Windows service, because the console program runs a flash, and there is no way to actually subscribe to MQ messages.

In actual development, it is generally usedTopselfTo publish the console programWindows ServicesLater, I will write another study blog about Topself.

Repeat the Publish operation to test the entire process.

 

Custom Topic

In this way, the message will be sent to all Queue queues whose names start with Test.

C.SendAndReceive

Send and receive can send messages to a specified queue.

 

Blog address: http://www.cnblogs.com/struggle999/p/6937530.html

Related Article

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.