【发布时间】:2018-07-04 19:37:56
【问题描述】:
我正在尝试通过事务将消息从发布者同步发送到代理,如 here 所述(使用 Tx 保证交付),以确保从发布者到代理的消息传递。
所以我向代理发送消息。
try
{
var factory = new ConnectionFactory() {HostName = "localhost"};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: routingKey, durable: true, exclusive: false, autoDelete: false, arguments: null);
var properties = channel.CreateBasicProperties();
properties.Persistent = true;
channel.TxSelect();
for (int i = 0; i < 10; i++)
{
channel.BasicPublish("", routingKey, properties, Encoding.UTF8.GetBytes("nop"));
channel.TxCommit();
}
}
}
catch (Exception ex)
{
//handle exception
Console.WriteLine(ex);
}
我期望消息将被传递给代理并持久化到队列中。否则如果出现问题就会出现异常。
但是当我在发布消息时删除队列时,什么也没有发生。
为什么事务无异常提交?
【问题讨论】:
标签: c# rabbitmq publish-subscribe