问题
I want to do the same functionality (with few changes based on message data) from two different eventhubs.
Is it possible to attach two consumer group to a single function.
It did not work even though I add it to function.json.
回答1:
The short answer is no. You cannot bind multiple input triggers to the same function: https://github.com/Azure/azure-webjobs-sdk-script/wiki/function.json
A function can only have a single trigger binding, and can have multiple input/output bindings.
However, you can call the same "shared" code from multiple functions by either wrapping the shared code in a helper method, or using Precompiled Functions.
回答2:
Recommended practice here is to share business logic between functions by using the fact that a single function app can be composed of multiple functions.
MyFunctionApp
| host.json
|____ business
| |____ logic.js
|____ function1
| |____ index.js
| |____ function.json
|____ function2
|____ index.js
|____ function.json
In "function1/index.js" and "function2/index.js"
var logic = require("../business/logic");
module.exports = logic;
The function.json of function1 and function2 can be configured to different triggers.
In "business/logic.js
module.exports = function (context, req) {
// This is where shared code goes. As an example, for an HTTP trigger:
context.res = {
body: "<b>Hello World</b>",
status: 201,
headers: {
'content-type': "text/html"
}
};
context.done();
};
来源:https://stackoverflow.com/questions/46820498/multiple-azure-eventhub-trigger-to-single-function-in-azure-function-app