Rabbitmq消息没有出现在c#的队列中

时间:2012-04-08 23:39:23

标签: c# .net queue rabbitmq

我在代码下面成功执行没有任何错误,但是当我执行list_queue命令时,它没有给我任何队列。不知道问题出在哪里。

以下代码根本没有给出错误。我的机器是Windows 7 64x,安装了AMPQ运行时64位,使用32x RabbitMq服务器v.2.8.1。

private void createExchange(string message)
        {
            var queName = Convert.ToString(ConfigurationManager.AppSettings["clientQueue"]);
            var exchangeName = Convert.ToString(ConfigurationManager.AppSettings["clientExchange"]);
            var hostName = Convert.ToString(ConfigurationManager.AppSettings["host"]);

            _logger.Info("entered in create exchange");
            _logger.Info("queName: " + queName);
            _logger.Info("exchangeName: " + exchangeName);
            _logger.Info("hostName: " + hostName);
            try
            {
                var connectionFactory = new ConnectionFactory();
                connectionFactory.HostName = "localhost";
                connectionFactory.UserName = "user1";
                connectionFactory.Password = "userpassword";

                using (IConnection connection =
                    connectionFactory.CreateConnection())
                {
                    _logger.Info("Conncection created");
                    using (IModel model = connection.CreateModel())
                    {
                        _logger.Info("Model is created");
                        model.ExchangeDeclare(exchangeName, ExchangeType.Fanout, true);
                        model.QueueDeclare(queName, true, true, false, null);
                        model.QueueBind(queName, exchangeName, "", new Dictionary<string, object>());

                        IBasicProperties basicProperties = model.CreateBasicProperties();
                        model.BasicPublish(exchangeName, "", false, false,
                                           basicProperties, Encoding.UTF8.GetBytes(message));
                        _logger.Info("message: " + message);
                        _logger.Info("message published");

                    }
                }
            }
            catch(Exception ex)
            {
                _logger.Info("Error in create exchange");
                _logger.Info("InnerException:" + ex.InnerException);
                _logger.Info("Message:" + ex.Message);
                _logger.Info("StackTrace:" + ex.StackTrace);
            }
        }

1 个答案:

答案 0 :(得分:2)

看起来好像是在声明一个“独占”队列。专用队列是连接专用的,因此不能在其他连接上进行操作(包括列出)。

尝试

Model.QueueDeclare(queName, true, **false**, false, null)

如果您希望能够列出它或使用其他连接执行任何其他操作。