You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-49Lines changed: 22 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,58 +14,20 @@ Add `Winton.Extensions.Configuration.Consul` to your project's dependencies, eit
14
14
## Usage
15
15
16
16
### Minimal Setup
17
-
The library provides an extension method called `AddConsul` for `IConfigurationBuilder` in the same way that other configuration providers do. The `IConfigurationBuilder` is usually configured in either the `Program` or `Startup` class for an ASP.NET Core application. See Microsoft's [documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1) for more information about `IConfigurationBuilder`.
17
+
18
+
The library provides an extension method called `AddConsul` for `IConfigurationBuilder` in the same way that other configuration providers do. The `IConfigurationBuilder` is usually configured in either the `Program` or `Startup` class for an ASP.NET Core application. See Microsoft's [documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.0) for more information about `IConfigurationBuilder`.
Assuming the application is running in the 'Development' environment and the application name is 'Website', then this will load a JSON configuration object from the `Website/Development` key in Consul.
30
28
31
-
The `CancellationToken` is used to cancel any active requests/watches to/on Consul.
32
-
It is recommended that this is cancelled during application shutdown to clean up resources. This will typically be done in one of two places. Either in the `Program` class, for example:
`AddConsul` has an overload with an additional third parameter of type `Action<IConsulConfigurationSource>` which allows the options outlined below to be set.
An `Action<HttpClient>` that can be used to configure the underlying Consul client's HTTP options.
42
+
***`KeyToRemove`**
43
+
44
+
The portion of the Consul key to remove from the configuration keys.
45
+
By default, when the configuration is parsed, the keys are created by removing the root key in Consul where the configuration is located.
46
+
This defaults to `Key`.
80
47
***`OnLoadException`**
81
48
82
49
An `Action<ConsulLoadExceptionContext>` that can be used to configure how exceptions thrown during the first load should be handled.
83
50
***`OnWatchException`**
84
51
85
52
A `Func<ConsulWatchExceptionContext, TimeSpan>` that can be used to configure how exceptions thrown when watching for changes should be handled.
86
-
The `TimeSpan` that is returned is used to set a delay before retrying.
87
-
The `ConsulWatchExceptionContext` provides data that can be used to implement a backoff strategy or to cancel watching altogether.
53
+
The `TimeSpan` that is returned is used to set a delay before retrying.
54
+
The `ConsulWatchExceptionContext` provides data that can be used to implement a back-off strategy or to cancel watching altogether.
88
55
***`Optional`**
89
56
90
57
A `bool` that indicates whether the config is optional. If `false` then it will throw during the first load if the config is missing for the given key. Defaults to `false`.
91
58
***`Parser`**
92
59
93
60
The parser to use, which should match the format of the configuration stored in Consul. Defaults to `JsonConfigurationParser`. Either use those under `Winton.Extensions.Configuration.Consul.Parsers` or create your own by implementing `IConfigurationParser`.
61
+
***`PollWaitTime`**
62
+
63
+
The amount of time the client should wait before timing out when polling for changes.
64
+
If this is set too low it can lead to excessive requests being issued to Consul.
65
+
Note this setting does not affect how quickly updates propagate, because when a value changes the long polling query returns immediately.
66
+
It is better to think of this as the frequency with which it issues calls in the long polling loop in the case where there is no change.
67
+
Defaults to 5 minutes.
94
68
***`ReloadOnChange`**
95
69
96
70
A `bool` indicating whether to reload the config when it changes in Consul.
By default this configuration provider will load all key-value pairs from Consul under the specified root key, but by default it assumes that the values of the leaf keys are encoded as JSON.
102
76
103
77
Take the following example of a particular instance of the Consul KV store:
78
+
104
79
```
105
80
- myApp/
106
81
- auth/
107
-
{
82
+
{
108
83
"appId": "guid",
109
84
"claims": [
110
85
"email",
@@ -127,7 +102,7 @@ var configuration = builder
127
102
128
103
The resultant configuration would contain sections for `auth` and `logging`. As a concrete example `configuration.GetValue<string>("logging:level")` would return `"warn"` and `configuration.GetValue<string>("auth:claims:0")` would return `"email"`.
129
104
130
-
Sometimes however, config in Consul is stored as a set of expanded keys. For instance, tools such as `consul-cli` load config in this format.
105
+
Sometimes however, config in Consul is stored as a set of expanded keys. For instance, tools such as `consul-cli` load config in this format.
131
106
132
107
The config in this case can be thought of as a tree under a specific root key in Consul. For instance, continuing with the example above, the config would be stored as:
133
108
@@ -152,22 +127,20 @@ As outlined above this configuration provider deals with recursive keys by defau
152
127
builder
153
128
.AddConsul(
154
129
"myApp",
155
-
cancellationToken,
156
130
options=>
157
131
{
158
132
options.Parser=newSimpleConfigurationParser();
159
133
});
160
134
```
161
135
162
-
The `SimpleConfigurationParser` expects to encounter a scalar value at each leaf key in the tree.
136
+
The `SimpleConfigurationParser` expects to encounter a scalar value at each leaf key in the tree.
163
137
164
138
If you need to support both expanded keys and JSON values then this can be achieved by putting them under different root keys and adding multiple configuration sources. For example:
0 commit comments