How to create an Imperative Azure Queue Input Function
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
I have an Azure Function that looks like follows:
```csharp
namespace TestAzureFunction
{
[StorageAccount("TEST_STORAGE_ACCOUNT")]
public static class SendEmailTestQueue
{
[FunctionName(nameof(SendEmailTestQueue))]
public async static Task Run(
[QueueTrigger("send-email-test-queue-name")]SendEmailTestQueueModel model,
ILogger logger)
{
// SEND EMAIL
logger.LogInformation("Email Sent");
}
}
}
```
and the way i add messages to queue is as follows:
```csharp
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("** connectionString **");
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queueReference = queueClient.GetQueueReference("send-email-test-queue-name");
await queueReference.CreateIfNotExistsAsync();
SendEmailTestQueueModel model = new SendEmailTestQueueModel
{
Subject = "Email Subject",
Body = "Email Body"
}
CloudQueueMessage queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(model));
await queueReference.AddMessageAsync(queueMessage);
```
Now all that works fine.
### **How can I make the declaration of azure function above [imperative][1]?**
Below is my failed attempt:
```csharp
namespace TestAzureFunction
{
public static class SendEmailTestQueue
{
public async static Task Run(
Binder binder,
ILogger logger)
{
var attributes = new Attribute[]
{
new QueueTriggerAttribute("send-email-test-queue-name"),
new StorageAccountAttribute("TEST_STORAGE_ACCOUNT")
};
SendEmailTestQueueModel model = await binder.BindAsync(attributes);
// SEND EMAIL
logger.LogInformation("Email Sent");
}
}
```
[1]: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#binding-at-runtime
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.