Description
An HTTP pipeline general guidelines:
https://azure.github.io/azure-sdk/general_azurecore.html
- sdk/data_cosmos
- sdk/storage
- sdk/storage_datalake
- sdk/storage_blobs
- sdk/storage_queues
- sdk/iothub
- sdk/messaging_servicebus
- sdk/data_tables
- sdk/security_keyvault
A description copied from #290:
Previous to the pipeline architecture, each operation was independently controlled meaning there was no central way to control the way operations were performed.
The pipeline architecture on the other hand allows users of the SDK to create pipelines through which outgoing requests and incoming responses are processed. The pipeline are composed of "policies" which can both change the outgoing request and the incoming response. Policies are usually either on a "per-request" basis (meaning they are called only once per operation) or "per-retry" (meaning they are applied every time an operation is attempted).
Examples of policies are the TelemetryPolicy
which adds various telemetry headers to the request and the retry policy which checks whether an incoming response was successful and if it detects a transient failure, retries the request.
Converting to the Architecture
For an example of converting one operation (Cosmos's get_database
operation) over to the pipeline architecture, take a look at #286.
The basic steps are:
- Create a new submodule of the
operations
module where the operation will live. This submodule should be named after the operation (e.g., forget_database
it's calledget_database
). - Move the "request builder" (e.g., for
get_database
theGetDatabaseBuilder
) to new operation submodule and rename it fromBuilder
toOptions
(e.g.,GetDatabaseBuilder =>
GetDatabaseOptions`). This now represents the options that can be supplied when performing the operation. Note that many options that were part of the builder are no longer valid options because there will be individual policies that take their place. For instance, previously many operations took an option to set the user agent. This is now done by a policy. - Change the
execute
method to adecorate_request
method that instead of performing the request, simply mutates a request parameter with any of the options supplied. - Move the associated response type (e.g., for
get_database
theGetDatabaseResponse
type from theresponses
submodule to the operation submodule. Previously astd::convert::TryFrom
implementation was used to convert from anhttp::Response<Bytes>
object. This should now be a plain associated async function calledtry_from
that converts from the newResponse
type. See the example for how this should be done. - Finally, convert the appropriate method on the appropriate client (e.g., for
get_database
this was theDatabaseClient::get_database
) to use the new options and response types with the pipeline. Again, see the example for how this should be done.