0
votes

I have an application that send some events for an Azure Service Bus Queue and a Azure Function as consumer, so I have this code for my Azure Function:

    [FunctionName("application-events-consumer")]
    public async Task Run([ServiceBusTrigger("events", Connection = "ServiceBusConnectionString")]
        Message message,
        string messageId,
        ILogger log)
    {
        log.LogInformation($"MessageId={messageId}");

        var jsonData = Encoding.UTF8.GetString(message.Body);
        var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
        var deserialized = JsonConvert.DeserializeObject(jsonData, settings);

        await _mediator.Publish(deserialized);
    }

The problem is: We cannot run Azure Service Bus locally, so I thought about use Azure Storage Queue just for locally development because It has an emulator, I didn't have any problem to send my events to the Azure Storage Queue because I'm using an abstraction but I have a problem to read my events from the queue because my azure function uses a bind specific for Azure Service Bus so I can't read event from Azure Storage Queue, is it possible to use a bind for both cases? Azure Storage Queue and Azure Service Bus depending on my Connection String?

1

1 Answers

1
votes

No, Azure Service Bus Queues and Azure Storage Queues are two very different services with a completely different tech stack. So you cannot just switch the two connection strings. They need different SDKs because they have different bindings.

The only thing you could try is to have two functions, one with a Storage Queue binding that you use for debugging locally and one with a SB Queue binding for running in the cloud. Both just take the message and you put the processing in one common internal function. However, that of course will not fully test your stack.