Issue
I have a set of functions, some of which require environment-specific connections to Event Hubs, i.e., Function App A connects to Event Hub A, Function App B connects to Event Hub B. Given that the CD model uses branch-per-environment, how can I maintain the separate copies of function.json that drive that integration?
The dumb answer is, obviously, maintain a separate copy of function.json on each branch. This is dumb because that means "be really careful not to accidentally merge over top of your environment-specific copy and be really sorry when you forget". Ideally, there'd be something like maintaining environment specific copies, like function.DEV.json and function.QA.json. But this does not appear to be the case.
My function.json looks like this:
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "iot-e1-ehub-dev-deviceevents-01",
"connection": "iot-e1-ehub-dev-deviceevents-01_iothubroutes_iot-e1-iot-dev-01_EVENTHUB"
}
],
"disabled": false
}
So, those path and connection elements need to be different for each environment. If there's a way to manage that binding outside of function.json, I don't know about it.
Is there a better solution?
Solution
The better solution is to keep parameters of event hubs in App Settings, and put the name of those settings in function.json
without ever transforming it.
So, you should define your function.json
as
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "%eventHubPath%",
"connection": "eventHubConnection"
}
],
"disabled": false
}
and then define eventHubPath
and eventHubConnection
in portal App Settings / Connection Strings (and local.settings.json
if you are using local environment).
Answered By - Mikhail Shilkov Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.