Skip to content

Commit

Permalink
Merge pull request #234 from fuwensun/pr4-4-3b
Browse files Browse the repository at this point in the history
fixed code
  • Loading branch information
chai2010 authored Aug 6, 2018
2 parents 541cdf8 + e4ff94a commit cb90c19
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 cb90c19

Please sign in to comment.