首页 > 其他 > 详细

rabbitmq 命令&& rabbitmq教程(一)

时间:2015-02-08 16:46:36      阅读:485      评论:0      收藏:0      [点我收藏+]

先来个官方教程

http://www.rabbitmq.com

 

在windows 下 命名 去掉sudo 我是在windows下测试 用net调用

常用命令

控制台命令:sudo rabbitmqctl#只能在root权限下使用

本地节点默认被命名为”rabbit”。可以通过这个命令前使 用”-n”标志明确的指定节点名称, 例如:  

sudo rabbitmqctl -n rabbit@hostname **** 控制台命令

启动:sudo rabbitmq-server start

启动应用:sudo  rabbitmqctl start_app

停止应用:sudo rabbitmqctl stop_app

停止rabbitmq:sudo rabbitmqctl stop

显示RabbitMQ中间件各种信息:sudo rabbitmqctl status

重置RabbitMQ节点:
sudo rabbitmqctl reset

sudo rabbitmqctl force_reset

 

用户管理
添加用户
sudo rabbitmqctl add_user username password
删除用户
sudo rabbitmqctl delete_user username
修改密码
sudo rabbitmqctl change_password username newpassword

列出所有用户

 

sudo rabbitmqctl list_users  
创建虚拟主机
sudo rabbitmqctl add_vhost vhostpath

删除虚拟主机

sudo rabbitmqctl delete_vhost vhostpath

列出所有虚拟主机
sudo rabbitmqctl list_vhosts
设置用户权限

sudo rabbitmqctl set_permissions [-p vhostpath] username regexp regexp regexp

example:sudo rabbitmqctl set_permissions -p vhostname testuser ".*" ".*" ".*"

清除用户权限
sudo rabbitmqctl clear_permissions [-p vhostpath] username
列出虚拟主机上的所有权限
sudo rabbitmqctl list_permissions [-p vhostpath]
列出用户权限

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>]

 

环境搭建

环境还是简单的说下

1、从官方下载http://www.rabbitmq.com/download.html 服务版本

2、没有erlang需要下载http://www.erlang.org/download.html

3、启动服务

技术分享

4、验证是否成功

sudo rabbitmqctl status

技术分享

简单消息(Hello World)

发送消息

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);
                    }
                }
            }
        }

 

运行结果

技术分享

rabbitmq 命令&& rabbitmq教程(一)

原文:http://www.cnblogs.com/shuzhengyi/p/4280102.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!