mirror of https://github.com/dapr/docs.git
				
				
				
			Added docs for python config subscribe API
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
This commit is contained in:
		
							parent
							
								
									48b63b2310
								
							
						
					
					
						commit
						1eee51b153
					
				|  | @ -212,6 +212,47 @@ message SubscribeConfigurationRequest { | ||||||
| 
 | 
 | ||||||
| Using this method, you can subscribe to changes in specific keys for a given configuration store. gRPC streaming varies widely based on language - see the [gRPC examples here](https://grpc.io/docs/languages/) for usage. | Using this method, you can subscribe to changes in specific keys for a given configuration store. gRPC streaming varies widely based on language - see the [gRPC examples here](https://grpc.io/docs/languages/) for usage. | ||||||
| 
 | 
 | ||||||
|  | Below are the examples in sdks: | ||||||
|  | 
 | ||||||
|  | {{< tabs Python>}} | ||||||
|  | 
 | ||||||
|  | {{% codetab %}} | ||||||
|  | ```python | ||||||
|  | #dependencies | ||||||
|  | import asyncio | ||||||
|  | from time import sleep | ||||||
|  | from dapr.clients import DaprClient | ||||||
|  | #code | ||||||
|  | async def executeConfiguration(): | ||||||
|  |     with DaprClient() as d: | ||||||
|  |         CONFIG_STORE_NAME = 'configstore' | ||||||
|  |         key = 'orderId' | ||||||
|  |         # Wait for sidecar to be up within 20 seconds. | ||||||
|  |         d.wait(20) | ||||||
|  |         # Subscribe to configuration by key. | ||||||
|  |         configuration = await d.subscribe_configuration(store_name=CONFIG_STORE_NAME, keys=[key], config_metadata={}) | ||||||
|  |         for x in range(10): | ||||||
|  |             if configuration != None: | ||||||
|  |                 items = configuration.get_items() | ||||||
|  |                 for item in items: | ||||||
|  |                     print(f"Subscribe key={item.key} value={item.value} version={item.version}", flush=True) | ||||||
|  |             else: | ||||||
|  |                 print("Nothing yet") | ||||||
|  |             sleep(5) | ||||||
|  | 
 | ||||||
|  | asyncio.run(executeConfiguration()) | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | Navigate to the directory containing the above code and run the following command to launch the application along with a Dapr sidecar: | ||||||
|  | 
 | ||||||
|  | ```bash | ||||||
|  | dapr run --app-id orderprocessing --components-path components/ -- python3 OrderProcessingService.py | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | {{% /codetab %}} | ||||||
|  | 
 | ||||||
|  | {{< /tabs >}} | ||||||
|  | 
 | ||||||
| ##### Stop watching configuration items | ##### Stop watching configuration items | ||||||
| 
 | 
 | ||||||
| After you have subscribed to watch configuration items, the gRPC-server stream starts. This stream thread does not close itself, and you have to do by explicitly call the `UnSubscribeConfigurationRequest` API. This method accepts the following request object: | After you have subscribed to watch configuration items, the gRPC-server stream starts. This stream thread does not close itself, and you have to do by explicitly call the `UnSubscribeConfigurationRequest` API. This method accepts the following request object: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue