Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.

Support for other Watch types? #43

Closed
egarson opened this issue Mar 2, 2016 · 2 comments
Closed

Support for other Watch types? #43

egarson opened this issue Mar 2, 2016 · 2 comments

Comments

@egarson
Copy link

egarson commented Mar 2, 2016

Hello
I see that consultdotnet supports Watches on KV pairs.
Is there support for other Watch types (services, nodes...)? Or, can this be implemented in some way (i.e. I missed something)?
Kind regards
Edward

@highlyunavailable
Copy link
Contributor

Watches are secretly just blocking queries against an endpoint.

All query style requests (e.g. KV.Get, Catalog.Services, Health.Service, and many, many others) have a method signature that accepts a QueryOptions class parameter. QueryOptions objects are used to parameterize a query and have a WaitIndex property.

To watch an endpoint, first construct a QueryOptions class instance and leave WaitIndex at 0 (the default).

Pass the instance to a query method (e.g. client.Health.Service("fooservice", null, false, myQueryOpts)) and await the result. All queries return a QueryResult<T> object type. The Result property is the actual result of the query, but all the other properties of the QueryResult object have metadata about the query. What you're interested in is the LastIndex property of the QueryResult. Set you custom QueryOptions object's WaitIndex property to be the LastIndex value and re-issue your query. Your await will now block waiting for the query timeout or the blocking query to return when data is updated. See https://github.com/PlayFab/consuldotnet/blob/master/Consul/Lock.cs#L252-L308 for an actual example of use against the K/V store - this method works against any endpoint that supports blocking queries, though.

I really should write some better docs on how to use the API in C# since the way the HTTP API works diverges just enough to make the Hashicorp docs not quite work for this.

@highlyunavailable
Copy link
Contributor

Okay, created #44 to track docs. Feel free to comment on that issue if there are any other docs you'd like to see that aren't covered by the Hashicorp docs on the operation of the service itself.

Let me know if you have any questions about this way of watching values or if not, feel free to close out the issue. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants