Skip to content

Conversation

Copy link

Copilot AI commented Nov 4, 2025

Adds Kafka consumer middleware following the existing patterns from cloudevents and http packages.

Implementation

Core Package (kafka/)

  • service.go - Kafka consumer with automatic CloudEvents detection (structured/binary mode) and raw message handling
  • instance.go - Handler interfaces supporting both Handle(context.Context, event.Event) and Handle(context.Context, kafka.Message) signatures
  • logs.go - Logging configuration matching existing packages
  • service_test.go - Tests for lifecycle, configuration parsing, and handler detection
  • mock/function.go - Test mock avoiding import cycles
  • README.md - Comprehensive documentation for the kafka package

Example Commands

Following the repository pattern of separate commands for different handler types:

cmd/fcekafka/main.go - CloudEvents handler example (similar to fce)

type MyFunction struct{}

func (f *MyFunction) Handle(ctx context.Context, e event.Event) (*event.Event, error) {
    fmt.Println("Instanced CloudEvents handler invoked")
    fmt.Println(e)
    return &e, nil
}

func main() {
    kafka.Start(New())
}

cmd/frawkafka/main.go - Raw message handler example (similar to fhttp)

type MyFunction struct{}

func (f *MyFunction) Handle(ctx context.Context, msg kafka.Message) error {
    fmt.Printf("Topic: %s, Partition: %d, Offset: %d\n", msg.Topic, msg.Partition, msg.Offset)
    fmt.Printf("Key: %s, Value: %s\n", string(msg.Key), string(msg.Value))
    return nil
}

func main() {
    kafka.Start(New())
}

Configuration

Environment variables:

  • KAFKA_BROKERS - Comma-separated broker list (default: localhost:9092)
  • KAFKA_TOPICS - Comma-separated topics (default: func-topic)
  • KAFKA_CONSUMER_GROUP - Consumer group ID (default: func-go-consumer)

Dependencies

Added github.com/segmentio/[email protected] - standard Go Kafka client with no known vulnerabilities.

Original prompt

This section details on the original issue you should resolve

<issue_title>Kafka middleware</issue_title>
<issue_description>Implement Kafka middleware.

With CloudEvents: similar to https://github.com/knative-extensions/func-go/blob/main/cmd/fce/main.go
With raw messages: similar to https://github.com/knative-extensions/func-go/blob/main/cmd/fhttp/main.go</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 4, 2025
@knative-prow
Copy link

knative-prow bot commented Nov 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please assign matzew for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1 similar comment
@knative-prow
Copy link

knative-prow bot commented Nov 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please assign matzew for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 4, 2025
Copilot AI changed the title [WIP] Implement Kafka middleware for CloudEvents and raw messages Implement Kafka middleware for CloudEvents and raw message handling Nov 4, 2025
Copilot AI requested a review from aliok November 4, 2025 12:49
Copilot finished work on behalf of aliok November 4, 2025 12:49
@aliok
Copy link
Member

aliok commented Nov 4, 2025

@copilot you should create 2 mains

  • cmd/fcekafka/main.go
  • cmd/frawkafka/main.go

Copy link
Author

Copilot AI commented Nov 4, 2025

@copilot you should create 2 mains

  • cmd/fcekafka/main.go
  • cmd/frawkafka/main.go
    ...

Done. Created separate commands:

  • cmd/fcekafka/main.go for CloudEvents handler (similar to fce)
  • cmd/frawkafka/main.go for raw message handler (similar to fhttp)

Removed the old cmd/fkafka directory and updated .gitignore accordingly.

Commit: 2ba569f

Copilot finished work on behalf of aliok November 4, 2025 13:05
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2025
@knative-prow-robot
Copy link

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kafka middleware

3 participants