-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to pass gRPC channel options when creating channel
- Loading branch information
Showing
3 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
""" gRPC Channel Options | ||
``grpc.keepalive_time_ms`` | ||
-------------------------- | ||
Time between keepalive pings. Following the official Zeebe Java/Go client, sending pings every 45 seconds. | ||
https://docs.camunda.io/docs/product-manuals/zeebe/deployment-guide/operations/setting-up-a-cluster/#keep-alive-intervals | ||
""" | ||
from typing import Dict, Any, Tuple | ||
|
||
GRPC_CHANNEL_OPTIONS = { | ||
# https://docs.camunda.io/docs/product-manuals/zeebe/deployment-guide/operations/setting-up-a-cluster/#keep-alive-intervals | ||
# "By default, the official Zeebe clients (Java and Go) send keep alive pings every 45 seconds." | ||
"grpc.keepalive_time_ms": 45_000 | ||
} | ||
|
||
|
||
def get_channel_options(): | ||
def get_channel_options(options: Dict[str, Any] = None) -> Tuple[Tuple[str, Any], ...]: | ||
""" | ||
Channel arguments are expected as a tuple of tuples: | ||
https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments | ||
Convert options dict to tuple in expected format for creating the gRPC channel | ||
Args: | ||
options (Dict[str, Any]): A key/value representation of `gRPC channel arguments_`. | ||
Default: None (will use library defaults) | ||
Returns: | ||
Tuple[Tuple[str, Any], ...]: Options for the gRPC channel | ||
.. _gRPC channel arguments: | ||
https://grpc.github.io/grpc/python/glossary.html#term-channel_arguments | ||
""" | ||
if options: | ||
options = {**GRPC_CHANNEL_OPTIONS, **options} | ||
else: | ||
options = GRPC_CHANNEL_OPTIONS | ||
return tuple( | ||
(k, v) for k, v in GRPC_CHANNEL_OPTIONS.items() | ||
(k, v) for k, v in options.items() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters