0

How can I specify queue name when using RawRabbit with C#? I could not find an example anywhere on how to do it. If implementing INamingConvention is the only way then how to do it with INamingConvention?

I have tried specifying queue name following way but it still uses _appname as postfix.

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

1 Answers1

1

Just reading the source code of RawRabbit in GitHub. Looks like there is a WithSubscriberId(string subscriberId) available to you. That subscriberId sets the name suffix which is appended to end of the queue name you set.

The queue is created using the FullQueueName property in the QueueConfiguration class

public string FullQueueName
{
    get
    {
        var fullQueueName =  string.IsNullOrEmpty(NameSuffix)
            ? QueueName
            : $"{QueueName}_{NameSuffix}";

        return fullQueueName.Length > 254
            ? string.Concat("...", fullQueueName.Substring(fullQueueName.Length - 250))
            : fullQueueName;
    }
}

So just set the subscriberId to an empty string.

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

Something like that. I don't have .NET Core on my PC so I can't verify it, so feel free to tell me it doesn't work.

UPDATED Fixed the code as suggested by NewToSO's comment

Vanlightly
  • 1,389
  • 8
  • 10
  • It works with one correction. .WithSubscriberId("") needs to be attached to cfg.WithQueue and not to q.WithName. Thank you. – Alpesh Apr 21 '17 at 08:34