Rabbitmq 消息未出现在来自 c# 的队列中
本文关键字:队列 消息 Rabbitmq | 更新日期: 2023-09-27 18:30:38
我成功地执行了下面的代码,没有任何错误,但是当我执行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);
}
}
看起来
好像您正在声明一个"独占"队列。独占队列是连接独占的,因此无法从另一个连接进行操作(包括列出)。
尝试
Model.QueueDeclare(queName, true, **false**, false, null)
如果您希望能够列出它或使用另一个连接执行任何其他操作。