{"id":19990873,"url":"https://github.com/stulzq/NConsul","last_synced_at":"2025-05-04T10:30:48.732Z","repository":{"id":53240937,"uuid":"224350718","full_name":"stulzq/NConsul","owner":"stulzq","description":".NET API for Consul (http://www.consul.io/)","archived":true,"fork":false,"pushed_at":"2021-07-21T02:43:40.000Z","size":777,"stargazers_count":61,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T19:19:54.898Z","etag":null,"topics":["consul","grpc"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stulzq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-27T05:22:06.000Z","updated_at":"2024-08-25T22:47:48.000Z","dependencies_parsed_at":"2022-08-19T20:20:36.365Z","dependency_job_id":null,"html_url":"https://github.com/stulzq/NConsul","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FNConsul","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FNConsul/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FNConsul/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stulzq%2FNConsul/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stulzq","download_url":"https://codeload.github.com/stulzq/NConsul/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252319994,"owners_count":21729055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consul","grpc"],"created_at":"2024-11-13T04:51:30.745Z","updated_at":"2025-05-04T10:30:47.948Z","avatar_url":"https://github.com/stulzq.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"Please support https://github.com/G-Research/consuldotnet , this repo is no longer maintained\n\n# Consul.NET\n\nFork from https://github.com/PlayFab/consuldotnet and Support GRPC.\n\n* Consul API: [v0.7.2](https://github.com/hashicorp/consul/tree/v0.7.2/api)\n* .NET Core: \u003e= 2.0\n\nConsul.NET is a .NET port of the Go Consul API, but reworked to use .NET\nidioms such as Tasks/CancellationTokens instead of Goroutines/Channels.\nThe majority of the calls directly track the [HTTP\nAPI](https://www.consul.io/docs/agent/http.html), but this API does have\nadditional functionality that is provided in the Go API, like Locks and\nSemaphores.\n\n## GRPC Check Example\n\n````csharp\nvar consulClient = new ConsulClient(x =\u003e x.Address = new Uri($\"http://localhost:8500\"));\nvar grpCheck = new AgentServiceCheck()\n{\n    DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(5),\n    Interval = TimeSpan.FromSeconds(10),\n    GRPC = \"127.0.0.1:5000\",\n    GRPCUseTLS = false,\n    Timeout = TimeSpan.FromSeconds(10)\n};\nvar registration = new AgentServiceRegistration()\n{\n    Checks = new[] { grpCheck },\n    ID = Guid.NewGuid().ToString(),\n    Name = \"grpctest\",\n    Address = \"localhost\",\n    Port = 5000,\n    Tags = new[] { $\"xc/grpc/test\" }\n};\n\nawait consulClient.Agent.ServiceRegister(registration);\n````\n\n## ASP.NET Core\n\n````csharp\nservices.AddConsul(\"http://localhost:8500\")\n    .AddGRPCHealthCheck(\"localhost:5000\")\n    .RegisterService(\"grpctest\",\"localhost\",5000,new []{\"xc/grpc/test\"});\n````\n\n## Example\n\nYou'll need a running Consul Server on your local machine, or a Consul\nAgent connected to a Consul Server cluster. To run a local server:\n\n1. [Download a copy](https://www.consul.io/downloads.html) of the latest Windows\nversion and unzip it into the `Consul.Test` folder.\n2. Open a command prompt and `cd` to the `Consul.Test` folder.\n3. Run `.\\consul.exe agent -dev -config-file test_config.json`\n\nThis creates a 1-server cluster that operates in \"dev\" mode (does not\nwrite data to disk) and listens on `127.0.0.1:8500`.\n\nOnce Consul is running (you'll see something like `consul: cluster\nleadership acquired`) in your command prompt, then do the following\nsteps in your project.\n\nAdd a reference to the Consul library and add a using statement:\n\n```csharp\nusing Consul;\n```\n\nWrite a function to talk to the KV store:\n\n```csharp\npublic static async Task\u003cstring\u003e HelloConsul()\n{\n    using (var client = new ConsulClient())\n    {\n        var putPair = new KVPair(\"hello\")\n        {\n            Value = Encoding.UTF8.GetBytes(\"Hello Consul\")\n        };\n\n        var putAttempt = await client.KV.Put(putPair);\n\n        if (putAttempt.Response)\n        {\n            var getPair = await client.KV.Get(\"hello\");\n            return Encoding.UTF8.GetString(getPair.Response.Value, 0,\n                getPair.Response.Value.Length);\n        }\n        return \"\";\n    }\n}\n```\n\nAnd call it:\n\n```csharp\nConsole.WriteLine(HelloConsul().GetAwaiter().GetResult());\n```\n\nYou should see `Hello Consul` in the output of your program. You should\nalso see the following lines in your command prompt, if you're running\na local Consul server:\n\n```\n[DEBUG] http: Request /v1/kv/hello (6.0039ms)\n[DEBUG] http: Request /v1/kv/hello (0)\n```\n\nThe API just went out to Consul, wrote \"Hello Consul\" under the key\n\"hello\", then fetched the data back out and wrote it to your prompt.\n\n## Usage\n\nAll operations are done using a `ConsulClient` object. First,\ninstantiate a `ConsulClient` object, which connects to `localhost:8500`,\nthe default Consul HTTP API port. Once you've got a `ConsulClient`\nobject, various functionality is exposed as properties under the\n`ConsulClient`.\n\nAll responses are wrapped in `QueryResponse` and `WriteResponse`\nclasses, which provide metadata about the request, like how long it\ntook and the monotonic Consul index when the operation occured.\n\nThis API also assumes some knowledge of Consul, including things like\n[blocking queries and consistency\nmodes](https://www.consul.io/docs/agent/http.html)\n\n### ACL\n\nThe ACL endpoints are used to create, update, destroy, and query ACL tokens.\n\n### Agent\n\nThe Agent endpoints are used to interact with the local Consul agent.\nUsually, services and checks are registered with an agent which then\ntakes on the burden of keeping that data synchronized with the cluster.\nFor example, the agent registers services and checks with the Catalog\nand performs anti-entropy to recover from outages.\n\n### Catalog\n\nThe Catalog is the endpoint used to register and deregister nodes,\nservices, and checks. It also provides query endpoints.\n\n### Event\n\nThe Event endpoints are used to fire new events and to query the\navailable events.\n\n### Health\n\nThe Health endpoints are used to query health-related information. They\nare provided separately from the Catalog since users may prefer not to\nuse the optional health checking mechanisms. Additionally, some of the\nquery results from the Health endpoints are filtered while the Catalog\nendpoints provide the raw entries.\n\n### KV\n\nThe KV endpoint is used to access Consul's simple key/value store,\nuseful for storing service configuration or other metadata.\n\n### Query\n\nThe Prepared Query endpoints are used to create, update, destroy, and\nexecute prepared queries. Prepared queries allow you to register a\ncomplex service query and then execute it later via its ID or name to\nget a set of healthy nodes that provide a given service.\n\n### Session\n\nThe Session endpoints are used to create, destroy, and query sessions.\n\n### Status\n\nThe Status endpoints are used to get information about the status of the\nConsul cluster. This information is generally very low level and not\noften useful for clients.\n\n### Additional Functions\n\nFunctionality based on the Consul guides using the available primitives\nhas been implemented as well, just like the Go API.\n\n### Lock\n\nLock is used to implement client-side leader election for a distributed\nlock. It is an implementation of the [Consul Leader\nElection](https://consul.io/docs/guides/leader-election.html) guide.\n\n### Semaphore\n\nSemaphore is used to implement a distributed semaphore using the Consul\nKV primitives. It is an implementation of the [Consul Semaphore\n](https://www.consul.io/docs/guides/semaphore.html) guide.\n\n## Using with .NET Core and Mono\n\nBoth .NET 4.5+ and .NET Core 1.0+ are fully supported. Mono is supported on a\nbest-effort basis. It should compile and run happily on Mono but this is not as\nheavily tested as Microsoft .NET stacks. If you have any issues using the Nuget\npackage or compiling this code with .NET, .NET Core, or Mono, please file a\nGithub issue with details of the problem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2FNConsul","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstulzq%2FNConsul","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstulzq%2FNConsul/lists"}