In the fourth quarter RabbitMQ C # application terminal - Connection Client

Original: fourth quarter RabbitMQ C # application terminal - Connection Client

Copyright: without his consent shall not be reproduced this article, thank you https://blog.csdn.net/phocus1/article/details/87357911

1. Create a new console application in VS2013 in , and then add a reference: .NET / C # RabbitMQ client library

Use NuGet package download RabbitMQ.Client, as follows:

2. Add a reference in the code, and write connection code

using RabbitMQ.Client;
//核心代码:
 try
    {
        ConnectionFactory factory = new ConnectionFactory();
        factory.UserName = "wiadmin";
        factory.Password = "wi2019";
        factory.HostName = "127.0.0.1";
        factory.VirtualHost = "/";//默认情况可省略此行
        factory.Port = 5672;//此处默认即为5672端口,可省略此行
        IConnection conn = factory.CreateConnection();                            
        Console.Write("---------------RabbitMQ连接成功---------------\n");
    }
    catch (Exception ex)
    {
        Console.Write(string.Format("RabbitMQ连接异常:{0}\n", ex.ToString()));
    }

 At this time, an error will be connected , as shown below:

Is displayed wiadmin accounts do not have permission, can now be added through the other end of permissions management, are as follows:

Before adding permissions:

After adding permissions:

Run the program again, will not be given:

Add that to use here two core API:

IConnection: indicates AMQP 0-9-1 connected
ConnectionFactory: Example configuration IConnection

 

 

 

 

 

Original: fourth quarter RabbitMQ C # application terminal - Connection Client

Copyright: without his consent shall not be reproduced this article, thank you https://blog.csdn.net/phocus1/article/details/87357911

1. Create a new console application in VS2013 in , and then add a reference: .NET / C # RabbitMQ client library

Use NuGet package download RabbitMQ.Client, as follows:

2. Add a reference in the code, and write connection code

using RabbitMQ.Client;
//核心代码:
 try
    {
        ConnectionFactory factory = new ConnectionFactory();
        factory.UserName = "wiadmin";
        factory.Password = "wi2019";
        factory.HostName = "127.0.0.1";
        factory.VirtualHost = "/";//默认情况可省略此行
        factory.Port = 5672;//此处默认即为5672端口,可省略此行
        IConnection conn = factory.CreateConnection();                            
        Console.Write("---------------RabbitMQ连接成功---------------\n");
    }
    catch (Exception ex)
    {
        Console.Write(string.Format("RabbitMQ连接异常:{0}\n", ex.ToString()));
    }

 At this time, an error will be connected , as shown below:

Is displayed wiadmin accounts do not have permission, can now be added through the other end of permissions management, are as follows:

Before adding permissions:

After adding permissions:

Run the program again, will not be given:

Add that to use here two core API:

IConnection: indicates AMQP 0-9-1 connected
ConnectionFactory: Example configuration IConnection

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/owenzh/p/11087942.html