1. Create a new console application in VS2013 in , and then add a reference: .NET / C # RabbitMQ client library
- RabbitMQ .NET Client (supports .NET Core and .NET 4.5.1+)
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
1. Create a new console application in VS2013 in , and then add a reference: .NET / C # RabbitMQ client library
- RabbitMQ .NET Client (supports .NET Core and .NET 4.5.1+)
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