skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search