37 lines
614 B
Go
37 lines
614 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"simplemq/lib/client"
|
|
"simplemq/lib/types"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
c, err := client.New("ws://localhost:8080/ws")
|
|
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 wildcard")
|
|
})
|
|
|
|
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.Second)
|
|
}
|
|
}
|