simplemq/cmd/rpccli/main.go

94 lines
1.9 KiB
Go
Raw Permalink Normal View History

2021-11-15 23:06:05 +00:00
package main
import (
"fmt"
2021-11-17 00:26:51 +00:00
"go.digitalcircle.com.br/open/simplemq/lib/smqcli"
"go.digitalcircle.com.br/open/simplemq/lib/types"
2021-11-15 23:06:05 +00:00
"log"
"runtime"
2021-11-15 23:06:05 +00:00
"time"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
2021-11-17 00:26:51 +00:00
c, err := smqcli.New("ws://localhost:8080/ws")
2021-11-15 23:06:05 +00:00
if err != nil {
panic(err.Error())
}
c.Sub("a", func(m *types.Msg) {
ret := fmt.Sprintf("==> Got %s at %s", string(m.Payload), time.Now().String())
log.Printf(ret)
c.RpcReply(m, []byte(ret))
})
c.Sub("ab.*", func(m *types.Msg) {
log.Printf("Got msg at %s: %s", m.Topic, string(m.Payload))
c.RpcReply(m, []byte(fmt.Sprintf("Got msg at %s: %s", m.Topic, string(m.Payload))))
})
c.Sub("c.*", func(m *types.Msg) {
//log.Printf("Got msg at %s: %s", m.Topic, string(m.Payload))
2021-11-15 23:06:05 +00:00
})
go func() {
for {
//bs, err := c.Rpc("ab01", []byte("A msg to AB01: "+time.Now().String()))
//if err != nil {
// log.Printf(err.Error())
//}
//log.Printf(string(bs))
//time.Sleep(time.Millisecond * 100)
}
}()
go func() {
for {
c.Pub("ca", []byte("A msg to CA: "+time.Now().String()))
//time.Sleep(time.Millisecond * 100)
}
}()
go func() {
for {
c.Pub("cb", []byte("A msg to CB: "+time.Now().String()))
//time.Sleep(time.Millisecond * 75)
}
}()
go func() {
for {
c.Pub("cc", []byte("A msg to CC: "+time.Now().String()))
//time.Sleep(time.Millisecond * 15)
}
}()
go func() {
for {
c.Pub("cd", []byte("A msg to CD: "+time.Now().String()))
//time.Sleep(time.Millisecond * 15)
}
}()
go func() {
for {
c.Pub("ce", []byte("A msg to CE: "+time.Now().String()))
//time.Sleep(time.Millisecond * 15)
2021-11-15 23:06:05 +00:00
}
}()
go func() {
for {
c.Pub("cf", []byte("A msg to CF: "+time.Now().String()))
//time.Sleep(time.Millisecond * 15)
}
}()
for {
//bs, err := c.Rpc("a", []byte("A Request"))
//if err != nil {
// log.Printf(err.Error())
//} else {
// log.Printf("Recv: %s", string(bs))
//}
time.Sleep(time.Minute)
2021-11-15 23:06:05 +00:00
}
}