How to send an array of message to Client

411 views
Skip to first unread message

Benjamin Shafa

unread,
Feb 4, 2020, 12:33:20 PM2/4/20
to grpc.io
Below is the `message` I have created in my `.Proto` :

    message ProductShippingReply {
      string id = 1;
      string shipping_mode = 2;
      double shipping_cost = 3;
      int32 shipping_duration = 4;
    }

in my Node.Js code I am trying to send an `Array` of this `message` back to the client, however the client receives an empty object. It works if I send only an instance of such `message`.

How do I send an `Array` of `Message` in PB?

Danesh Kuruppu

unread,
Feb 4, 2020, 1:21:40 PM2/4/20
to Benjamin Shafa, grpc.io
Hi Benjamin,
You can either define your rpc method as server streaming and send multiple instances of the above message to the client. or you can to define a new message type like below

message ProductShippingReplies {
  repeated ProductShippingReply replies = 1;
}

and set this new message type in your rpc method. So you can create a new message(ProductShippingReplies) instance with the array of `ProductShippingReply` instances and send it to the client.

Thanks
Danesh

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/f5d41749-e163-470a-92d0-f511465f87dd%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages