2

I'm trying to do some Proof of Concept with EventHub and Azure Functions. I have a Generic Webhook Function in C# that I want to pass a message to my EventHub.

I get stuck on the parameter name given on the "Integrate" tab. If I declare that name among the parameters I have to give it a type. I can't figure out what kind of type though... I've tried:

  • String (other functions uses that together with the direction, not applicable with webhooks).
  • EventData
  • IEnumerable

I can't get it to work. If I don't do this I get the error message: "Missing binding argument named 'outputEventHubMessage'"

If I give it the wrong type I get the message: "Error indexing method 'Functions.GenericWebhookCSharp1'. Microsoft.Azure.WebJobs.Host: Can't bind to parameter."

I'm probably a bit lost in documentation or just a bit tired, but I'd appreciate any help here!

/Joakim

1 Answer 1

3

Likely you're just missing the out keyword on your parameter. Below is a working WebHook function that declares an out string message parameter that is mapped to the EventHub output, and writes an EventHub message via message = "Test Message".

Because async functions can't return out parameters, I made this function synchronous (returning an object rather than Task<object>). If you want to remain async, rather than use an out parameter, you can instead bind to an IAsyncCollector<string> parameter. You can then enqueue one or more messages by calling the AddAsync method on the collector.

More details on the EventHub binding and the types it supports can be found here. Note that the other bindings follow the same general patterns.

#r "Newtonsoft.Json"

using System;
using System.Net;
using Newtonsoft.Json;

public static object Run(HttpRequestMessage req, out string message, TraceWriter log)
{
    string jsonContent = req.Content.ReadAsStringAsync().Result;
    dynamic data = JsonConvert.DeserializeObject(jsonContent);

    log.Info($"Webhook was triggered! Name = {data.first}");

    message = "Test Message";

    var res = req.CreateResponse(HttpStatusCode.OK, new {
        greeting = $"Hello {data.first} {data.last}!"
    });

    return res;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That did the trick. Thanks a lot! I was really wondering abut the asynchronous part and thought I had to work with that. Now I can see my messages coming in to my EventHub and can move on to the next bit in my PoC! Many thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.