Checkpoint the world

This commit is contained in:
Asim
2015-12-18 01:01:59 +00:00
parent 6ae48c9f29
commit 4cba0c57ab
7 changed files with 86 additions and 86 deletions

View File

@@ -56,9 +56,7 @@ func call(i int) {
func stream() {
// Create new request to service go.micro.srv.example, method Example.Call
req := client.NewRequest("go.micro.srv.example", "Example.Stream", &example.StreamingRequest{
Count: int64(10),
})
req := client.NewRequest("go.micro.srv.example", "Example.Stream", &example.StreamingRequest{})
stream, err := client.Stream(context.Background(), req)
if err != nil {
@@ -66,6 +64,15 @@ func stream() {
return
}
fmt.Println("sending request")
if err := stream.Send(&example.StreamingRequest{
Count: int64(10),
}); err != nil {
fmt.Println("err", err)
return
}
fmt.Println("sent request")
for stream.Error() == nil {
rsp := &example.StreamingResponse{}
err := stream.Recv(rsp)
@@ -88,14 +95,14 @@ func stream() {
func main() {
cmd.Init()
fmt.Println("\n--- Call example ---\n")
for i := 0; i < 10; i++ {
call(i)
}
// fmt.Println("\n--- Call example ---\n")
// for i := 0; i < 10; i++ {
// call(i)
// }
fmt.Println("\n--- Streamer example ---\n")
stream()
fmt.Println("\n--- Publisher example ---\n")
pub()
// fmt.Println("\n--- Publisher example ---\n")
// pub()
}

View File

@@ -18,16 +18,24 @@ func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.R
return nil
}
func (e *Example) Stream(ctx context.Context, req *example.StreamingRequest, response func(interface{}) error) error {
func (e *Example) Stream(ctx context.Context, stream server.Streamer) error {
log.Info("Executing streaming handler")
req := &example.StreamingRequest{}
// We just want to receive 1 request and then process here
if err := stream.Recv(req); err != nil {
log.Errorf("Error receiving streaming request: %v", err)
return err
}
log.Infof("Received Example.Stream request with count: %d", req.Count)
for i := 0; i < int(req.Count); i++ {
log.Infof("Responding: %d", i)
r := &example.StreamingResponse{
if err := stream.Send(&example.StreamingResponse{
Count: int64(i),
}
if err := response(r); err != nil {
}); err != nil {
return err
}
}