Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose more session options from C++ SDK
Since the creation of the BlazingMQ Python SDK, our underlying C++ SDK libbmq has gained more `SessionOptions` that a user can configure, including additional and more fine-grained timeout settings, new watermark configurations, and buffer sizes. These session options are not currently exposed in the Python SDK, though, so Python users are unable to make use of the new configuration options. We want to expose all new session options that are not already marked as deprecated or that do not involve distributed trace, which will require more substantial integration work. This work can be undertaken in the future without impact on the changes here. This patch extends the Python SDK to expose these new SessionOptions, modifying the API, documentation, and tests. The BlazingMQ Python SDK is divided into three layers, with the lowest level being a pure C++ library pybmq that interfaces with the BlazingMQ C++ client library libbmq, with the highest level being exposed through the `_session.py` module’s `Session` Python class, and with a thin middle layer of Cython glue code in `_ext.pyx` connecting the two. In order to expose these new `SessionOptions` to users of the Python SDK, we need to include them in each layer of the library. Crucially, we want the changes in the highest layer, `_session.py` to maintain backwards compatibility with all existing clients of the Python SDK. We maintain compatibility and evolve our API with two steps: 1. Add the new session options as additional parameters to the `Session` class’s constructor. First, all new session options that the `Session` constructor accepts are defaulted to `None`, which pybmq ignores, maintaining the existing behavior for callers who do not set any of these new arguments. Second, new session options are also appended to the list of arguments, so clients who build a `Session` using positional arguments rather than named arguments will continue to function correctly. Finally, we introduce a new value-semantic class `Timeouts`, which allows users to independently set the timeouts for each of the five session operations whose timeouts are configureable: session connection, session disconnection, queue opening, queue configuraiton, and queue closing. By overloading the `timeout` argument to taking either a simple float or an instance of `Timeouts`, users who currently set a timeout for the `Session` by passing in a single timeout will continue to see the same behavior, but users passing in a new `Timeouts` value have access to the more fine-grained timeout settings that libbmq’s `SessionOptions` provides. 2. Add a new named constructor `with_options` to `Session`, which takes an instance of a new value-semantic class `SessionOptions`. Thile users can continue to construct the `Session` directly using its extended constructor, adding the additional session options arguments to the constructor makes it somewhat unwieldly to call, especially if the user only wants to configure one of the session options. This patch provides an alternative, simpler way to construct a `Session` instance, using a new value-semantic builder class named `SessionOptions` that holds each of the new session options and a class method named `with_options`, which takes an instance of `SessionOptions` and returns a new `Session`. `with_options` is the recommended way to construct a new session if you plan to configure the session options.
- Loading branch information