Reputation: 395
In VS I have created a continuous type web job. My web job SDK is 3.0.14. I could write a timerTribber however none of the bindings for blob/queue is available. What am I missing? Below is the code. I an on .NET 4.7.2. WHen I compile I get the error "error CS0404: Cannot apply attribute class 'Queue' because it is generic"
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
namespace WebJob2
{
public class Functions
{
// This function will get triggered every Min
public static void ProcessEveryMin([TimerTrigger("0 * * * * *", RunOnStartup = true)] TimerInfo timerTriggerInfo,
[Queue("queue1")] string message, TextWriter log)
{
message = "NextRun on " + timerTriggerInfo.Schedule.GetNextOccurrence(DateTime.Now).ToString();
log.WriteLine(message);
}
}
}
Upvotes: 0
Views: 206
Reputation: 14324
Firstly I don't know you want to write message to queue or read from queue, you are trying to get the message from queue however you assign other value to the message.
Then is about how to bind Queue to webjob. The below is my Program.cs main method. If you want to use Queue binding you need AddAzureStorageCoreServices()
and AddAzureStorage()
.
static void Main(string[] args)
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddTimers();
b.AddAzureStorage();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
var host = builder.Build();
using (host)
{
host.Run();
}
}
And below is my Function.cs.
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Queue;
namespace ConsoleApp68
{
public class Functions
{
public static async Task ProcessEveryMinAsync([TimerTrigger("0 * * * * *", RunOnStartup = true)] TimerInfo timerTriggerInfo,
[Queue("myqueue") ] CloudQueue queue, ILogger logger)
{
logger.LogInformation("NextRun on " + timerTriggerInfo.Schedule.GetNextOccurrence(DateTime.Now).ToString());
CloudQueueMessage message= await queue.GetMessageAsync();
logger.LogInformation(message.AsString);
await queue.DeleteMessageAsync(message);
CloudQueueMessage testmessage = new CloudQueueMessage("test message");
await queue.AddMessageAsync(testmessage);
}
}
}
Here is my test result pic.
Upvotes: 1