diff options
Diffstat (limited to 'plugins/broadcast/root/tests/go-client.go')
-rw-r--r-- | plugins/broadcast/root/tests/go-client.go | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/plugins/broadcast/root/tests/go-client.go b/plugins/broadcast/root/tests/go-client.go deleted file mode 100644 index 21442a01..00000000 --- a/plugins/broadcast/root/tests/go-client.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/spiral/broadcast/v2" - rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/service/rpc" - "golang.org/x/sync/errgroup" -) - -type logService struct { - broadcast *broadcast.Service - stop chan interface{} -} - -func (l *logService) Init(service *broadcast.Service) (bool, error) { - l.broadcast = service - - return true, nil -} - -func (l *logService) Serve() error { - l.stop = make(chan interface{}) - - client := l.broadcast.NewClient() - if err := client.SubscribePattern("tests/*"); err != nil { - return err - } - - logFile, _ := os.Create("log.txt") - - g := &errgroup.Group{} - g.Go(func() error { - for msg := range client.Channel() { - _, err := logFile.Write([]byte(fmt.Sprintf( - "%s: %s\n", - msg.Topic, - string(msg.Payload), - ))) - if err != nil { - return err - } - - err = logFile.Sync() - if err != nil { - return err - } - } - return nil - }) - - <-l.stop - err := logFile.Close() - if err != nil { - return err - } - - err = client.Close() - if err != nil { - return err - } - - return g.Wait() -} - -func (l *logService) Stop() { - close(l.stop) -} - -func main() { - rr.Container.Register(rpc.ID, &rpc.Service{}) - rr.Container.Register(broadcast.ID, &broadcast.Service{}) - rr.Container.Register("log", &logService{}) - - rr.Execute() -} |