-
Notifications
You must be signed in to change notification settings - Fork 11
Add Kafka event sourcing middleware #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aliok
wants to merge
18
commits into
knative-extensions:main
Choose a base branch
from
aliok:kafka-cloudevents-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c9c80a2
Add Kafka event sourcing middleware package
aliok 922dacc
Fix data race on responseEventWarned using sync.Once
aliok 0d6421b
Parse ce_dataschema as standard CE attribute in pass-through
aliok d50f078
Handle *DefaultHandler pointer in invokeHandler
aliok 608c28c
Validate handler signature at startup instead of first message
aliok 15d7f26
Move context.Context to first parameter in invokeHandler
aliok f06959a
Add unit tests for health handlers, CE pass-through, and consumeLoop
aliok b9d48bd
Cancel consumer context on shutdown so Sarama unblocks promptly
aliok d035e92
Recover from GetReceiverFn panic in validateHandler
aliok 446dd5d
Support content-type header for CE datacontenttype in Kafka pass-through
aliok 8c6cded
Use buffered stop channel with non-blocking sends
aliok e50d677
Add GoDoc comment to exported GetReceiverFn
aliok 6dfc999
Close listener when startInstance fails to prevent port leak
aliok eb2e72d
Log debug message when static config file is absent
aliok 52ebda9
Reject nil handler function in validateHandler
aliok c446904
Set explicit Sarama Kafka version to V2_0_0_0
aliok 6121435
Fix goimports and rename dummy to placeholder in tests
aliok ae16f93
Fix missing newline at end of cmd/fkafka/main.go
aliok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| cloudevents "github.com/cloudevents/sdk-go/v2/event" | ||
|
|
||
| "knative.dev/func-go/kafka" | ||
| ) | ||
|
|
||
| // Main illustrates how scaffolding works to wrap a user's function | ||
| // when the event source is Kafka. | ||
| // | ||
| // The function uses a standard CloudEvents handler signature. | ||
| // Kafka messages are automatically wrapped as CloudEvents by the runtime. | ||
| // | ||
| // Required environment variables: | ||
| // | ||
| // KAFKA_BROKERS — comma-separated broker addresses | ||
| // KAFKA_TOPIC — topic to consume from | ||
| // KAFKA_CONSUMER_GROUP — consumer group ID | ||
| func main() { | ||
| if err := kafka.Start(New()); err != nil { | ||
| fmt.Fprintln(os.Stderr, err.Error()) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| // MyFunction is an example instanced CloudEvents function that consumes | ||
| // from Kafka. | ||
| type MyFunction struct{} | ||
|
|
||
| func New() *MyFunction { | ||
| return &MyFunction{} | ||
| } | ||
|
|
||
| func (f *MyFunction) Handle(ctx context.Context, e cloudevents.Event) error { | ||
| fmt.Printf("Received event: type=%s source=%s id=%s\n", | ||
| e.Type(), e.Source(), e.ID()) | ||
| if e.Data() != nil { | ||
| fmt.Printf("Data: %s\n", string(e.Data())) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.