Search code examples
.netazureasp.net-coreazureservicebusazure-servicebus-queues

Test Azure Service Bus Queues Locally with a subscription


How does one test Azure Service Bus Queues Locally?

1.I have to rename our Queue to something else, as some other developers or already running function may consume it

Example: 

a) Original Queue: Product

b) Test Queue: Test

2.We also have Azure functions picking up queues, so also rename the Service Bus Trigger.

However, its still not working?

Does Anything else need to be changed?

I see Queue messages being sent with Service Bus Explorer, but they are not being event handle or responded with our process action.

[FunctionName(nameof(TestAsync))]
public async Task TestRollAsync(
[ServiceBusTrigger("test", Connection = "ServiceBusConnection", IsSessionsEnabled = false)] Message sbMessage)
{
    var cmessage = Encoding.UTF8.GetString(sbMessage.Body);
    Test msg = null;

    try
    {
        msg = JsonConvert.DeserializeObject<Test>(cmessage);
    }

Solution

  • Renaming the queue is not the most convenient way as it will require to undo the changes when you commit the code and that's error-prone. A better option would be to use a developer-specific Azure Service Bus namespace that can be provisioned on a standard tier, using MSDN/company account. You can have as many namespaces on the standard tier as needed. There's no cost involved for the service other than $10 a month for the service (or the equivalent for your currency) when additional namespaces are provisioned and not used.

    With a namespace per developer, your code stays as-is, and the connection string (the value) can be changed in the settings.json file that is local and should not be committed to the repository. That way the queue name and connection string name remain untouched and you can develop/debug locally