0

在 C# 中使用 RawRabbit 时如何指定队列名称?我在任何地方都找不到如何做到这一点的例子。如果实施 INamingConvention 是唯一的方法,那么如何使用 INamingConvention 呢?

我尝试按照以下方式指定队列名称,但它仍然使用 _appname 作为后缀。

client.SubscribeAsync<string>(async (msg, context) =>
        {
          Console.WriteLine("Recieved: {0}", msg);
        }, cfg=>cfg.WithQueue(q=>q.WithName("ha.test")));
4

1 回答 1

1

只是在 GitHub 上阅读 RawRabbit 的源代码。看起来有一个 WithSubscriberId(stringsubscriberId) 可供您使用。该subscriberId 设置附加到您设置的队列名称末尾的名称后缀。

队列是使用 QueueConfiguration 类中的 FullQueueName 属性创建的

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(""));

类似的东西。我的 PC 上没有 .NET Core,所以我无法验证它,所以请随时告诉我它不起作用。

UPDATED Fixed the code as suggested by NewToSO's comment

于 2017-04-20T14:52:27.763 回答