4
votes

I have an Azure Function written in node.js that is successfully sending a message to an Azure Service Bus Queue using an output binding.

How can I send a scheduled message into the same Queue still using the binding syntax? I'd rather do this without installing the node.js sdk if at all possible.

The binding documentation doesn't mention scheduled messages. However, interestingly enough this comment has been made a few times on the Functions github issues repository:

At least with C# & Node.js (and why not in F#) the Service Bus queue output already supports this e.g. if you create and put multiple messages e.g. to IAsyncCollector or create out BrokeredMessage. Within your outgoing message(s) you can control the scheduled enqueuing time:

outgoingMessage.ScheduledEnqueueTimeUtc = DateTimeOffset.UtcNow.AddSeconds(10)

Anyway, here's my current code that is working fine for immediately delivering a message:

function.json

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "name" : "queueOutput",
      "queueName" : "scheduler",
      "connection" : "AZURE_SERVICEBUS_CONNECTION_STRING",
      "type" : "serviceBus",
      "direction" : "out"
    }
  ]
}

index.js

module.exports = function (context, req) {

  context.log('Scheduler function processed a request.');

  context.bindings.queueOutput = req.body;

  context.res = {
    "status": 200,
    "body": {
      "message": "Successfully sent message to Queue"
    } 
  };

  context.done();

};
1
Did you solve this? I want to do the same but with Azure Storage Queue. In terms of bindings it looks the same, I can assign an array to the binding variable but don't think I can specify the initial visibility delaydarnmason
No, we never did solve this. It seems as though queues are really just meant for no-response back-end processing. We still use them, just not for any web responses.Graham

1 Answers

0
votes

What about using the time based trigger syntax (CRON scheduling)... Assuming I haven't misunderstood the question

{
  "name": "function",
  "type": "timerTrigger",
  "direction": "in",
  "schedule": "0 */5 * * * *"
},