Install RABBITMQ server and basic configuration under Windows

Source: Internet
Author: User
Tags readline rabbitmq

RABBITMQ is a complete, reusable enterprise messaging system based on the AMQP protocol standard. It follows the Mozilla Public License Open Source protocol, an industrial-grade Message Queuing (MQ) server implemented with Erlang, and Rabbit MQ is built on the Erlang OTP platform.

Installing the RABBITMQ server must first install the Erlang(https://www.erlang.org/downloads) runtime environment.

Installing Erlang

When installing Erlang, be aware of the Erlang version on which RABBITYMQ is installed, choose a version according to RABBITMQ's requirements, and the version of RABBITMQ that I want to install here is 3.7.7, and the range of Erlang versions he relies on IS


19.3.6.4 to 21.0.x, so I chose the version to be OTP 20.3. Erlang. After downloading the Erlang installation package, you can install it directly.

Setting Erlang_home Environment variables


I am here by default installation so Erlang's installation path is:

C:\Program Files\erl9.3\bin\erl.exe

Click OK to add the erlang_home you just added in the system environment variable

Note: If you have previously installed other versions of Erlang, you will need to reinstall and setup after uninstalling.

To find Erlang in the Start menu, click Start to open the following interface, then Erlang installs successfully. Next, install RABBITMQ.

Installing RABBITMQ

The latest version of the RabbitMQ server Installer can be downloaded from the official website of RabbitMQ, RabbitMQ, where I downloaded the latest version of the official recommendation Rabbitmq-server-3.7.7.exe, and then clicked on the default installation.

RABBITMQ is installed as a Windows service running in the background.

Setting RABBITMQ Environment variables

After the RabbitMQ is installed, you will see three menus in the Start menu input RabbitMQ:

The three menu here is a command to control Windows service, in order to be able to manipulate the RABBITMQ service on any Windows command window requires an environment variable to be added to the system and configured in the system's PHTH environment variable.

First add a Rabbitqm_server variable:

Then configure the following in the path variable of the system:

This allows the RABBITMQ service to be manipulated in a CMD window launched by Windows Administrator. You do not need to navigate to:
C:\Program FILES\RABBITMQ server\rabbitmq_server-3.7.7\sbin>

Installing Rabbitmq_management

Let's take a look at all the RABBTITMQ plugins:

C:\windows\system32>rabbitmq-plugins List

See RABBTITMQ list out a lot of plugins

We install the Rabbitmq_management plugin with the following command, which is a visual way to view the status of the RABBITMQ server instance and to manipulate the RABBITMQ server.

C:\windows\system32>rabbitmq-plugins Enable Rabbitmq_management

When you finish running the command, you see that the installation was successful.

Now we enter in the browser: http://localhost:15672 can see a login interface:

Here you can use the default account Guest/guest login interface as follows:

Enter http://localhost:15672/api/in the browser to see the RabbitMQ Management HTTP API documentation, such as:

This allows you to view information about the status of the RABBITMQ server instance.

Managing users of Rabbitmq_management

Use the command Rabbitmqctl list_users to view the current Rabbitmq_management registered users

Found that there is now only one user guest, and its tag is administrator.

Then create a user at the command line, and the command to create the user is:

Rabbitmqctl Add_user [username] [Password]

Now create a username=rabbit1 password=rabbit1 user with the following command:

Rabbitmqctl Add_user rabbit1 rabbitl

The creation was successful:

Now look at the number of users, run the command:

Rabbitmqctl list_user

A user rabbit1 is found in the user list, but the tag is empty. Use the command to set tag to rabbit, set the command format of the tag:

Rabbitmqctl Set_user_tag [TAG1] [Tag2] ...

You can set multiple tags for one user at a time, or you can set a

Now Rabbit1 has two tags, one is administrator, the other is none.

There are 5 tags to choose from, namely: Administrator, Monitoring,policymaker,management and none interested students can come here to understand the meaning of each tag, in fact, the tag here is the authority, Administrator is the highest privilege, none means no access, here the combination of administrator and none, the permissions should be high on the line, ignoring none, with the permissions of the administrator. We use RABBIT1/RABBIT1 to log in to Rabbitmq_management.


In fact, with rabbitmq_management This visual plugin, a lot of things can be done in this plug-in, including creating users, creating switches (Exchange) and creating Queues (Queque).

About Rabbit's basic configuration under Windows is over, for more advanced configuration, you can refer to the official website, with the Rabbitmq_management plug-in is indeed a lot of convenience. The following is the start of creating a client for testing.


Test

Create two. Net Core Console Types of applications, one for sending messages and one for receiving messages.

1. Send-Side code:


using System;
using System.Text;
using RabbitMQ.Client;

namespace Q.Demo.Send
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello",
                    durable: false,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);
                while (true)
                {
                    var input = Console.ReadLine();
                    string message = input;
                    var body = Encoding.UTF8.GetBytes(message);

                   channel.BasicPublish(exchange: "",
                    routingKey: "hello",
                    basicProperties: null,
                    body: body);
                Console.WriteLine(" [x] Sent {0}", message);
                }
                
            }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
    }
}


2.Receive Terminal code:

using System;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace Q.Demo.Receive
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello",
                    durable: false,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", message);
                };
                channel.BasicConsume(queue: "hello",
                    autoAck: true,
                    consumer: consumer);

                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
            }
        }
    }
}
The effect of running the input message is as follows:
Summarize:

About the installation and basic setup steps for RABBITMQ under Windows:

1. Install the corresponding version of Erlang and set the environment variables

2. Installing RABBITMQ

3. Setting Environment variables

4. Install the plugin rabbitmq_management

5. With the plugin rabbitmq_management a lot of things can be done in this visual plug-in.

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.