diff --git a/examples/consumer-confirm/main.go b/examples/consumer-confirm/main.go deleted file mode 100644 index 1cb45cc..0000000 --- a/examples/consumer-confirm/main.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log/slog" - "time" - - "ella.to/bus" - "ella.to/bus/client" -) - -func main() { - slog.SetLogLoggerLevel(slog.LevelDebug) - - const confirmRequired = 2 - - c, err := client.New(client.WithAddr("http://localhost:2021")) - if err != nil { - panic(err) - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - for i := range confirmRequired { - go func() { - defer func() { - slog.Debug("closing consumer", "consumer", i) - }() - - for msg, err := range c.Get(ctx, bus.WithSubject("a.b.c"), bus.WithFromOldest()) { - if err != nil { - fmt.Println(msg, err) - } - } - }() - } - - evt, err := bus.NewEvent(bus.WithSubject("a.b.c"), bus.WithData([]byte("hello"))) - if err != nil { - panic(err) - } - - err = c.Put(ctx, evt) - if err != nil { - panic(err) - } - - cancel() - - time.Sleep(1 * time.Second) -} diff --git a/examples/request-reply-single/main.go b/examples/request-reply-single/main.go deleted file mode 100644 index be07d12..0000000 --- a/examples/request-reply-single/main.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - - "ella.to/bus" - "ella.to/bus/client" -) - -type Req struct { - A int - B int -} - -func (r *Req) String() string { - return fmt.Sprintf("func.div(%d, %d)", r.A, r.B) -} - -type Resp struct { - Result int -} - -func (r *Resp) String() string { - return fmt.Sprintf("%d", r.Result) -} - -func main() { - c, err := client.New(client.WithAddr("http://localhost:2021")) - if err != nil { - panic(err) - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - funcName := "func.div" - - bus.Reply(ctx, c, funcName, func(ctx context.Context, in json.RawMessage) (any, error) { - fmt.Println("Got a request") - - req := &Req{} - err := json.Unmarshal(in, req) - if err != nil { - return nil, err - } - - if req.B == 0 { - return nil, fmt.Errorf("division by zero") - } - return &Resp{Result: req.A / req.B}, nil - }) - - fn := bus.Request(c, funcName) - - for range 1000 { - req := &Req{A: 4, B: 2} - resp := &Resp{} - rawResp, err := fn(ctx, req) - if err != nil { - fmt.Printf("%s = %s\n", req, err) - } else { - json.Unmarshal(rawResp, resp) - fmt.Printf("%s = %s\n", req, resp) - } - } -} diff --git a/examples/request-reply/data/data.go b/examples/request-reply/data/data.go deleted file mode 100644 index c0a8793..0000000 --- a/examples/request-reply/data/data.go +++ /dev/null @@ -1,20 +0,0 @@ -package data - -import "fmt" - -type Req struct { - A int - B int -} - -func (r *Req) String() string { - return fmt.Sprintf("func.div(%d, %d)", r.A, r.B) -} - -type Resp struct { - Result int -} - -func (r *Resp) String() string { - return fmt.Sprintf("%d", r.Result) -} diff --git a/examples/request-reply/reply/main.go b/examples/request-reply/reply/main.go deleted file mode 100644 index 0a0e836..0000000 --- a/examples/request-reply/reply/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - - "ella.to/bus" - "ella.to/bus/client" - - "ella.to/bus/examples/request-reply/data" -) - -func main() { - c, err := client.New(client.WithAddr("http://localhost:2021")) - if err != nil { - panic(err) - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - bus.Reply(ctx, c, "func.div", func(ctx context.Context, in json.RawMessage) (any, error) { - fmt.Println("Got a request") - - req := &data.Req{} - err := json.Unmarshal(in, req) - if err != nil { - return nil, err - } - - if req.B == 0 { - return nil, fmt.Errorf("division by zero") - } - return &data.Resp{Result: req.A / req.B}, nil - }) - - select {} -} diff --git a/examples/request-reply/request/main.go b/examples/request-reply/request/main.go deleted file mode 100644 index c60583a..0000000 --- a/examples/request-reply/request/main.go +++ /dev/null @@ -1,36 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - - "ella.to/bus" - "ella.to/bus/client" - - "ella.to/bus/examples/request-reply/data" -) - -func main() { - c, err := client.New(client.WithAddr("http://localhost:2021")) - if err != nil { - panic(err) - } - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - fn := bus.Request(c, "func.div") - - for range 1000 { - req := &data.Req{A: 4, B: 2} - resp := &data.Resp{} - rawResp, err := fn(ctx, req) - if err != nil { - fmt.Printf("%s = %s\n", req, err) - } else { - json.Unmarshal(rawResp, resp) - fmt.Printf("%s = %s\n", req, resp) - } - } -}