我正在成功执行下面的代码,没有任何错误,但是当我执行 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);
}
}