private
private

Reputation: 1

Is it possible that 2 azure functions can get triggered by one eventhub?

Is it possible that 2 azure functions can get triggered by one eventhub? One azure function will write its data to database1 and the other azure function writes its data to database2

[FunctionName("EventToDB1")]
public async System.Threading.Tasks.Task Run([EventHubTrigger("eventhub", Connection = "Debezium")]  
    EventData[] events, ILogger log)
    {
       
            {
[FunctionName("EventToDB2")]
public async System.Threading.Tasks.Task Run([EventHubTrigger("eventhub", Connection = "Debezium")]  
        EventData[] events, ILogger log)
     {
        
            {

answer on the possibility of having 2 azure functions get triggered by one eventhub

Upvotes: 0

Views: 527

Answers (2)

RithwikBojja
RithwikBojja

Reputation: 11183

I do agree with @peter bons, you need to create two consumer groups for that and you can create two consumers by below process:

enter image description here

You can also use logic apps to work with event hubs.

Upvotes: 0

Peter Bons
Peter Bons

Reputation: 29770

Yes that is possible by using different consumer groups. Because you specified the same connection to the Event Hub, being "Debezium", I Assume you want both funtions to process the same message. You have to create a new consumer group and specify the name using the ConsumerGroup property of the EventHubTrigger attribute (The default consumergroup is $Default):

public class EventToDB1
{
    [FunctionName("EventToDB1")]
    public async System.Threading.Tasks.Task Run(
            [EventHubTrigger("eventhub",
        Connection = "Debezium",
        ConsumerGroup = "CG1")]
        EventData[] events, ILogger log)
    {

    }
}

public class EventToDB2
{
    [FunctionName("EventToDB2")]
    public async System.Threading.Tasks.Task Run(
        [EventHubTrigger("eventhub",
        Connection = "Debezium",
        ConsumerGroup = "CG2")]
        EventData[] events, ILogger log)
    {

    }
}

Each consumer group receives the same messages from the Event Hub.

Upvotes: 1

Related Questions