3
votes

I am running Visual Studio 2017 Preview and running the function code locally and I am using the out of the box Azure Function project template. I'm trying to have an Azure Function triggered by a timer send a message to a Service Bus queue using an output binding but it looks like the WebJob SDK can't bind the output to a string type.

Binding

 "bindings": [
    {
      "type": "serviceBus",
      "name": "msg",
      "queueName": "myqueue",
      "connection": "ServiceBusQueue",
      "accessRights": "manage",
      "direction": "out"
    }
  ]

Timer Function

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace MyFunctionApp
{
    public static class TimerTrigger
    {
        [FunctionName("TimerTriggerCSharp")]
        public static void Run([TimerTrigger("1 * * * * *", RunOnStartup = true)]TimerInfo myTimer, TraceWriter log, out string msg)
        {
            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

            msg = "Hello!";
        }
    }
}

Error Message

TimerTriggerCSharp: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TimerTriggerCSharp'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'msg' to type String&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

Am I missing a step in the setup, or does the Service Bus binding really not support a string for an out parameter

1

1 Answers

7
votes

It looks like you're missing the binding attributes for ServiceBus. I've only used the ICollector<T> types rather than an out string but it shouldn't matter either way.

[FunctionName("TimerTriggerCSharp")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
                       TraceWriter log,
                       [ServiceBus("%QueueName%", Connection = "ServiceBusConnection", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Queue)] out string msg)
{
   msg = "My message";
}

To run locally with the VS2017 Preview tooling you will also need the following local settings defined in local.settings.json to match up with your ServiceBus attribute.

{
  "Values": {
     "ServiceBusConnection" : "Endpoint=sb://.....your connection",
     "QueueName": "my-service-bus-queue
   }
}