See the full example here
Dubbo-Python supports streaming calls, including ClientStream
, ServerStream
, and BidirectionalStream
modes.
Streaming calls can be divided into write-streams and read-streams. For ClientStream
, it’s multiple writes with a single read; for ServerStream
, a single write with multiple reads; and BidirectionalStream
allows multiple writes and reads.
Write operations in streaming calls can be divided into single write (ServerStream
) and multiple writes (ClientStream
and BidirectionalStream
).
Single write calls are similar to unary mode. For example:
For multiple writes, users can write data using either an iterator or writeStream
(only one of these options should be used).
Iterator-based Write: Writing via iterator is similar to unary mode, with the main difference being the use of an iterator for multiple writes. For example:
Using writeStream
: This method requires an empty argument, after which data is written incrementally using write
, and done_writing
is called to end the write-stream. For example:
Read operations for streaming calls can be single read (ClientStream
) or multiple reads (ServerStream
and BidirectionalStream
). A ReadStream
is returned in all cases, and data can be read using the read
method or an iterator. When using read
, please note:
read
method supports a timeout
parameter (in seconds).read
method can return one of three values: the expected data, None
(timeout exceeded), or EOF
(end of the read-stream).A single call to the read
method will retrieve the data, for example:
Multiple reads can be done by repeatedly calling read
, with handling for None
and EOF
values. Since ReadStream
implements __iter__
and __next__
, an iterator-based approach can also be used, which automatically handles these values but doesn’t support a timeout.
Using Iterator (Recommended):
Multiple Calls to read
Method: