Reputation: 1041
I am building a continuous job that listens for Azure queue messages. Using the documentation I have something like this:
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment("development");
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
public static void Run(
[QueueTrigger("myqueue-items")] string myQueueItem,
ILogger log)
{
...
}
I'm not a fan of the magic QueueTrigger
attribute found at runtime. Is it possible to add a trigger function manually? I'm imagining something like:
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment("development");
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddQueueListener("myqueue-items", Run); // no magic attributes, compiler error if Run function is deleted
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
public static void Run(
string myQueueItem,
ILogger log)
{
...
}
Upvotes: 0
Views: 294
Reputation: 9511
Yes, you can use manual triggers, you don’t need to use QueueTrigger
attribute, but, as described in the document: To trigger a function manually, use the NoAutomaticTrigger
attribute.
Therefore, I think whether you are using Automatic triggers or Manual triggers, you must add a trigger with attributes, which is necessary!
Upvotes: 2