I am setting up an example where I have an Azure Function with a webhook that has an Azure Event Hub as a sink. There are two different consumer groups for this event hub, one of which is used by another Azure Function. The code doesn't do anything too fancy (excerpts are below), but I am observing an odd pattern. For every two messages published, only one appears to trigger the function once.
Publishing web hook:
module.exports = function (context, req) {
var statusCode = 400;
var responseBody = "Invalid request object";
if (typeof req.body != 'undefined' && typeof req.body == 'object') {
var eventInformation = req.body;
context.log("Received event: " + eventInformation);
context.bindings.outEvent = eventInformation;
statusCode = 200;
responseBody = "Event received.";
}
context.res = {
status: statusCode,
body: responseBody
};
context.done();
};
Receiving function:
module.exports = function (context, offerMadeEvent) {
var connection = new Connection(dbConfig); // Tedious connection
connection.on('connect', function(err) {
context.log('Connection established.');
// Somewhere in the database callbacks:
context.done();
});
};
Based on @Michael's the response from the "Comment" section above, the issue is related to a bug in the support for non-default consumer groups.
Background
A Function App instance is a process instance for all Functions inside the Function App. For a Function to execute, at least 1 Function App instance must be running.
Typically, a Function App instance is launched due to one of the following scenarios:
For Functions that are created under the Consumption Plan, the Function App instance will stay alive for 5 minutes. After 5 minutes, the Function App instance will idle out. Once the "last" Function App instance idles out, if Scenario #1 does not occur, then the Function will only be triggered by Scenario #2.
Issue
For EventHub triggers, the internal service is currently only listening for events on the default consumer group. It does not detect when there are new events arriving for other consumer groups and will not wake up the Function App.
This is a known issue and is actively being fixed. You may track the issue at https://github.com/Azure/Azure-Functions/issues/230