[Feature] Add @azure/functions-extensions-kafka package for KafkaRecord binding

オープン
#103 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@TsuyoshiUshio がすでに取り組んでいます。

2026年4月24日 から。

  • #104 @TsuyoshiUshio による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
70/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
typescript

調査の方向性

まず azure-functions-nodejs-extensions-servicebus パッケージを読み、次に src/index.ts、kafka/registerKafkaRecordFactory.ts、kafka/kafkaRecordFactory.ts、util/kafkaRecordDecoder.ts にある一覧のエントリポイントをたどります。パッケージを実装しながら test/kafkaRecordFactory.test.ts を実行します。単一およびバッチの KafkaRecord 値が指定されたメタデータとともにデコードされ、AzureKafkaRecord に自動登録されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

Add a new @azure/functions-extensions-kafka package that enables Node.js users to bind to raw Apache Kafka records (KafkaRecord type) with full message metadata access (topic, partition, offset, key/value as Buffers, headers, timestamp, leader epoch).

This is the Node.js implementation of Azure/azure-functions-kafka-extension#612. The host-side Kafka Extension 4.3.1 and .NET Isolated Worker (PR #3356) are already complete.

Background

The host-side Kafka Extension (4.3.1) serializes IKafkaEventData to Protobuf and sends it as ModelBindingData with:

  • source: "AzureKafkaRecord"
  • content_type: "application/x-protobuf"
  • content: Protobuf-encoded KafkaRecordProto

The Node.js library already has a ResourceFactoryResolver singleton pattern (used by ServiceBus extensions) that auto-dispatches ModelBindingData to registered factories based on source. No changes needed to the library or worker — only a new extensions package.

Protobuf Schema

message KafkaRecordProto {
    string topic = 1;
    int32 partition = 2;
    int64 offset = 3;
    optional bytes key = 4;
    optional bytes value = 5;
    KafkaTimestampProto timestamp = 6;
    repeated KafkaHeaderProto headers = 7;
    optional int32 leader_epoch = 8;
    reserved 9 to 15;
}

message KafkaTimestampProto {
    int64 unix_timestamp_ms = 1;
    int32 type = 2; // 0=NotAvailable, 1=CreateTime, 2=LogAppendTime
}

message KafkaHeaderProto {
    string key = 1;
    optional bytes value = 2;
}

Required Changes

New package: azure-functions-nodejs-extensions-kafka/

Follow the azure-functions-nodejs-extensions-servicebus pattern exactly:

azure-functions-nodejs-extensions-kafka/
├── package.json
├── src/
│   ├── index.ts                              # Auto-registers factory on import
│   ├── kafka/
│   │   ├── kafkaRecordFactory.ts             # Protobuf decode + KafkaRecord build
│   │   └── registerKafkaRecordFactory.ts     # Register "AzureKafkaRecord" with ResourceFactoryResolver
│   └── util/
│       └── kafkaRecordDecoder.ts             # Protobuf binary decoder using protobufjs
├── types/
│   └── index.d.ts                            # KafkaRecord, KafkaHeader, KafkaTimestamp exports
└── test/
    └── kafkaRecordFactory.test.ts
File Description
registerKafkaRecordFactory.ts Register factory under key "AzureKafkaRecord" with ResourceFactoryResolver
kafkaRecordFactory.ts Decode Protobuf bytes from ModelBindingData.content, build KafkaRecord objects. Handle single and batch (array)
kafkaRecordDecoder.ts Use protobufjs to decode KafkaRecordProto from binary
types/index.d.ts TypeScript interfaces: KafkaRecord, KafkaHeader, KafkaTimestamp, KafkaTimestampType
index.ts Call registerKafkaRecordFactory() on module load (auto-registration pattern)
Dependencies
{
  "dependencies": {
    "@azure/functions-extensions-base": "^0.3.0",
    "protobufjs": "^7.0.0"
  }
}
No changes needed in other repos
Repo Changes
azure-functions-nodejs-library None — fromRpcTypedData.ts already dispatches modelBindingData via ResourceFactoryResolver
azure-functions-nodejs-worker None — worker is trigger-type agnostic

User Experience

import { KafkaRecord } from '@azure/functions-extensions-kafka';

app.generic('KafkaTrigger', {
    trigger: {
        type: 'kafkaTrigger',
        topic: 'my-topic',
        brokerList: '%BrokerList%',
        consumerGroup: '$Default',
    },
    handler: async (record: KafkaRecord, context) => {
        context.log(`Topic: ${record.topic}`);
        context.log(`Partition: ${record.partition}`);
        context.log(`Offset: ${record.offset}`);
        context.log(`Key: ${Buffer.from(record.key).toString('utf-8')}`);
        context.log(`Timestamp: ${new Date(record.timestamp.unixTimestampMs)}`);

        for (const header of record.headers) {
            context.log(`Header: ${header.key} = ${Buffer.from(header.value).toString('utf-8')}`);
        }
    },
});

Breaking Changes

None. This is a new package. All existing Kafka bindings (string, generic) continue to work.

Related Issues

主要言語
TypeScript
スター
2
フォーク
8
平均マージ
1時間 6分
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Azure/azure-functions-nodejs-extensions のほかの issue

Azure/azure-functions-nodejs-extensions の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。