如何在RawRabbit和C#一起使用时指定队列名?我在任何地方都找不到如何做这件事的例子。如果实现INamingConvention是唯一的方法,那么如何使用INamingConvention来实现呢?
我尝试过按以下方式指定队列名,但它仍然使用_appname作为后缀。
client.SubscribeAsync<string>(async (msg, context) =>
{
Console.WriteLine("Recieved: {0}", msg);
}, cfg=>cfg.WithQueue(q=>q.WithName("ha.test")));发布于 2017-04-20 14:52:27
只是在GitHub中阅读GitHub的源代码。看起来您可以使用WithSubscriberId(string subscriberId)。该subscriberId设置名称后缀,该后缀被附加到您设置的队列名称的末尾。
队列是使用FullQueueName属性在QueueConfiguration类中创建的。
public string FullQueueName
{
get
{
var fullQueueName = string.IsNullOrEmpty(NameSuffix)
? QueueName
: $"{QueueName}_{NameSuffix}";
return fullQueueName.Length > 254
? string.Concat("...", fullQueueName.Substring(fullQueueName.Length - 250))
: fullQueueName;
}
}因此,只需将subscriberId设置为空字符串即可。
client.SubscribeAsync<string>(async (msg, context) =>
{
Console.WriteLine("Recieved: {0}", msg);
}, cfg=>cfg.WithQueue(q=>q.WithName("ha.test")).WithSubscriberId(""));差不多吧。我的个人电脑上没有.NET内核,所以我无法验证它,所以请告诉我它不工作。
按NewToSO评论的建议更新了代码
https://stackoverflow.com/questions/43521608
复制相似问题