Skip to content

Instantly share code, notes, and snippets.

@beachside-project
Created February 21, 2018 07:40
Show Gist options
  • Save beachside-project/4db7aa5d429d6d75c893654bc5d81021 to your computer and use it in GitHub Desktop.
Save beachside-project/4db7aa5d429d6d75c893654bc5d81021 to your computer and use it in GitHub Desktop.
azure functions - binder demo: queue imperative binding
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading.Tasks;
namespace BinderDemo
{
public static class Function1
{
private const string OutputQueueName = "output";
[FunctionName("queueBind")]
public static async Task Run([QueueTrigger("input4queue")]string message, Binder binder, TraceWriter log)
{
log.Info($"RunQueueBind1 called; input: {message}");
var attribute = new QueueAttribute(OutputQueueName);
var queue = await binder.BindAsync<CloudQueue>(attribute);
await queue.AddMessageAsync(new CloudQueueMessage(message));
}
[FunctionName("queueBind2")]
public static async Task RunQueueBind2([QueueTrigger("input", Connection = "MyQueue")]string message, Binder binder, TraceWriter log)
{
log.Info($"RunQueueBind2 called; input: {message}");
var attributes = new Attribute[]
{
new QueueAttribute(OutputQueueName),
new StorageAccountAttribute("MyQueue")
};
var queue = await binder.BindAsync<CloudQueue>(attributes);
await queue.AddMessageAsync(new CloudQueueMessage(message));
}
//以下略...
@psheldon
Copy link

psheldon commented Jul 10, 2019

The second function, "queueBind2", appears to be incorrect. I get a compile error due to there being no overload of BindAsync that takes an array of Attribute:

namespace Microsoft.Azure.WebJobs
{
    public interface IBinder
    {
        Task<T> BindAsync<T>(Attribute attribute, CancellationToken cancellationToken = default(CancellationToken));
    }
}

@cpoDesign
Copy link

@psheldon, you are correct, this is quite old, but I am posting this in case someone else needs to figure it out too

   `     var attribute = new QueueAttribute(queueToPostInto)
        {
            Connection = "MyQueue"
        };

        var queue = await binder.BindAsync<CloudQueue>(attribute);
        await queue.AddMessageAsync(new CloudQueueMessage(message));`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment