From 14526a13da03b162a7b6fd714fdc25f56d66917b Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Tue, 11 Oct 2022 15:15:08 -0700 Subject: [PATCH 1/5] Add more example of transport See https://github.com/Azure/azure-sdk-for-python/pull/26757 --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index 36c5933986a8..21bdc0ea06de 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -113,6 +113,20 @@ from azure.core.pipeline.transport import RequestsTransport synchronous_transport = RequestsTransport() ``` +For example if you would like to alter connection pool you can initialise `RequestsTransport` with an instance of `requests.Session`. + + ```Python + from azure.cosmos import CosmosClient + import requests + session = requests.Session() + adapter = requests.adapters.HTTPAdapter(pool_connections=42, pool_maxsize=42) + session.mount('https://', adapter) + cosmos_client = CosmosClient.from_connection_string( + COSMOS_CONNECTION_STRING, + transport=RequestsTransport(session=session) + ) + ``` + For asynchronous pipelines a couple of transport options are available. Each of these transports are interchangable depending on whether the user has installed various 3rd party dependencies (i.e. aiohttp or trio), and the user should easily be able to specify their chosen transport. SDK developers should use the `aiohttp` transport as the default for asynchronous pipelines where the user has not specified an alternative. From 0eb25abd9ec8931f7f0d9b2be91dbb84d7d4a8f0 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 11 Oct 2022 15:22:02 -0700 Subject: [PATCH 2/5] Update CLIENT_LIBRARY_DEVELOPER.md --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index 21bdc0ea06de..92b0076a74dc 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -123,8 +123,11 @@ For example if you would like to alter connection pool you can initialise `Reque session.mount('https://', adapter) cosmos_client = CosmosClient.from_connection_string( COSMOS_CONNECTION_STRING, - transport=RequestsTransport(session=session) + transport=RequestsTransport(session=session, session_owner=False) ) + + # When using custom session, we need to manage the session by ourself. When we are done with the session: + session.close() ``` For asynchronous pipelines a couple of transport options are available. Each of these transports are interchangable depending on whether the user has installed various 3rd party dependencies (i.e. aiohttp or trio), and the user From 8441e1f214e79094bb4e11b3eeb58047bb5e9221 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 11 Oct 2022 15:25:39 -0700 Subject: [PATCH 3/5] Update CLIENT_LIBRARY_DEVELOPER.md --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index 92b0076a74dc..42860ea82df6 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -116,15 +116,12 @@ synchronous_transport = RequestsTransport() For example if you would like to alter connection pool you can initialise `RequestsTransport` with an instance of `requests.Session`. ```Python - from azure.cosmos import CosmosClient import requests + from azure.core.pipeline.transport import RequestsTransport session = requests.Session() adapter = requests.adapters.HTTPAdapter(pool_connections=42, pool_maxsize=42) session.mount('https://', adapter) - cosmos_client = CosmosClient.from_connection_string( - COSMOS_CONNECTION_STRING, - transport=RequestsTransport(session=session, session_owner=False) - ) + client = FooServiceClient(endpoint, creds, transport=RequestsTransport(session=session, session_owner=False)) # When using custom session, we need to manage the session by ourself. When we are done with the session: session.close() From df6c8fa32e082cad01ce8c1a28e0b0006364d578 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 11 Oct 2022 15:34:16 -0700 Subject: [PATCH 4/5] Update CLIENT_LIBRARY_DEVELOPER.md --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index 42860ea82df6..d358341566f1 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -125,6 +125,8 @@ For example if you would like to alter connection pool you can initialise `Reque # When using custom session, we need to manage the session by ourself. When we are done with the session: session.close() + + # Note: `session_owner` gives the information of ownership of the requests sessions to the transport instance, to authorize it to close on customer's behalf. If you're ok that the client closes your session on your behalf as necessary, you don't need to pass a value. ``` For asynchronous pipelines a couple of transport options are available. Each of these transports are interchangable depending on whether the user has installed various 3rd party dependencies (i.e. aiohttp or trio), and the user From 24965d59217c763401bca238fae03168ceb62a51 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 11 Oct 2022 16:00:24 -0700 Subject: [PATCH 5/5] Update CLIENT_LIBRARY_DEVELOPER.md --- sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md index d358341566f1..0ca157a83037 100644 --- a/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md +++ b/sdk/core/azure-core/CLIENT_LIBRARY_DEVELOPER.md @@ -123,7 +123,7 @@ For example if you would like to alter connection pool you can initialise `Reque session.mount('https://', adapter) client = FooServiceClient(endpoint, creds, transport=RequestsTransport(session=session, session_owner=False)) - # When using custom session, we need to manage the session by ourself. When we are done with the session: + # Here we want to manage the session by ourselves. When we are done with the session, we need to close the session. session.close() # Note: `session_owner` gives the information of ownership of the requests sessions to the transport instance, to authorize it to close on customer's behalf. If you're ok that the client closes your session on your behalf as necessary, you don't need to pass a value.