dueๆฏไธๆฌพๅบไบGo่ฏญ่จๅผๅ็่ฝป้็บงๅๅธๅผๆธธๆๆๅกๅจๆกๆถใ ๅ ถไธญ๏ผๆจกๅ่ฎพ่ฎกๆน้ขๅ้ดไบkratos็ๆจกๅ่ฎพ่ฎกๆ่ทฏ๏ผไธบๅผๅ่ ๆไพไบ่พไธบ็ตๆดป็้็พคๆๅปบๆนๆกใ
- ็ฎๅๆง๏ผๆถๆ็ฎๅ๏ผๆบ็ ็ฎๆดๆ็่งฃใ
- ไพฟๆทๆง๏ผไป ๆด้ฒๅฟ ่ฆ็่ฐ็จๆฅๅฃ๏ผๅ่ฝปๅผๅ่ ็ๅฟๆบ่ดๆ ใ
- ้ซๆง่ฝ๏ผๆกๆถๅ็ๅฎ็ฐ้็พค้ไฟกๆนๆก๏ผๆฎ้ๆบๅจๅ็บฟ็จไน่ฝ่ฝปๆพๅฎ็ฐ20W็TPSใ
- ้ซๆๆง๏ผๆกๆถๅ็ๆไพtcpใkcpใws็ญๅ่ฎฎ็ๆๅกๅจ๏ผๆนไพฟๅผๅ่ ๅฟซ้ๆๅปบๅ็ง็ฑปๅ็็ฝๅ ณๆๅกๅจใ
- ๆฉๅฑๆง๏ผ้็จ่ฏๅฅฝ็ๆฅๅฃ่ฎพ่ฎก๏ผๆนไพฟๅผๅ่ ่ฎพ่ฎกๅฎ็ฐ่ชๆๅ่ฝใ
- ๅนณๆปๆง๏ผๅผๅ ฅไฟกๅท้๏ผ้่ฟๆงๅถๆๅกๆณจๅไธญๅฟๆฅๅฎ็ฐไผ้ ๅฐๆปๅจๆดๆฐใ
- ๆฉๅฎนๆง๏ผ้่ฟไผ้ ็่ทฏ็ฑๅๅๆบๅถ๏ผ็่ฎบไธๅฏๅฎ็ฐๆ ้ๆฉๅฎนใ
- ๆ่ฐ่ฏ๏ผๆกๆถๅ็ๆไพไบtcpใkcpใws็ญๅ่ฎฎ็ๅฎขๆท็ซฏ๏ผๆนไพฟๅผๅ่ ่ฟ่ก็ฌ็ซ็่ฐ่ฏๅ จๆต็จ่ฐ่ฏใ
- ๅฏ็ฎก็๏ผๆไพๅฎๅ็ๅๅฐ็ฎก็ๆฅๅฃ๏ผๆนไพฟๅผๅ่ ๅฟซ้ๅฎ็ฐ่ชๅฎไน็ๅๅฐ็ฎก็ๅ่ฝใ
- ็ฝๅ ณ๏ผๆฏๆtcpใkcpใws็ญๅ่ฎฎ็็ฝๅ ณๆๅกๅจใ
- ๆฅๅฟ๏ผๆฏๆstdใzapใlogrusใaliyunใtencent็ญๅค็งๆฅๅฟ็ปไปถใ
- ๆณจๅ๏ผๆฏๆconsulใetcdใnacos็ญๅค็งๆๅกๆณจๅไธญๅฟใ
- ๅ่ฎฎ๏ผๆฏๆjsonใprotobufใmsgpack็ญๅค็ง้ไฟกๅ่ฎฎใ
- ้ ็ฝฎ๏ผๆฏๆconsulใetcdใnacos็ญๅค็ง้ ็ฝฎไธญๅฟ๏ผๅนถๆฏๆjsonใyamlใtomlใxml็ญๅค็งๆไปถๆ ผๅผใ
- ้ไฟก๏ผๆฏๆgrpcใrpcx็ญๅค็ง้ซๆง่ฝ้ไฟกๆนๆกใ
- ้ๅฏ๏ผๆฏๆๆๅกๅจ็ๅนณๆป้ๅฏใ
- ไบไปถ๏ผๆฏๆredisใnatsใkafkaใrabbitMQ็ญไบไปถๆป็บฟๅฎ็ฐๆนๆกใ
- ๅ ๅฏ๏ผๆฏๆrsaใecc็ญๅค็งๅ ๅฏๆนๆกใ
- ๆๅก๏ผๆฏๆgrpcใrpcx็ญๅค็งๅพฎๆๅก่งฃๅณๆนๆกใ
- ็ตๆดป๏ผๆฏๆๅไฝใๅๅธๅผ็ญๅค็งๆถๆๆนๆกใ
- ็ฎก็๏ผๆไพmasterๅๅฐ็ฎก็ๆ็ธๅ ณๆฅๅฃๆฏๆใ
- Web๏ผๆไพhttpๅ่ฎฎ็fiberๆๅกๅจๅswaggerๆๆกฃ่งฃๅณๆนๆกใ
- ๅทฅๅ ท๏ผๆไพdue-cli่ๆๆถๅทฅๅ ท็ฎฑ๏ผๅฏๅฟซ้ๆๅปบ้็พค้กน็ฎใ
- Actor๏ผๆไพๅฎๅactorๆจกๅ่งฃๅณๆนๆกใ
- ๅฎ็ฐๆกๆถๅฑ็ๅๅธๅผ้
ๅจdueไบคๆต็พคไธญ็ปๅธธๆๅฐไผไผดๆๅๅฐGateใNodeใMeshไน้ดๅฐๅบๆฏไธชไปไนๅ ณ็ณป๏ผ่ฟ้ๅฐฑๅไธไธช็ปไธ็่งฃ็ญ
- Gate๏ผ็ฝๅ ณๆ๏ผไธป่ฆ็จไบ็ฎก็ๅฎขๆท็ซฏ่ฟๆฅ๏ผๆฅๆถๅฎขๆท็ซฏ็่ทฏ็ฑๆถๆฏ๏ผๅนถๅๅ่ทฏ็ฑๆถๆฏๅฐไธๅ็็Node่็นๆใ
- Node: ่็นๆ๏ผไฝไธบๆดไธช้็พค็ณป็ป็ๆ ธๅฟ็ปไปถ๏ผไธป่ฆ็จไบๆ ธๅฟ้ป่พไธๅก็็ผๅใNode่็นๆๅกๅฏไปฅๆ นๆฎไธๅก้่ฆๅๆๆ็ถๆๆๆ ็ถๆ็่็น๏ผๅฝไฝไธบๆ ็ถๆ็่็นๆถ๏ผNode่็นไธMeshๅพฎๆๅกๅบๆฌๆ ๅผ๏ผไฝๅฝNode่็นไฝไธบๆ็ถๆ่็นๆถ๏ผNode่็นไพฟไธ่ฝ้ๆๆดๆฐ่ฟ่ก้ๅฏๆไฝใๆ ่NodeไธMeshๅ็ฆป็ไธๅกๅบๆฏ็ไปทๅผๅฐฑไฝ็ฐๅบๆฅไบใ
- Mesh๏ผๅพฎๆๅก๏ผไธป่ฆ็จไบๆ ็ถๆ็ไธๅก้ป่พ็ผๅใMesh่ฝๅ็ๅ่ฝNodeไธๆ ทๅฏไปฅๅฎๆ๏ผๅฆไฝ้ๆฉๅฎๅ จๅๅณไบ่ช่บซไธๅกๅบๆฏ๏ผๅผๅ่ ๅฏไปฅๆ นๆฎ่ช่บซไธๅกๅบๆฏ็ตๆดปๆญ้ ใ
- Master๏ผ็ฎก็ๆ๏ผไธป่ฆ็จไบGMๅๅฐ็ฎก็ๅ่ฝ็ๅผๅใ
ๅจdueๆกๆถไธญ๏ผ้ไฟกๅ่ฎฎ็ปไธ้็จsize+header+route+seq+message็ๆ ผๅผ๏ผ
1.ๆฐๆฎๅ
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+---------------------------------------------------------------+-+-------------+-------------------------------+-------------------------------+
| size |h| extcode | route | seq |
+---------------------------------------------------------------+-+-------------+-------------------------------+-------------------------------+
| message data ... |
+-----------------------------------------------------------------------------------------------------------------------------------------------+
2.ๅฟ่ทณๅ
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+---------------------------------------------------------------+-+-------------+---------------------------------------------------------------+
| size |h| extcode | heartbeat time (ns) |
+---------------------------------------------------------------+-+-------------+---------------------------------------------------------------+
size: 4 bytes
- ๅ ้ฟๅบฆไฝ
- ๅบๅฎ้ฟๅบฆไธบ4ๅญ่๏ผไธไธๅฏไฟฎๆน
header: 1 bytes
h: 1 bit
- ๅฟ่ทณๆ ่ฏไฝ
- %x0 ่กจ็คบๆฐๆฎๅ
- %x1 ่กจ็คบๅฟ่ทณๅ
extcode: 7 bit
- ๆฉๅฑๆไฝ็
- ๆๆชๆ็กฎๅฎไนๅ ทไฝๆไฝ็
route: 1 bytes | 2 bytes | 4 bytes
- ๆถๆฏ่ทฏ็ฑ
- ้ป่ฎค้็จ2ๅญ่๏ผๅฏ้่ฟๆๅ ๅจ้ ็ฝฎpacket.routeBytes่ฟ่กไฟฎๆน
- ไธๅ็่ทฏ็ฑๅฏนๅบไธๅ็ไธๅกๅค็ๆต็จ
- ๅฟ่ทณๅ ๆ ๆถๆฏ่ทฏ็ฑไฝ
- ๆญคๅๆฐ็ฑไธๅกๆๅ ๅจๆๅ ๏ผๆๅกๅจๅผๅ่ ๅๅฎขๆท็ซฏๅผๅ่ ๅ่ฆๅ ณๅฟๆญคๅๆฐ
seq: 0 bytes | 1 bytes | 2 bytes | 4 bytes
- ๆถๆฏๅบๅๅท
- ้ป่ฎค้็จ2ๅญ่๏ผๅฏ้่ฟๆๅ ๅจ้ ็ฝฎpacket.seqBytes่ฟ่กไฟฎๆน
- ๅฏ้่ฟๅฐๆๅ ๅจ้ ็ฝฎpacket.seqBytes่ฎพ็ฝฎไธบ0ๆฅๅฑ่ฝไฝฟ็จๅบๅๅท
- ๆถๆฏๅบๅๅทๅธธ็จไบ่ฏทๆฑ/ๅๅบๆจกๅ็ๆถๆฏๅฏนๅฟ็็กฎ่ฎค
- ๅฟ่ทณๅ ๆ ๆถๆฏๅบๅๅทไฝ
- ๆญคๅๆฐ็ฑไธๅกๆๅ ๅจpacket.Packerๆๅ ๏ผๆๅกๅจๅผๅ่ ๅๅฎขๆท็ซฏๅผๅ่ ๅ่ฆๅ ณๅฟๆญคๅๆฐ
message data: n bytes
- ๆถๆฏๆฐๆฎ
- ๅฟ่ทณๅ ๆ ๆถๆฏๆฐๆฎ
- ๆญคๅๆฐ็ฑไธๅกๆๅ ๅจpacket.Packerๆๅ ๏ผๆๅกๅจๅผๅ่ ๅๅฎขๆท็ซฏๅผๅ่ ๅ่ฆๅ ณๅฟๆญคๅๆฐ
heartbeat time: 8 bytes
- ๅฟ่ทณๆฐๆฎ
- ๆฐๆฎๅ ๆ ๅฟ่ทณๆฐๆฎ
- ไธ่กๅฟ่ทณๅ ๆ ้ๆบๅธฆๅฟ่ทณๆฐๆฎ๏ผไธ่กๅฟ่ทณๅ ้ป่ฎคๆบๅธฆ8 bytes็ๆๅกๅจๆถ้ด๏ผns๏ผ๏ผๅฏ้่ฟ็ฝ็ปๅบ้ ็ฝฎ่ฟ่ก่ฎพ็ฝฎๆฏๅฆๆบๅธฆไธ่กๅ ๆถ้ดไฟกๆฏ
- ๆญคๅๆฐ็ฑ็ฝ็ปๆกๆถๅฑ่ชๅจๆๅ ๏ผๆๅก็ซฏๅผๅ่ ไธๅ ณๆณจๆญคๅๆฐ๏ผๅฎขๆท็ซฏๅผๅ่ ้ๅ ณๆณจๆญคๅๆฐ
1.ๅฎ่ฃ protobuf็ผ่ฏๅจ๏ผไฝฟ็จๅบๆฏ๏ผๅผๅmeshๅพฎๆๅก๏ผ
- Linux, using apt or apt-get, for example:
$ apt install -y protobuf-compiler
$ protoc --version # Ensure compiler version is 3+
- MacOS, using Homebrew:
$ brew install protobuf
$ protoc --version # Ensure compiler version is 3+
- Windows, download from Github:
2.ๅฎ่ฃ protobuf goไปฃ็ ็ๆๅทฅๅ ท๏ผไฝฟ็จๅบๆฏ๏ผๅผๅmeshๅพฎๆๅก๏ผ
go install github.com/gogo/protobuf/protoc-gen-gofast@latest
3.ๅฎ่ฃ grpcไปฃ็ ็ๆๅทฅๅ ท๏ผไฝฟ็จๅบๆฏ๏ผไฝฟ็จGRPC็ปไปถๅผๅmeshๅพฎๆๅก๏ผ
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
4.ๅฎ่ฃ rpcxไปฃ็ ็ๆๅทฅๅ ท๏ผไฝฟ็จๅบๆฏ๏ผไฝฟ็จRPCX็ปไปถๅผๅmeshๅพฎๆๅก๏ผ
go install github.com/rpcxio/protoc-gen-rpcx@latest
5.ๅฎ่ฃ gorm daoไปฃ็ ็ๆๅทฅๅ ท๏ผไฝฟ็จๅบๆฏ๏ผไฝฟ็จGORMไฝไธบๆฐๆฎๅบorm๏ผ
go install github.com/dobyte/gorm-dao-generator@latest
6.ๅฎ่ฃ mongo daoไปฃ็ ็ๆๅทฅๅ ท๏ผไฝฟ็จๅบๆฏ๏ผไฝฟ็จMongoDBไฝไธบๆฐๆฎๅบorm๏ผ
go install github.com/dobyte/mongo-dao-generator@latest
1.ๅ่ฝไป็ป
้ ็ฝฎไธญๅฟไธป่ฆๅฎไฝไบไธๅก็้ ็ฝฎ็ฎก็๏ผๆไพๅฟซๆท็ตๆดป็้ ็ฝฎๆนๆกใๆฏๆๅฎๅ็่ฏปๅใไฟฎๆนใๅ ้คใ็ญๆดๆฐ็ญๅ่ฝใ
2.ๆฏๆ็ปไปถ
1.ๅ่ฝไป็ป
ๆณจๅไธญๅฟ็จไบ้็พคๅฎไพ็ๆๅกๆณจๅๅๅ็ฐใๆฏๆๆดไธช้็พค็ๆ ๆ็ฅๅๆใ้ๅฏใๅจๆๆฉๅฎน็ญๅ่ฝใ
2.ๆฏๆ็ปไปถ
1.ๅ่ฝไป็ป
็ฝ็ปๆจกๅไธป่ฆไปฅ็ปไปถ็ๅฝขๅผ้ๆไบ็ฝๅ ณๆจกๅ๏ผไธบ็ฝๅ ณๆไพ็ตๆดป็็ฝ็ป้ไฟกๆฏๆใ
2.ๆฏๆ็ปไปถ
ไธ้ขๆไปฌๅฐฑ้่ฟไธคๆฎต็ฎๅ็ไปฃ็ ๆฅไฝ้ชไธไธdue็้ญ ๅ๏ผLet's go~~
1.ๅฏๅจ็ปไปถ
docker-compose up
docker-compose.yamlๆไปถๅทฒๅจdocker็ฎๅฝไธญๅคๅฅฝ๏ผๅฏไปฅ็ดๆฅๅ็จ
2.่ทๅๆกๆถ
go get -u github.com/dobyte/due/v2@latest
go get -u github.com/dobyte/due/locate/redis/v2@latest
go get -u github.com/dobyte/due/network/ws/v2@latest
go get -u github.com/dobyte/due/registry/consul/v2@latest
go get -u github.com/dobyte/due/transport/rpcx/v2@latest
3.ๆๅปบGateๆๅกๅจ
package main
import (
"github.com/dobyte/due/locate/redis/v2"
"github.com/dobyte/due/network/ws/v2"
"github.com/dobyte/due/registry/consul/v2"
"github.com/dobyte/due/v2"
"github.com/dobyte/due/v2/cluster/gate"
)
func main() {
// ๅๅปบๅฎนๅจ
container := due.NewContainer()
// ๅๅปบๆๅกๅจ
server := ws.NewServer()
// ๅๅปบ็จๆทๅฎไฝๅจ
locator := redis.NewLocator()
// ๅๅปบๆๅกๅ็ฐ
registry := consul.NewRegistry()
// ๅๅปบ็ฝๅ
ณ็ปไปถ
component := gate.NewGate(
gate.WithServer(server),
gate.WithLocator(locator),
gate.WithRegistry(registry),
)
// ๆทปๅ ็ฝๅ
ณ็ปไปถ
container.Add(component)
// ๅฏๅจๅฎนๅจ
container.Serve()
}
4.ๅฏๅจGateๆๅกๅจ
$ go run main.go
____ __ ________
/ __ \/ / / / ____/
/ / / / / / / __/
/ /_/ / /_/ / /___
/_____/\____/_____/
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| [Website] https://github.com/dobyte/due |
| [Version] v2.1.0 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโGlobalโโโโโโโโโโโโโโโโโโโโโโโโโ
| PID: 27159 |
| Mode: debug |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโGateโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Name: gate |
| Link: 172.22.243.151:46545 |
| Server: [ws] 0.0.0.0:3553 |
| Locator: redis |
| Registry: consul |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
5.ๆๅปบNodeๆๅกๅจ
package main
import (
"fmt"
"github.com/dobyte/due/locate/redis/v2"
"github.com/dobyte/due/registry/consul/v2"
"github.com/dobyte/due/v2"
"github.com/dobyte/due/v2/cluster/node"
"github.com/dobyte/due/v2/codes"
"github.com/dobyte/due/v2/log"
"github.com/dobyte/due/v2/utils/xtime"
)
const greet = 1
func main() {
// ๅๅปบๅฎนๅจ
container := due.NewContainer()
// ๅๅปบ็จๆทๅฎไฝๅจ
locator := redis.NewLocator()
// ๅๅปบๆๅกๅ็ฐ
registry := consul.NewRegistry()
// ๅๅปบ่็น็ปไปถ
component := node.NewNode(
node.WithLocator(locator),
node.WithRegistry(registry),
)
// ๅๅงๅ็ๅฌ
initListen(component.Proxy())
// ๆทปๅ ่็น็ปไปถ
container.Add(component)
// ๅฏๅจๅฎนๅจ
container.Serve()
}
// ๅๅงๅ็ๅฌ
func initListen(proxy *node.Proxy) {
proxy.Router().AddRouteHandler(greet, false, greetHandler)
}
type greetReq struct {
Message string `json:"message"`
}
type greetRes struct {
Code int `json:"code"`
Message string `json:"message"`
}
func greetHandler(ctx node.Context) {
req := &greetReq{}
res := &greetRes{}
defer func() {
if err := ctx.Response(res); err != nil {
log.Errorf("response message failed: %v", err)
}
}()
if err := ctx.Parse(req); err != nil {
log.Errorf("parse request message failed: %v", err)
res.Code = codes.InternalError.Code()
return
}
log.Info(req.Message)
res.Code = codes.OK.Code()
res.Message = fmt.Sprintf("I'm server, and the current time is: %s", xtime.Now().Format(xtime.DatetimeLayout))
}
6.ๅฏๅจNodeๆๅกๅจ
$ go run main.go
____ __ ________
/ __ \/ / / / ____/
/ / / / / / / __/
/ /_/ / /_/ / /___
/_____/\____/_____/
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| [Website] https://github.com/dobyte/due |
| [Version] v2.1.0 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโGlobalโโโโโโโโโโโโโโโโโโโโโโโโโ
| PID: 27390 |
| Mode: debug |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโNodeโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Name: node |
| Link: 172.22.243.151:37901 |
| Codec: json |
| Locator: redis |
| Registry: consul |
| Encryptor: - |
| Transporter: - |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
7.ๆๅปบๆต่ฏๅฎขๆท็ซฏ
package main
import (
"fmt"
"github.com/dobyte/due/eventbus/nats/v2"
"github.com/dobyte/due/network/ws/v2"
"github.com/dobyte/due/v2"
"github.com/dobyte/due/v2/cluster"
"github.com/dobyte/due/v2/cluster/client"
"github.com/dobyte/due/v2/eventbus"
"github.com/dobyte/due/v2/log"
"github.com/dobyte/due/v2/utils/xtime"
"time"
)
const greet = 1
func main() {
// ๅๅงๅไบไปถๆป็บฟ
eventbus.SetEventbus(nats.NewEventbus())
// ๅๅปบๅฎนๅจ
container := due.NewContainer()
// ๅๅปบๅฎขๆท็ซฏ็ปไปถ
component := client.NewClient(
client.WithClient(ws.NewClient()),
)
// ๅๅงๅ็ๅฌ
initListen(component.Proxy())
// ๆทปๅ ๅฎขๆท็ซฏ็ปไปถ
container.Add(component)
// ๅฏๅจๅฎนๅจ
container.Serve()
}
// ๅๅงๅ็ๅฌ
func initListen(proxy *client.Proxy) {
// ็ๅฌ็ปไปถๅฏๅจ
proxy.AddHookListener(cluster.Start, startHandler)
// ็ๅฌ่ฟๆฅๅปบ็ซ
proxy.AddEventListener(cluster.Connect, connectHandler)
// ็ๅฌๆถๆฏๅๅค
proxy.AddRouteHandler(greet, greetHandler)
}
// ็ปไปถๅฏๅจๅค็ๅจ
func startHandler(proxy *client.Proxy) {
if _, err := proxy.Dial(); err != nil {
log.Errorf("gate connect failed: %v", err)
return
}
}
// ่ฟๆฅๅปบ็ซๅค็ๅจ
func connectHandler(conn *client.Conn) {
doPushMessage(conn)
}
// ๆถๆฏๅๅคๅค็ๅจ
func greetHandler(ctx *client.Context) {
res := &greetRes{}
if err := ctx.Parse(res); err != nil {
log.Errorf("invalid response message, err: %v", err)
return
}
if res.Code != 0 {
log.Errorf("node response failed, code: %d", res.Code)
return
}
log.Info(res.Message)
time.AfterFunc(time.Second, func() {
doPushMessage(ctx.Conn())
})
}
// ๆจ้ๆถๆฏ
func doPushMessage(conn *client.Conn) {
err := conn.Push(&cluster.Message{
Route: 1,
Data: &greetReq{
Message: fmt.Sprintf("I'm client, and the current time is: %s", xtime.Now().Format(xtime.DatetimeLayout)),
},
})
if err != nil {
log.Errorf("push message failed: %v", err)
}
}
type greetReq struct {
Message string `json:"message"`
}
type greetRes struct {
Code int `json:"code"`
Message string `json:"message"`
}
8.ๅฏๅจๅฎขๆท็ซฏ
$ go run main.go
____ __ ________
/ __ \/ / / / ____/
/ / / / / / / __/
/ /_/ / /_/ / /___
/_____/\____/_____/
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| [Website] https://github.com/dobyte/due |
| [Version] v2.1.0 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโGlobalโโโโโโโโโโโโโโโโโโโโโโโโโ
| PID: 27801 |
| Mode: debug |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโClientโโโโโโโโโโโโโโโโโโโโโโโโโ
| Name: client |
| Codec: json |
| Protocol: ws |
| Encryptor: - |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
INFO[2024/07/03 14:53:08.969845] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:08]
INFO[2024/07/03 14:53:09.983827] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:09]
INFO[2024/07/03 14:53:10.986592] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:10]
INFO[2024/07/03 14:53:11.988530] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:11]
INFO[2024/07/03 14:53:12.991217] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:12]
INFO[2024/07/03 14:53:13.995049] main.go:72 [I'm server, and the current time is: 2024-07-03 14:53:13]
1.ๅๆตๆบๅจ
Ubuntu 20.04.6 LTS 13th Gen Intel(R) Core(TM) i5-13400F 16GB
2.ๅๆต็ปๆ
____ __ ________
/ __ \/ / / / ____/
/ / / / / / / __/
/ /_/ / /_/ / /___
/_____/\____/_____/
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| [Website] https://github.com/dobyte/due |
| [Version] v2.1.0 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโGlobalโโโโโโโโโโโโโโโโโโโโโโโโโ
| PID: 28660 |
| Mode: debug |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโClientโโโโโโโโโโโโโโโโโโโโโโโโโ
| Name: client |
| Codec: json |
| Protocol: tcp |
| Encryptor: - |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
server : tcp
concurrency : 50
latency : 4.741343s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 210910
--------------------------------
server : tcp
concurrency : 100
latency : 4.697039s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 212900
--------------------------------
server : tcp
concurrency : 200
latency : 4.447127s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 224864
--------------------------------
server : tcp
concurrency : 300
latency : 5.616742s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 178039
--------------------------------
server : tcp
concurrency : 400
latency : 4.726411s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 211577
--------------------------------
server : tcp
concurrency : 500
latency : 5.054949s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 197825
--------------------------------
server : tcp
concurrency : 1000
latency : 5.486149s
data size : 1.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 182277
--------------------------------
server : tcp
concurrency : 1000
latency : 7.753779s
data size : 2.00KB
sent requests : 1000000
received requests : 1000000
throughput (TPS) : 128969
--------------------------------
ๆฌๆต่ฏ็ปๆไป ไพๅ่๏ผ่ฏฆ็ปๆต่ฏ็จไพไปฃ็ ่ฏทๆฅ็due-benchmark
- ๆฅๅฟ็ปไปถ
- zap: github.com/dobyte/due/log/zap/v2
- logrus: github.com/dobyte/due/log/logrus/v2
- aliyun: github.com/dobyte/due/log/aliyun/v2
- tencent: github.com/dobyte/due/log/zap/v2
- ็ฝ็ป็ปไปถ
- ws: github.com/dobyte/due/network/ws/v2
- tcp: github.com/dobyte/due/network/tcp/v2
- kcp: github.com/dobyte/due/network/kcp/v2
- ๆณจๅๅ็ฐ
- etcd: github.com/dobyte/due/registry/etcd/v2
- consul: github.com/dobyte/due/registry/consul/v2
- nacos: github.com/dobyte/due/registry/nacos/v2
- ไผ ่พ็ปไปถ
- grpc: github.com/dobyte/due/transporter/grpc/v2
- rpcx: github.com/dobyte/due/transporter/rpcx/v2
- ๅฎไฝ็ปไปถ
- redis: github.com/dobyte/due/locate/redis/v2
- ไบไปถๆป็บฟ
- redis: github.com/dobyte/due/eventbus/redis/v2
- nats: github.com/dobyte/due/eventbus/nats/v2
- kafka: github.com/dobyte/due/eventbus/kafka/v2
- Web็ปไปถ
- http: github.com/dobyte/due/component/http/v2
- ้
็ฝฎไธญๅฟ
- etcd: github.com/dobyte/due/config/etcd/v2
- consul: github.com/dobyte/due/config/consul/v2
- nacos: github.com/dobyte/due/config/nacos/v2
- ็ผๅญ็ปไปถ
- redis: github.com/dobyte/due/cache/redis/v2
ๆดๅค่ฏฆ็ป็คบไพ่ฏท็นๅปdue-examples
ไธชไบบๅพฎไฟก๏ผyuebanfuxiao