简体   繁体   中英

Multiple Azure WebJob functions on single queue message?

Our back-end is collecting raw data and pushing it to Azure Storage Queue. We would like to do two things with each queued message :

  1. Log/archive it
  2. Parse it and send the parsed result to a new queue

To keeps things small and clear, we would like to have two WebJob functions pointing to the same queue:

    public static void ArchiveRawData([QueueTrigger("raw")] RawData data, [Blob("{Ticks}.dat")] out string raw)
    {
        raw = data.Data;
    }

    public static void ParseRawData([QueueTrigger("raw")] RawData data, [Queue("result")] out Parsed parsedData
    {
        var parsed = Parser.Parse(data.Data);
        parsedData = parsed;
    }

But this doesn't work: Either the ArchiveRawData or ParseRawData gets the message, but not the other .

Is there an option somewhere which would make the above scenario work? It seems that the message is now automatically dequeued after the first function finishes (no matter which one). But I think the WebJobs SDK could detect that there are multiple functions with same QueueTrigger and it could dequeue the message only after all the functions have completed.

In order to get around this, we currently have two outputs in a single function:

    public static void ParseRawData([QueueTrigger("raw")] RawData data, [Queue("result")] out Parsed parsedData, [Blob("{Ticks}.dat")] out string raw)
    {
        var parsed = Parser.Parse(data.Data);
        parsedData = parsed;
        raw = data.Data;
    }                   

But as I said, we would like to keep things small and simple so it would be great if we could use separate function.

Unfortunately, the SDK does not support multiple functions listening to the same queue.

If you want multiple functions to be invoked, just create a few methods and make the webjob function the entry point. Then the webjob will call those functions.

Alternatively, you can have the second function listen to a different queue. The first queue, adds a message to this queue.

If you replace the Storage Queue with a ServiceBus Topic you can put two Subscriptions on it, one for each WebJob. Then each WebJob will get its own copy of every message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM