playfab / consuldotnet Goto Github PK
View Code? Open in Web Editor NEW.NET API for Consul (http://www.consul.io/)
License: Apache License 2.0
.NET API for Consul (http://www.consul.io/)
License: Apache License 2.0
Hi,
If I set ConsulClientConfiguration.WaitTime
to a value (I've tried 10 seconds and 5 minutes, so sane values) then when I use ICatalogEndpoint.Service
it fails with the error message:
Unexpected response, status code BadRequest: Invalid wait time
If I use QueryOptions
instead then it works.
I've not tried any other calls so this might not affect just ICatalogEndpoint.Service
.
Hello - would you entertain accepting a pull request that would break the dependency of your project on Json.Net? This could be achieved by exposing a serialization interface and moving the Json.net specific code into a separate nuget package as an adapter.
Hi there,
I would to change the Consule server endpoint from localhost:8500 to something else. I tried to instantiate the client object using the following code:
using (var client = new ConsulClient(x => new ConsulClientConfiguration()
{ Address = new Uri("http://consul.local:8500") }))
{
....
}
However when I run the code, the result looks like it's still pointing to localhost:8500. Am I doing the configuration wrong?
Thank you for your help.
Hi,
I've seen that you use Finalizer in your code,
~ConsulClient()
{
if (HttpClient != null)
{
HttpClient.Dispose();
}
}
Is there any reason why the ConsulClient does not implement the IDisposable interface and you just add a Dispose method? (Finalizer are not so common in the .Net framework and should be used when there is absolutely no other way to achieve the goal. You're in the Managed world, Enjoy it my friend :))
As I see it the class should like like this:
public partial class ConsulClient : IDisposable
/* Some awesome code (without finalizers */
public Dispose()
{
if (HttpClient != null)
{
HttpClient.Dispose();
}
}
What do you think?
Hi,
I'm not able to create unit tests that handle the response from ICatalogEndpoint.Service
(and similar calls) because QueryResult<>.Response
has an internal setter. Could the setter be made public, please? I'm guessing that's the least disruptive means of solving this problem.
Thanks.
UrlPathEncode does actually what we're trying to do when encoding query string values.
https://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urlpathencode(v=vs.110).aspx
Hi,
I'm thinking about start working with Consul in my .Net environment, I saw your cool client and it's seems one of the best tools to use for .Net developers.
However, when I dive into the code I saw a lot (really a lot) of places you're using the async await pattern but you're waiting for nothing. for example:
/// <summary>
/// Checks returns the locally registered checks
/// </summary>
/// <returns>A map of the registered check names and check data</returns>
public async Task<QueryResult<Dictionary<string, AgentCheck>>> Checks()
{
return await _client.Get<Dictionary<string, AgentCheck>>("/v1/agent/checks").Execute().ConfigureAwait(false);
}
I don't understand why there is await over there, nothing happens afterwards, why not just return the Task from the Execute method and let the user decide if he wish to await for that or not.
As far as I know there is a little bit of overhead when using IAsyncStateMachine.
So to my final questions:
Thanks,
Hello.
I want to use one ConsulClient for application - is it thread safe? Or I should just create it (in using) wherever I need cause the creation has minimal overhead and internal connection pooling is used?
0.7.0 adds KV transaction support as well as other API changes and these need to be ported in.
I've been using the following code to register services:
var serviceRegistration = new AgentServiceRegistration
{
...
};
Client.Agent.ServiceRegister(serviceRegistration);
It appears there is no way of not setting a port. Am I wrong?
Port is an non-nullable int, which means it is always set, despite the attribute declaring nulls are ignored.
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
What are your thoughts on making a public read-only interface of the configuration options?
We had some tests confirming that configuration options were passed into the client correctly from a wrapper class somewhat similar to https://github.com/PlayFab/consuldotnet/blob/master/Consul.Test/ClientTest.cs#L28
Now that the Config object is internal those tests do not compile obviously. These tests are obviously redundant to your own tests, although still somewhat comforting to confirm our wrapper is working correctly.
I guess since its internal, i think actively debugging it would be able to display how the client is configured, which is probably enough for 90% of uses. But exposing the options in a read-only way might be nice for logging weird cases.
Hello,
I came across this project after researching microservices, specially service discovery in C#, which led me to the Microphone project and from there to here.
My ultimate aim is to use something like Owin-self-hosting, TopShelf, ILRepack and Consul to build small console exes that behave as RESTful microservices and that can simply be deployed onto boxes by copying one exe and have it "just work" - configuration and discovery being automatic.. It would be great for scalability and reliability too.
Microphone looked like a great start, but then I discovered that it doesn't actually use your Consul.Net library. That is not a show-stopper in itself, but that project also seems to be heading towards being agnostic about its back end and providing lots of options (Nancy, ETCD etc.) whereas my feeling is, if you're going to pick Consul, use it, and build something small and targeted at Consul. Too many options just makes for developer confusion and extra maintenance burden. Plus, it seems to be written using DotNetCore which means it pulls in about 40 dependencies and is hard to ILRepack.
So I was wondering about taking the principles and design expressed in Microphone and and just creating (let's say) Consul.Net.ServiceDiscovery.
I have had a look over the Microphone source and there is not a lot of code there, it doesn't feel like a massive job, though I'll need to get my employer to let me do it on their time.
I noted your question here, to which you never got a reply: rogeralsing/Microphone#21
Have you thought about this at all, and do you have any particular direction in mind for Consul.Net?
I have large suolution with 300+ projects targeting .NET 4.5 and I have no chance to target .NET Framework 4.5.1 in next 6 month. Last NuGet package targeting this .NET is v0.6.4.7.
So what can I do now to use Consul v.0.7?
"Core" Consul version 0.6.3.3 (bleeding edge as I write this) loads into MonoDevelop ok (which is just a heuristic for getting along with Mono on my Xubuntu / mono 4.2.2 machine). However, Consul.Test is unhappy with more than just the xunit.runner.visualstudio.2.1.0 Import element declarations in Consul.Test.csproj.
I'd like to potentially contribute to this project, but I'm not able to resolve the above "safely" for users on Windows. If this were resolvable, I'd be in a position to run the tests....
Kind regards
Hi guys!
Thank you for the library 👍
But we have one small trouble using your library - Newtonsoft.Json dependency. Our code base depends on 6.0.8 version and it's very difficult to update it to latest.
What do you think about ilmerging this dependency?
Write docs about how to, from a C# perspective
when i compile, display “无法在 finally 子句体中等待” in await _client.Session.Destroy(id).ConfigureAwait(false);
Hi,
Would you be able to release a strongly named version of this library to Nuget?
I have a project which requires strong naming in assemblies and this failed the build. I was able to pull down the source and build myself but that's not as ideal as nuget as I will miss updates and such.
Thanks,
Mark
Commit cc8c37b has broken consuldotnet v0.6.4.3 on Mono. WebRequestHandler.ClientCertificates
throws a NotImplementedException
in released versions of Mono.
Checking the status code of the k/v get response always return 0.
var getPair = await client.KV.Get(key, setting);
if (getPair.StatusCode == System.Net.HttpStatusCode.OK) // Alaways fail
{
var value = Encoding.UTF8.GetString(getPair.Response.Value, 0, getPair.Response.Value.Length));
}
This would be an enhancement request to create a custom configuration provider that uses Consul under the hood.
https://docs.asp.net/en/latest/fundamentals/configuration.html#writing-custom-providers
From @rmul:
I have an issue and would like to check if you think this is related:
When a semaphore has been aqcuired and the session gets lost (for instance use the api to destroy the session) the RenewPeriodic method throws a "Session no longer exists" exception but catches that also and a cycle later a "Session timed out" exception is thrown which is not handled by the semaphore.acquire method.
If it is not related I am more than willing to create a new issue and help out with it.
This is a broader error in that both locks and semaphores need to be looked at.
What is the best method to set proxy settings and timeouts for the underlying httpclient used by consuldotnet?
Method Agent.UpdateTTL
has parameter note
which value gets encoded via Uri.EscapeDataString(note)
before adding to web request parameters dictionary. It is incorrect because in method ConsulRequest.BuildConsulUri
all uri parameter values gets encoded via Uri.EscapeDataString
. So when we publish some note with service state, its value gets encoded 2 times.
Correct standard service check (proves that it is not consul core bug):
I can send PR with bug fix and tests.
Hi,
In my application I try to join to couple of server nodes (so if the one hard coded server is temporary down, I'm covered :))
However I've seen in Client.cs that you initializing the ConsulClient.HttpClient.Timeout with a hard coded value of 15 minutes:
HttpClient.Timeout = TimeSpan.FromMinutes(15);
(Which mean for me if one Consul node is down or have difficulties responding I need to wait 15 minutes for the result)
I was wondering why this is the value and if I can refactor this to be a configurable value from the ConsulClientConfiguration
By the way, I saw there is a Wait
property in the ConsulClientCofiguration
is it for consul usage?
Thank you very much.
The following throws an exception of Cannot access a disposed object.Object name: 'System.Net.Http.WebRequestHandler'
.
This is because ConsoleClient.Dispose
also calls down to Config.Handler.Dispose()
and Config only creates the Handler
in the constructor.
void Main()
{
var config = new ConsulClientConfiguration();
using (var client = new ConsulClient(config))
{
Console.WriteLine(client.Catalog.Services().Result.StatusCode);
}
using (var client = new ConsulClient(config))
{
Console.WriteLine(client.Catalog.Services().Result.StatusCode);
}
}
I would expect the Configuration settings should not be a holder for a WebRequestHandler, or should rebuild it if the config object is reused. OR the constructor of the client should take in a Action<ConsulClientConfiguration>
to show it can't simply be reused.
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'PushStreamContent' could not be found (are you missing a using directive or an assembly reference?) Consul C:\Users\xxx\Desktop\consuldotnet-master\consuldotnet-master\Consul\Client.cs 949 Active
Hi,
It would be nice to have an interface for the consul client class so that dependency injection/unit testing with mocks could be done properly.
I'm happy to do this and submit a pull request.
Currently, I use Consul for service discovery in ASP.NET Application. But I don't know how to use DNS lookup in Consul Client .NET
The higher-level APIs (eg, ConsulClient.Catalog.Service()
) do not accept CancellationToken
arguments. It would be nice if they did.
It appears that the methods they call into (eg, Consult.GetRequest<T>.Execute()
) do accept a CancellationToken
, so it should just be a matter of adding method overloads and passing the argument through.
Born out of a request in #55, all methods should have a set of overrides that accept a CancellationToken
. This will allow all methods (including Put/Delete/non-poll Get) to be aborted midflight.
I see your client.KV.Get
supports QueryOptions to set consistency modes. But I'm not seeing any tests or documentation on how to use that on client.Agent.Services
. Or did i misread consul docs and that isn't supported on service lookups?
For reference: https://www.consul.io/docs/agent/http.html#consistency-modes
I wonder whether our library for Consul supports for detect Key/Value data changes or not?
Per #33 (comment) onward.
Would be good to explore converting locks to use async because of I/O during creation/teardown.
Sorry about the question but the documentation doesn't not having enough info.
Can this library connect to remote Consul server (not localhost and default port) to register itself as a service for specific data center !
https://www.consul.io/docs/internals/sessions.html
Add support for setting sessionbehavior in lock calls.
Hi,
When specifying LockWaitTime in LockOptions, if LockTryOnce is set, the expected behavior is to block for the lock acquisition for a max of LockWaitTime just once,
The blocking GET call that happens for the lock doesn't block until the wait time is coupled with index value. But the index value isn't obtained until after the first call is made(which ignores the wait time since index to wait on isn't supplied) and this first call fulfills the LockTryOnce criteria and throws an exception after that. So the blocking wait never happens in case LockTryOnce is set.
Can this be fixed so that even in case the requested lock key is already acquired, the wait happens for the specified wait time once?
I added "Consul": "0.7.0.4" to my .net core 1.0 project via nuget in vs2015. The problem was all KV operations on Consul took 5000ms+ while no more than 10ms in .net framework 4.5 platform. Consul version is 0.7.1 in centos7. Here is my test code.
static async Task TestConsulKV(string flag)
{
Stopwatch _watcher = new Stopwatch();
Stopwatch _subWatcher = new Stopwatch();
_watcher.Start();
_subWatcher.Start();
var _count = 0;
var _consul = new ConsulClient(config => config.Address = new Uri("http://172.18.70.71:8500"));
for (; _count < 5; _count++)
{
var _key = $"schema/test/{_count}";
var _existsPair = await _consul.KV.Get(_key);
if (_existsPair.Response != null)
{
Console.WriteLine(Encoding.UTF8.GetString(_existsPair.Response.Value));
}
var _kvPair = new KVPair(_key);
_kvPair.Value = Encoding.UTF8.GetBytes($"{flag ?? "default"}{_count}");
_consul.KV.Put(_kvPair).Wait();
//if (_count % 100 == 0)
//{
Console.WriteLine($"finished {_count} in {_subWatcher.ElapsedMilliseconds}ms");
_subWatcher.Restart();
//}
}
Console.WriteLine($"all finished in {_watcher.ElapsedMilliseconds}ms");
}
If a lock is lost, add an abort of the action if it's not completed within the TTL.
I would like to use your library to add support for Consul to Microsoft Orleans (https://github.com/dotnet/orleans) but the lack of async support is a big issue for that project.
I see there is a PR which has switched the client code to use HttpClient, do you intend to build on this and move to supporting async requests?
Thanks for the work so far!
i create a dev server on 192.168.15.235
and my c# client is on 192.168.15.24
.
the simple sample cost about 150ms
every request KV.Get
. and i used wireshark to test the real latency. and the one single request cost about 1ms
when the response came back.
50 16:22:26.949815 192.168.15.24 192.168.15.235 HTTP 154 GET /v1/kv/hello HTTP/1.1
51 16:22:26.950450 192.168.15.235 192.168.15.24 HTTP 337 HTTP/1.1 200 OK (application/json)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.