简体   繁体   中英

Error while Reading from ServiceBus topic/subscription using Azure funtion

I'm currently developing azure functions (new at it) but I'm getting the below error while trying to read from a topic/subscription. I have no idea what's causing this. Any help would be appreciated.

[20/12/2018 14:22:22] Loaded custom extension: ServiceBusExtensionConfig from 'referenced by: Method='Function.ContentCacheUpdate.ReadNotificationQueue.Run', Parameter='mySbMsg'.'
[20/12/2018 14:22:22] Generating 1 job function(s)
[20/12/2018 14:22:23] Found the following functions:
[20/12/2018 14:22:23] Function.ContentCacheUpdate.ReadNotificationQueue.Run
[20/12/2018 14:22:23]
[20/12/2018 14:22:23] Host initialized (1208ms)
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[20/12/2018 14:22:23] Host started (1682ms)
[20/12/2018 14:22:23] Job host started
[20/12/2018 14:22:23] Host lock lease acquired by instance ID '000000000000000000000000EB6A5850'.

My function looks like this

private const string TopicName = "testtopic";

[FunctionName("Function2")]
public static void Run([ServiceBusTrigger(TopicName, "SubscriptionName", Connection = "MyBindingConnection")]string mySbMsg, ILogger log)
{
    log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}

and my local.settings.json file is

{
 "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "TopicName": "testtopic",
    "SubscriptionName": "testsubscription",
    "MyBindingConnection": "Endpoint=sb://test-.xxxxxxxxxxxxxxxxxxxx="
  }
}

Thanks

Looks like your Azure Functions Core Tools used by VS is outdated. To fix this,

First, go to VS menus>Tools>Extensions and Updates, find Azure Functions and Web Jobs Tools , update it if it's not the latest (15.10.2046.0 right now). Close all VS instances. Wait for the update to finish(if there is).

Then clean the old tools and templates and use VS to download new tools.

  1. Remove %localappdata%\\AzureFunctionsTools and %userprofile%\\.templateengine folder.

  2. Reopen VS to create a new Function project, wait at the creation dialog, See Making sure all templates are up to date... .

    在此处输入图片说明 After a while, we can see the tip changes as

    在此处输入图片说明

  3. Click Refresh to work with the latest template instantly.

After creating a new v2 ServiceBus Topic trigger, change your code as below. Connection looks for value in app settings(local.setting.json) by default, while for others properties, we need to wrap them with percent sign. Check details in doc .

    [FunctionName("MyServiceBusTrigger")]
    public static void Run([ServiceBusTrigger("%TopicName%", "%SubscriptionName%", Connection = "MyBindingConnection")]string mySbMsg, ILogger log)
    {
        log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
    }

local.settings.json

{
 "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "TopicName": "testtopic",
    "SubscriptionName": "testsubscription",
    "MyBindingConnection": "Endpoint=sb://test-.xxxxxxxxxxxxxxxxxxxx="
  }
}

即使我确实使用这种方式,也可以交叉检查订阅中是否有消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM