question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Imperative binding patterns

See original GitHub issue

I don’t know if it is possible but I would like to have a named parameter in my outputbinding like this:

{
  "type": "queue",
  "name": "queueoutput",
  "queueName": "{queuename}",
  "connection": "AzureWebJobsStorage",
  "direction": "out"
}

And have the code decide what queuename to use. Scenario is, rest call in -> route to correct queue which will trigger corresponding function.

Right now I have to add all queue’s declaratively, as you can imagine, it can grow exponentially so having the ability to define the desired queue code would help a lot!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
pragnagopacommented, Apr 5, 2019

@TylerLeonhardt - I have reopened https://github.com/Azure/azure-functions-host/issues/4207. yes, host should set typedData.json if the input data is infact json.

@bgelens -

Would it be possible if the queue would contain a json body, to refer to a key / nested key?

yes, you can. Please see https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#dot-notation

Here is an extension to the above example: Sample input data in queue1

{
  "input": {
    "name":"queue2",
    "Id":"3"
  }
}

Corresponding function.json to bind queuename to input.name for the outputbinding

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "queue1",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "{input.name}",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ]
}
2reactions
pragnagopacommented, Apr 5, 2019

You will not be able to set queuename for an output binding from within the function code. But Binding expressions allow you to use result from an input binding. Following sample shows how to specify queuename from an output binding from queueTrigger data

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "queue1",
      "connection": "AzureWebJobsStorage"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "{name}",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
  ]
}

Sample queue trigger data from queue with name queue1

{
  "name": "queue2",
  "Id": "5"
}

Now, you can set value for outputQueueItem for outputbinding which will be pushed to queue with name queue2

Hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Functions bindings expressions and patterns
NET languages, you can use an imperative binding pattern, as opposed to the declarative bindings in function.json and attributes.
Read more >
Azure Functions: Use imperative binding to control output ...
Azure Function is great, especially binding feature is awesome. But we need to control how binding work in run time, rather than compiled ......
Read more >
Azure Functions imperative bindings
Imperative binder pattern The imperative binder uses a pattern where you add the Binder object in the signature of your Run method. ·...
Read more >
Triggers and bindings in Azure Functions
Binding to a function is a way of declaratively connecting another resource to the function; bindings may be connected as input bindings, output ......
Read more >
Azure Function Triggers and Bindings
NET languages, you can use an imperative binding pattern, as opposed to the declarative bindings in function.json and attributes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found