The use of Rabbitmq and the use of Web monitoring tools

This article is reproduced from: https://www.cnblogs.com/gossip/p/4475978.html

Please refer to the windows installation manual: http://www.rabbitmq.com/install-windows-manual.html

 

 
 

 

1. Documentation

       1. Official website: http://www.rabbitmq.com/
       2. Installation tutorial: http://www.rabbitmq.com/install-windows.html
 
2. Installation Guide
      1. Download and follow the OTP (must be installed before installing RabbitMQ Server): http://www.erlang.org/download.html
            32-bit: OTP 17.5 Windows 32-bit Binary File (91.0 MB)
            64位:OTP 17.5 Windows 64-bit Binary File (91.1 MB)
      2. Download and install RabbitMQ Server: http://www.rabbitmq.com/download.html
            Select the windows platform, download directly from the official link, or download from github. After the installation is complete, the service will start automatically (services.msc)
      3. Download and install the .Net client: http://www.rabbitmq.com/ dotnet.html
              http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.5.1/rabbitmq-dotnet-client-3.5.1-dotnet-4.0.zip
              (The .net 4.0 version is selected, and it can also be downloaded through nuget )
 
3. Command Line Tools
      1. Navigate to the rabbitmq installation directory:
          windows 7   cd C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.5.1\sbin
          Widows Serve  cd /d C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.5.1\sbin
      2. Execute the rabbitmq command line tool (rabbitmqctl):
         rabbitmqctl -q status //Prints some rabbitmq service status information, including memory, hard disk, and version information using erlong
         rabbitmqctl list_queues //View all queue messages
 
Fourth, the use of C# client
         1. Server code
       
copy code
namespace Server
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    //Define the queue (hello is the queue name)
                    channel.QueueDeclare("hello", false, false, false, null);
 
                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume("hello", true, consumer);
 
                    Console.WriteLine(" [*] Waiting for messages." +
                                             "To exit press CTRL+C");
                    while (true)
                    {
                        //Accept the message sent by the client and print it
                        var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
 
                        var body = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        Console.WriteLine(" [x] Received {0}", message);
                    }
                }
            }
        }
    }
}
copy code

 

 
          2. Client code
copy code
namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    //Define the queue (hello is the queue name)
                    channel.QueueDeclare("hello", false, false, false, null);
                    //The message sent to the queue, including the timestamp
                    string message = "Hello World!" + "_" + DateTime.Now.ToString();
                    var body = Encoding.UTF8.GetBytes(message);
                    channel.BasicPublish("", "hello", null, body);
                    Console.WriteLine(" [x] Sent {0}", message);
                }
            }
        }
    }
}
copy code

 

 
If the client is started before the server is started, the message will be stored in the queue, da
 
Five, RabbitMQ GUID use
       1. An official web management tool (rabbitmq_management)
       2. After installing Rabbitmq, the management tool is also installed by default, and you can start it by executing the command
            rabbitmq-plugins enable rabbitmq_management (first locate the rabbitmq installation directory)  
            
        3. After startup, enter directly in the browser address: http://localhost:15672/ The    account password is: guest    
 
 



6. Abnormal problems

1、None of the specified endpoints were reachable

      The factory parameters of the production side and the consumer side should be unified

  var factory = new ConnectionFactory();
  factory.UserName = QueueSetttiong.UserName; //User name, corresponding to admin-->user of Management tool
  factory.Password = QueueSetttiong.Password; //Password, corresponding to admin--> of Management tool Password
  factory.HostName = QueueSetttiong.HostName; //The local deployment service can use hostname directly
  factory.Port = AmqpTcpEndpoint.UseDefaultPort;
  factory.VirtualHost = QueueSetttiong.VirtualHost; //Use the default value: "/"
  factory.Protocol = Protocols. DefaultProtocol;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325117978&siteId=291194637