0

I have written an azure function which consumes a message from event hub using event hub trigger and push to it to Kafka topic using output binding using typescript. The message is getting consumed but while trying to send it, I am getting this error

msg failed to send on topic ::

I tried configuring both the event hub trigger and Kafka output binding in the same function.json. In the method, I tried to consume the msg, do schema validation and them tried to place the message in the output like this.

kafka.bindings.outputKafkaMessage = msg;

But I am getting the above mentioned error. I have verified all my configuration related to Kafka output binding.

1
  • Please put your code so others can know and recreate what you've done already. Commented Jun 10, 2023 at 1:10

1 Answer 1

0

I referred the below github sample and to use Eventhub cluster Kafka as Output binding of Azure Event Hub function and the messages where sent to the Event Hub cluster kafka successfully, Make sure you go through the above github samples for more insights.

Created a sample Typescript Event Hub Function like below:-

I have used different Eventhub namespace in Input binding and Eventhub cluster kafka namespace as Output binding. You can use the same EventHub cluster with Kafka for Input and Output Binding:-

my index.ts:-


import { AzureFunction, Context } from "@azure/functions"

const eventHubTrigger: AzureFunction = async function (context: Context, eventHubMessages: any[]): Promise<void> {
    context.log(`Eventhub trigger function called for message array ${eventHubMessages}`);
    const responseMessage = 'Ok'
    // context.bindings.outputKafkaMessage = eventHubMessages
    
    eventHubMessages.forEach((message, index) => {
        context.log(`Processed message ${message}`);
        context.bindings.outputKafkaMessage = message
    
    });
    
};
export default eventHubTrigger;

My function.json:-

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "eventHubMessages",
      "direction": "in",
      "eventHubName": "ceventhub",
      "connection": "cPolicy_EVENTHUB",
      "cardinality": "many",
      "consumerGroup": "$Default",
      "dataType": "string"
    },
    {
      "type": "kafka",
      "direction": "out",
      "name": "eventData",
      "brokerList": "example_APPSETTING",
      "topic": "topic",
      "username": "$ConnectionString",
      "password": "example_APPSETTING",
      "protocol": "NOTSET",
      "authenticationMode": "NOTSET"
    }
  ],
  "scriptFile": "../dist/EventHubTrigger1/index.js"
}

enter image description here

Sent a message to Event Hub by the sample code from here

Azure EventHub Trigger was successful, Refer below:-

enter image description here

Now, when I checked my EventHub Cluster with Kafka enabled, I got the request of these messages successfully, Refer below:-

enter image description here

In order to create EventHub Cluster with Kafka and consume messages, Refer this Document step by step.

Example with same EventHub cluster with Kafka:-

Index.ts remains same, My function.json:-

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "eventHubMessages",
      "direction": "in",
      "eventHubName": "ev1",
      "connection": "evhbnameosc43_RootManageSharedAccessKey_EVENTHUB",
      "cardinality": "many",
      "consumerGroup": "$Default",
      "dataType": "string"
    },
    {
      "type": "kafka",
      "direction": "out",
      "name": "eventData",
      "brokerList": "example_APPSETTING",
      "topic": "ev1",
      "username": "$ConnectionString",
      "password": "example_APPSETTING",
      "protocol": "NOTSET",
      "authenticationMode": "NOTSET"
    }
  ],
  "scriptFile": "../dist/EventHubTrigger1/index.js"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.