@@ -147,7 +147,11 @@ class BidiRpc(object):
147
147
148
148
initial_request = example_pb2.StreamingRpcRequest(
149
149
setting='example')
150
- rpc = BidiRpc(stub.StreamingRpc, initial_request=initial_request)
150
+ rpc = BidiRpc(
151
+ stub.StreamingRpc,
152
+ initial_request=initial_request,
153
+ metadata=[('name', 'value')]
154
+ )
151
155
152
156
rpc.open()
153
157
@@ -165,11 +169,14 @@ class BidiRpc(object):
165
169
Callable[None, protobuf.Message]]): The initial request to
166
170
yield. This is useful if an initial request is needed to start the
167
171
stream.
172
+ metadata (Sequence[Tuple(str, str)]): RPC metadata to include in
173
+ the request.
168
174
"""
169
175
170
- def __init__ (self , start_rpc , initial_request = None ):
176
+ def __init__ (self , start_rpc , initial_request = None , metadata = None ):
171
177
self ._start_rpc = start_rpc
172
178
self ._initial_request = initial_request
179
+ self ._rpc_metadata = metadata
173
180
self ._request_queue = queue .Queue ()
174
181
self ._request_generator = None
175
182
self ._is_active = False
@@ -200,7 +207,7 @@ def open(self):
200
207
request_generator = _RequestQueueGenerator (
201
208
self ._request_queue , initial_request = self ._initial_request
202
209
)
203
- call = self ._start_rpc (iter (request_generator ))
210
+ call = self ._start_rpc (iter (request_generator ), metadata = self . _rpc_metadata )
204
211
205
212
request_generator .call = call
206
213
@@ -288,10 +295,14 @@ def should_recover(exc):
288
295
initial_request = example_pb2.StreamingRpcRequest(
289
296
setting='example')
290
297
291
- rpc = ResumeableBidiRpc(
298
+ metadata = [('header_name', 'value')]
299
+
300
+ rpc = ResumableBidiRpc(
292
301
stub.StreamingRpc,
302
+ should_recover=should_recover,
293
303
initial_request=initial_request,
294
- should_recover=should_recover)
304
+ metadata=metadata
305
+ )
295
306
296
307
rpc.open()
297
308
@@ -310,10 +321,12 @@ def should_recover(exc):
310
321
should_recover (Callable[[Exception], bool]): A function that returns
311
322
True if the stream should be recovered. This will be called
312
323
whenever an error is encountered on the stream.
324
+ metadata Sequence[Tuple(str, str)]: RPC metadata to include in
325
+ the request.
313
326
"""
314
327
315
- def __init__ (self , start_rpc , should_recover , initial_request = None ):
316
- super (ResumableBidiRpc , self ).__init__ (start_rpc , initial_request )
328
+ def __init__ (self , start_rpc , should_recover , initial_request = None , metadata = None ):
329
+ super (ResumableBidiRpc , self ).__init__ (start_rpc , initial_request , metadata )
317
330
self ._should_recover = should_recover
318
331
self ._operational_lock = threading .RLock ()
319
332
self ._finalized = False
0 commit comments