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
32-bit: OTP 17.5 Windows 32-bit Binary File (91.0 MB)
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
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); } } } } } }
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); } } } } }
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;