先來個官方教程html
http://www.rabbitmq.comwindows
在windows 下 命名 去掉sudo 我是在windows下測試 用net調用app
控制檯命令:sudo rabbitmqctl#只能在root權限下使用測試
本地節點默認被命名爲」rabbit」。能夠經過這個命令前使 用」-n」標誌明確的指定節點名稱, 例如: spa
sudo rabbitmqctl -n rabbit@hostname **** 控制檯命令regexp
啓動:sudo rabbitmq-server startserver
啓動應用:sudo rabbitmqctl start_apphtm
中止應用:sudo rabbitmqctl stop_app中間件
中止rabbitmq:sudo rabbitmqctl stop教程
顯示RabbitMQ中間件各類信息:sudo rabbitmqctl status
sudo rabbitmqctl force_reset
列出全部用戶
刪除虛擬主機
sudo rabbitmqctl delete_vhost vhostpath
sudo rabbitmqctl set_permissions [-p vhostpath] username regexp regexp regexp
example:sudo rabbitmqctl set_permissions -p vhostname testuser ".*" ".*" ".*"
sudo rabbitmqctl list_user_permissions username
列出所有隊列,exchanger,binder
sudo rabbitmqctl list_queues [-p <vhostpath>] [<queueinfoitem> ...]
list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]
list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]
list_connections [<connectioninfoitem> ...]
list_channels [<channelinfoitem> ...]
list_consumers [-p <vhostpath>]
環境仍是簡單的說下
一、從官方下載http://www.rabbitmq.com/download.html 服務版本
二、沒有erlang須要下載http://www.erlang.org/download.html
三、啓動服務
四、驗證是否成功
sudo rabbitmqctl status
發送消息
static void Main(string[] args)
{
var factory = new ConnectionFactory();
factory.HostName = "Localhost";
factory.UserName = "shuzhengyi";
factory.Password = "shuzhengyi";
while (true)
{
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
string message = "Hello World";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish("", "hello", null, body);
Console.WriteLine(" set {0}", message);
Console.ReadLine();
}
}
}
}
接受消息
public static void Main()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
factory.UserName = "shuzhengyi";
factory.Password = "shuzhengyi";
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." +
"To exit press CTRL+C");
while (true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0}", message);
}
}
}
}
運行結果