-
Notifications
You must be signed in to change notification settings - Fork 319
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
operationsmodule where the operation will live. This submodule should be named after the operation (e.g., forget_databaseit's calledget_database). - Move the "request builder" (e.g., for
get_databasetheGetDatabaseBuilder) to new operation submodule and rename it fromBuildertoOptions(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
executemethod to adecorate_requestmethod 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_databasetheGetDatabaseResponsetype from theresponsessubmodule to the operation submodule. Previously astd::convert::TryFromimplementation was used to convert from anhttp::Response<Bytes>object. This should now be a plain associated async function calledtry_fromthat converts from the newResponsetype. See the example for how this should be done. - Finally, convert the appropriate method on the appropriate client (e.g., for
get_databasethis 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.