Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Server-streaming RPCs

In a server-streaming RPC scenario, the client initiates an RPC on the server and receives a stream of responses. Clients block reading on the stream until new data becomes available or the server closes the stream. In the latter case, the client read request will return an io.EOF error to indicate that no more data is available.

In the following example, we are defining a service that streams price updates for a particular cryptocurrency:

message CryptoPriceRequest {  string crypto_type = 1;}message CryptoPrice {  double price = 1;}service PriceService {  rpc StreamCryptoPrice (CryptoPriceRequest) returns (stream CryptoPrice);}

The following code shows the server-side implementation for the StreamCryptoPrice RPC:

var ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content