Skip to content

Commit

Permalink
修改examples文件夹名称
Browse files Browse the repository at this point in the history
  • Loading branch information
osgochina committed Jan 10, 2022
1 parent 82a4bf1 commit 3a19b94
Show file tree
Hide file tree
Showing 48 changed files with 126 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dmicro [![GitHub release](https://img.shields.io/github/v/release/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/releases) [![report card](https://goreportcard.com/badge/github.com/osgochina/dmicro?style=flat-square)](http://goreportcard.com/report/osgochina/dmicro) [![github issues](https://img.shields.io/github/issues/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/issues?q=is%3Aopen+is%3Aissue) [![github closed issues](https://img.shields.io/github/issues-closed-raw/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/issues?q=is%3Aissue+is%3Aclosed) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/osgochina/dmicro) [![view examples](https://img.shields.io/badge/learn%20by-examples-00BCD4.svg?style=flat-square)](https://github.com/osgochina/dmicro/tree/main/.examples)
# dmicro [![GitHub release](https://img.shields.io/github/v/release/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/releases) [![report card](https://goreportcard.com/badge/github.com/osgochina/dmicro?style=flat-square)](http://goreportcard.com/report/osgochina/dmicro) [![github issues](https://img.shields.io/github/issues/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/issues?q=is%3Aopen+is%3Aissue) [![github closed issues](https://img.shields.io/github/issues-closed-raw/osgochina/dmicro.svg?style=flat-square)](https://github.com/osgochina/dmicro/issues?q=is%3Aissue+is%3Aclosed) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/osgochina/dmicro) [![view examples](https://img.shields.io/badge/learn%20by-examples-00BCD4.svg?style=flat-square)](https://github.com/osgochina/dmicro/tree/main/examples)
## dmicro简介
<img src="./docs/logo.svg" width="180" height="140" alt="dmicro logo"/>

Expand Down
66 changes: 66 additions & 0 deletions docs/drpc/multiclient.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#并发请求客户端

使用连接池创建session,满足并发请求的场景。


```go
package main

import (
"github.com/osgochina/dmicro/drpc"
"github.com/osgochina/dmicro/drpc/mixer/multiclient"
"github.com/osgochina/dmicro/logger"
"time"
)

type Arg struct {
A int
B int `param:"<range:1:>"`
}

type P struct{ drpc.CallCtx }

func (p *P) Divide(arg *Arg) (int, *drpc.Status) {
return arg.A / arg.B, nil
}

func main() {
srv := drpc.NewEndpoint(drpc.EndpointConfig{
ListenPort: 9090,
})
srv.RouteCall(new(P))
go srv.ListenAndServe()
time.Sleep(time.Second)

cli := multiclient.New(
drpc.NewEndpoint(drpc.EndpointConfig{}),
":9090",
time.Second*5,
)
go func() {
for {
logger.Printf("%d", cli.Size())
time.Sleep(time.Millisecond * 500)
}
}()
go func() {
var result int
for i := 0; ; i++ {
stat := cli.Call("/p/divide", &Arg{
A: i,
B: 2,
}, &result).Status()
if !stat.OK() {
logger.Print(stat)
} else {
logger.Printf("%d/2=%v", i, result)
}
time.Sleep(time.Millisecond * 500)
}
}()
time.Sleep(time.Second * 6)
cli.Close()
time.Sleep(time.Second * 3)
}

```
1 change: 1 addition & 0 deletions docs/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* [代理proxy](drpc/plugin_proxy.md)
* [平滑重启 - Graceful](drpc/graceful.md)
* [WebSocket支持](drpc/websocket.md)
* [并发请求客户端](drpc/multiclient.md)

* 组件库
* [EventBus(事件总线)](component/eventBus.md)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions examples/multiclient/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"github.com/osgochina/dmicro/drpc"
"github.com/osgochina/dmicro/drpc/mixer/multiclient"
"github.com/osgochina/dmicro/logger"
"time"
)

type Arg struct {
A int
B int `param:"<range:1:>"`
}

type P struct{ drpc.CallCtx }

func (p *P) Divide(arg *Arg) (int, *drpc.Status) {
return arg.A / arg.B, nil
}

func main() {
srv := drpc.NewEndpoint(drpc.EndpointConfig{
ListenPort: 9090,
})
srv.RouteCall(new(P))
go srv.ListenAndServe()
time.Sleep(time.Second)

cli := multiclient.New(
drpc.NewEndpoint(drpc.EndpointConfig{}),
":9090",
time.Second*5,
)
go func() {
for {
logger.Printf("%d", cli.Size())
time.Sleep(time.Millisecond * 500)
}
}()
go func() {
var result int
for i := 0; ; i++ {
stat := cli.Call("/p/divide", &Arg{
A: i,
B: 2,
}, &result).Status()
if !stat.OK() {
logger.Print(stat)
} else {
logger.Printf("%d/2=%v", i, result)
}
time.Sleep(time.Millisecond * 500)
}
}()
time.Sleep(time.Second * 6)
cli.Close()
time.Sleep(time.Second * 3)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3a19b94

Please sign in to comment.