4

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();

};
Graham
  • 7,431
  • 18
  • 59
  • 84
  • 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 delay – darnmason Oct 25 '18 at 03:28
  • 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 Oct 25 '18 at 05:39

1 Answers1

0

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 * * * *"
},
snowCrabs
  • 785
  • 5
  • 11
  • 1
    I think you've misunderstood the question. This isn't a Timer function, but a Scheduled Queue message. I don't want a recurring event, just a single event in the future using Service Bus, a different interval for each message.. – Graham Aug 22 '17 at 19:43