Rabbit交换机确认模式。comfirm和事务模式测试。
This commit is contained in:
parent
12beee8577
commit
2a9928c209
|
@ -138,5 +138,46 @@ namespace RabbitMqTest
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送到exchange后,exchange需要确认.Confirm模式
|
||||
/// </summary>
|
||||
[TestMethod("exchangeConfirm")]
|
||||
public void ExchangeConfirm() {
|
||||
var exchangeName = "tempExchange";
|
||||
|
||||
var channel = GetChannel();
|
||||
channel.ExchangeDeclare(exchangeName,ExchangeType.Fanout,false,true,null);
|
||||
channel.ConfirmSelect();
|
||||
channel.BasicPublish(exchangeName,"",null,RandomMsgBytes());
|
||||
if(channel.WaitForConfirms()) {
|
||||
Console.WriteLine("交换机确认成功!");
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("交换机确认失败!");
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送到exchange后,exchange需要确认.事务模式
|
||||
/// </summary>
|
||||
[TestMethod("exchangeTx")]
|
||||
public void ExchangeConfirm2() {
|
||||
var exchangeName = "tempExchange";
|
||||
|
||||
using var channel = GetChannel();
|
||||
channel.ExchangeDeclare(exchangeName,ExchangeType.Fanout,false,true,null);
|
||||
try {
|
||||
channel.TxSelect();
|
||||
channel.BasicPublish(exchangeName,"",null,RandomMsgBytes());
|
||||
channel.TxCommit();
|
||||
Console.WriteLine("交换机确认成功!");
|
||||
}
|
||||
catch(Exception ex) {
|
||||
Console.WriteLine("交换机确认失败!");
|
||||
Assert.Fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,16 @@ namespace RabbitMqTest
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成随机消息字节数组
|
||||
/// </summary>
|
||||
/// <param name="len"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual Byte[] RandomMsgBytes(int len = 10) {
|
||||
var str = RandomString(len);
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建队列
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user