Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

visual studio - Cannot run Azure Function with service bus trigger

I created an azure function with service bus trigger, when I try to run the function I get this error:

[2021-01-07T12:32:43.565Z] A host error has occurred during startup operation '4f45a03c-9302-43c6-8c54-e6555bc0f562'.
[2021-01-07T12:32:43.566Z] System.Private.Uri: Value cannot be null. (Parameter 'uriString').

I have my local.settings.json file set up for development storage

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

and I have the connection string in the function using AzureWebJobsStorage

public static class ProcessAS2ExchangeInboundExceptions
    {
        [FunctionName("ProcessAS2ExchangeInboundExceptions")]
        public static void Run(
            [ServiceBusTrigger("as2-exchange-inbound-topic", "exceptions", Connection = "AzureWebJobsStorage")] string myQueueItem,
            ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

        }

    }

I am not sure what the issue is. Any help would be appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As per your config, AzureWebJobsStorage is representing a connection string the Azure Storage instead of Azure Service Bus. So either you should define a new config to connect to Azure Service Bus instance with topic and subscription name (make sure to have a instance of Azure Service Bus is spinned-up in Azure) or use QueueTrigger with queue name to work with Azure Storage.

Updated below code to represent the QueueTrigger

public static class ProcessAS2ExchangeInboundExceptions
{
    [FunctionName("ProcessAS2ExchangeInboundExceptions")]
    public static void Run(
        [QueueTrigger("as2-exchange-inbound-queue", Connection = "AzureWebJobsStorage")] string myQueueItem,
        ILogger log)
    {
        log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    }

}

Queue Trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=csharp

Azure Service Bus Trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...