Skip to content

Commit

Permalink
fixes rotuer invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhang Balkundi committed Mar 27, 2024
1 parent fd7af8c commit f9af7af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions example/sampleapp/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//go:build ignore

package main

import (
"context"
"fmt"

"github.com/gojekfarm/ziggurat/v2"
"github.com/gojekfarm/ziggurat/v2/kafka"
"github.com/gojekfarm/ziggurat/v2/logger"
Expand All @@ -17,19 +16,23 @@ func main() {
l := logger.NewLogger(logger.LevelInfo)

kcg := kafka.ConsumerGroup{
Logger: logger.NewLogger(logger.LevelInfo),
Logger: l,
GroupConfig: kafka.ConsumerConfig{
BootstrapServers: "g-gojek-id-mainstream.golabs.io:6668",
GroupID: "foo.id",
GroupID: "bar.id",
ConsumerCount: 1,
AutoOffsetReset: "earliest",
Topics: []string{"^.*-booking-log"},
},
}

if runErr := zig.Run(ctx, ziggurat.HandlerFunc(func(ctx context.Context, event *ziggurat.Event) {
router := ziggurat.NewRouter()
router.HandlerFunc("bar.id/.*", func(ctx context.Context, event *ziggurat.Event) {
fmt.Println("path:", event.RoutingPath)
}), &kcg); runErr != nil {
l.Error("error running consumers", runErr)
})

if runErr := zig.Run(ctx, router, &kcg); runErr != nil {
l.Error("error running streams", runErr)
}

}
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (r *Router) Handle(ctx context.Context, event *Event) {
path := event.RoutingPath
h, _ := r.match(path)
if h != nil {
return
h.Handle(ctx, event)
}
return
}
Expand Down
8 changes: 8 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func Test_match(t *testing.T) {
{pattern: "foo.id/foo/"},
},
},
{
name: "should not match similar consumer group names",
want: "bar.id/.*",
paths: []string{"bar.id/GO_BIRD_COMBO-booking-log/11"},
input: []routerEntry{
{pattern: "bar.id/.*"},
},
},
}

esToMap := func(es []routerEntry) map[string]routerEntry {
Expand Down

0 comments on commit f9af7af

Please sign in to comment.