1.Rabbitmq的官方下载地址:https://www.rabbitmq.com/download.htmlhtml
注意:web
RabbitMQ须要安装64位支持的Erlang for Windows版本。Erlang版本包括Windows安装程序。Erlang Solutions也 提供二进制64位Erlang版本。浏览器
重要提示:必须使用管理账户运行Erlang安装程序,不然RabbitMQ安装程序所需的注册表项将不存在。工具
2.web监控工具(下载RabbitMQ时默认包含web监控工具)spa
使用方式:.net
(1)进入到RabbitMQ的安装地址:code
输入命令启动监控工具:rabbitmq-plugins enable rabbitmq_managementhtm
(2)步骤1启动后打开浏览器输入网址:http://localhost:15672/ 帐号密码都是:guest blog
3..net 实现简单的消息发送与接收token
(1)建立.net core控制台项目,新建发送类:Send.cs
注:须要先添加程序集依赖项:RabbitMQ.Client
//创建一个消息,名称为:hello
public class Send { public static void sendMain() { 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 ); string message = "Hello Amanda"; 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(); } } }
执行以后能够经过web监控工具程序查看结果:
(2)建立.net core控制台项目,新建接收类:Receive.cs
注:须要先添加程序集依赖项:RabbitMQ.Client
public class Receive { public static void ReceiveMain() { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) { using (var channel = connection.CreateModel()) { channel.QueueDeclare( queue:"hello", 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(); } } } }
执行以后能够经过web监控工具程序查看结果: