Skip to content

Commit

Permalink
feat: add gatewat util tool
Browse files Browse the repository at this point in the history
  • Loading branch information
wenfengwang committed Apr 25, 2022
1 parent 47b38c5 commit 8c6e9c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@

# data dir of etcd
etcd
bin
bin

*.xml
2 changes: 1 addition & 1 deletion internal/gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "github.com/linkall-labs/vanus/internal/primitive"

type Config struct {
Port int `yaml:"port"`
ControllerAddr []string `yaml:"controller"`
ControllerAddr []string `yaml:"controllers"`
}

func InitConfig(filename string) (*Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (ga *ceGateway) receive(ctx context.Context, event v2.Event) protocol.Resul
}

vrn := fmt.Sprintf("vanus://%s/eventbus/%s?controllers=%s", ga.config.ControllerAddr[0],
strings.Join(ga.config.ControllerAddr, ","), ebName)
ebName, strings.Join(ga.config.ControllerAddr, ","))
v, exist := ga.busWriter.Load(vrn)
if !exist {
writer, err := eb.OpenBusWriter(vrn)
Expand Down
13 changes: 5 additions & 8 deletions test/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ var (

func main() {
flag.Parse()
fmt.Printf("params: %s=%s", "addr", *addr)
fmt.Printf("params: %s=%s", "eb", *eb)
fmt.Printf("params: %s=%d", "num", *num)
fmt.Printf("params: %s=%d", "size", *size)
fmt.Printf("params: %s=%s\n", "addr", *addr)
fmt.Printf("params: %s=%s\n", "eb", *eb)
fmt.Printf("params: %s=%d\n", "num", *num)
fmt.Printf("params: %s=%d\n", "size", *size)

ctx := cloudevents.ContextWithTarget(context.Background(), fmt.Sprintf("http://%s/gateway/%s", *addr, *eb))

Expand Down Expand Up @@ -56,15 +56,12 @@ func main() {
})

res := c.Send(ctx, e)
if res.Error() != "" {
panic(fmt.Sprintf("send event failed: %s", res.Error()))
}
if cloudevents.IsUndelivered(res) {
log.Printf("Failed to send: %v", res)
} else {
var httpResult *cehttp.Result
cloudevents.ResultAs(res, &httpResult)
log.Printf("Sent %d with status code %d", i, httpResult.StatusCode)
log.Printf("Sent %d with status code %d, body: %s", i, httpResult.StatusCode, httpResult.Error())
}
}
}

0 comments on commit 8c6e9c3

Please sign in to comment.