Multiple Azure EventHub trigger to single function in Azure Function app

不问归期 提交于 2019-12-07 14:51:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!