3

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

下面的代码根本没有给出错误。我的机器是 windows 7 64x,安装 AMPQ runtime 64bit 并使用 32x RabbitMq server 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);
            }
        }
4

1 回答 1

3

看起来好像您正在声明一个“独占”队列。独占队列对连接是独占的,因此不能从另一个连接操作(包括被列出)。

尝试

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

如果您希望能够列出它或对来自另一个连接的 if 执行任何其他操作。

于 2012-04-09T06:57:46.453 回答