Skip to content

Commit

Permalink
fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
fuwensun committed Aug 6, 2018
1 parent 02b868a commit e4ff94a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ch4-rpc/ch4-04-grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ func main() {
```protobuf
service PubsubService {
rpc Publish (String) returns (String);
rpc SubscribeTopic (String) returns (stream String);
rpc Subscribe (String) returns (stream String);
}
```

其中Publish是普通的RPC方法,SubscribeTopic则是一个单向的流服务。然后grpc插件会为服务端和客户端生成对应的接口:
其中Publish是普通的RPC方法,Subscribe则是一个单向的流服务。然后grpc插件会为服务端和客户端生成对应的接口:

```go
type PubsubServiceServer interface {
Expand All @@ -286,7 +286,7 @@ type HelloService_SubscribeServer interface {
}
```

因为SubscribeTopic是服务端的单向流,因此生成的HelloService_SubscribeServer接口中只有Send方法。
因为Subscribe是服务端的单向流,因此生成的HelloService_SubscribeServer接口中只有Send方法。

然后就可以实现发布和订阅服务了:

Expand Down Expand Up @@ -315,7 +315,7 @@ func (p *PubsubService) Publish(
func (p *PubsubService) Subscribe(
arg *String, stream PubsubService_SubscribeServer,
) error {
ch := p.SubscribeTopic(func(v interface{}) bool {
ch := p.Subscribe(func(v interface{}) bool {
if key, ok := v.(string); ok {
if strings.Hasprefix(arg.GetValue()) {
return true
Expand Down

0 comments on commit e4ff94a

Please sign in to comment.