本文轉自:https://blog.csdn.net/xingxing513234072/article/details/51014850html
1、文檔資料git
2、安裝指南
64位:OTP 17.5 Windows 64-bit Binary File (91.1 MB)
(選擇的是.net 4.0版本,同時也能夠經過nuget下載)
3、命令行工具
一、定位到rabbitmq安裝目錄:
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
二、執行rabbitmq命令行工具(rabbitmqctl ):
rabbitmqctl -q status //打印了一些rabbitmq服務狀態信息,包括內存,硬盤,和使用erlong的版本信息
rabbitmqctl list_queues //查看全部隊列消息
4、C#客戶端使用
一、服務端代碼github
-
-
-
-
-
static void Main(string[] args)
-
-
var factory = new ConnectionFactory() { HostName = "localhost" };
-
using (var connection = factory.CreateConnection())
-
-
using (var channel = connection.CreateModel())
-
-
-
channel.QueueDeclare(
"hello", false, false, false, null);
-
-
var consumer = new QueueingBasicConsumer(channel);
-
channel.BasicConsume(
"hello", true, consumer);
-
-
Console.WriteLine(
" [*] Waiting for messages." +
-
-
-
-
-
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
-
-
-
var message = Encoding.UTF8.GetString(body);
-
Console.WriteLine(
" [x] Received {0}", message);
-
-
-
-
-
-
二、客戶端代碼web
-
-
-
-
-
static void Main(string[] args)
-
-
var factory = new ConnectionFactory() { HostName = "localhost" };
-
using (var connection = factory.CreateConnection())
-
-
using (var channel = connection.CreateModel())
-
-
-
channel.QueueDeclare(
"hello", false, false, false, null);
-
-
string message = "Hello World!" + "_" + DateTime.Now.ToString();
-
var body = Encoding.UTF8.GetBytes(message);
-
channel.BasicPublish(
"", "hello", null, body);
-
Console.WriteLine(
" [x] Sent {0}", message);
-
-
-
-
-
若是啓動服務端前啓動了客戶端,消息就會存放到隊列中,da
5、RabbitMQ GUID使用
一、官方提供的一個web管理工具(rabbitmq_management)
二、安裝了Rabbitmq後,默認也安裝了該管理工具,執行命令便可啓動
rabbitmq-plugins enable rabbitmq_management(先定位到rabbitmq安裝目錄)
6、異常問題windows
一、None of the specified endpoints were reachable瀏覽器
生產端和消費端的factory參數要統一工具
var factory = new ConnectionFactory();
factory.UserName = QueueSetttiong.UserName; //用戶名,對應Management工具的admin-->user
factory.Password = QueueSetttiong.Password; //密碼,對應Management工具的admin-->密碼
factory.HostName = QueueSetttiong.HostName; //本地部署服務直接用hostname便可
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
factory.VirtualHost = QueueSetttiong.VirtualHost; //使用默認值: "/"
factory.Protocol = Protocols.DefaultProtocol;網站