Created
February 21, 2018 07:40
-
-
Save beachside-project/4db7aa5d429d6d75c893654bc5d81021 to your computer and use it in GitHub Desktop.
azure functions - binder demo: queue imperative binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 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
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: