Client session with a high efficient and load balanced connection pool.
- Non exclusive, shared connection pool
- Making full use of the asynchronous communication advantages of each connection
- Load balancing mechanism of traffic level
- Real-time monitoring of connection status
import cliSession "github.com/henrylee2cn/tp-ext/mod-cliSession"
package cliSession_test
import (
"testing"
"time"
tp "github.com/henrylee2cn/teleport"
cliSession "github.com/henrylee2cn/tp-ext/mod-cliSession"
)
type Arg struct {
A int
B int `param:"<range:1:>"`
}
type P struct{ tp.PullCtx }
func (p *P) Divide(arg *Arg) (int, *tp.Rerror) {
return arg.A / arg.B, nil
}
func TestCliSession(t *testing.T) {
srv := tp.NewPeer(tp.PeerConfig{
ListenPort: 9090,
})
srv.RoutePull(new(P))
go srv.ListenAndServe()
time.Sleep(time.Second)
cli := cliSession.New(
tp.NewPeer(tp.PeerConfig{}),
":9090",
100,
time.Second*5,
)
go func() {
for {
t.Logf("%+v", cli.Stats())
time.Sleep(time.Millisecond * 500)
}
}()
go func() {
var result int
for i := 0; ; i++ {
rerr := cli.Pull("/p/divide", &Arg{
A: i,
B: 2,
}, &result).Rerror()
if rerr != nil {
t.Log(rerr)
} else {
t.Logf("%d/2=%v", i, result)
}
time.Sleep(time.Millisecond * 500)
}
}()
time.Sleep(time.Second * 6)
cli.Close()
time.Sleep(time.Second * 3)
}
test command:
go test -v -run=TestCliSession