Consul .NET Client API

website·Indexed 32 days ago

https://consuldot.net

API documentation for the Consul .NET client library (Consul.dll). It provides interfaces and classes for interacting with Consul API endpoints, including IKVEndpoint for key-value store operations, IHealthEndpoint for health checks, IAgentEndpoint for agent management, and ICatalogEndpoint for catalog operations, as well as support for ACL tokens and TLS configuration.

Tokens
139.2K
Snippets
1.1K
Records
1.3K
Agent score
64%

What's inside Consul

  1. Overview of Consul.NET

    Consul.NET is a .NET port of the Go Consul API. While most of its calls track the standard Consul HTTP API, it provides additional functionality found in the Go API, such as Locks and Semaphores. The library is designed using .NET idioms, utilizing Tasks and CancellationTokens instead of Goroutines and Channels. It is not tied to a specific Consul server version.
  2. Configure JWT validation for service mesh proxies using JWTProviderEntry

    The JWTProviderEntry class in the Consul namespace is used to configure Consul to use JSON Web Tokens (JWT) and JSON Web Key Sets (JWKS). This allows the addition of JWT validation to proxies within the service mesh.
    public class JWTProviderEntry
  3. PreparedQuery Class Overview

    The PreparedQuery class (Namespace: Consul, Assembly: Consul.dll) implements the IPreparedQueryEndpoint interface. It is the primary entry point for managing prepared queries in Consul, allowing developers to define queries once and execute them repeatedly by ID or name.
  4. Report an issue in Consul.NET

    When opening a new issue for a bug or feature request in Consul.NET, provide the following details to ensure a faster resolution: an overview of the issue (including stack traces for errors), the motivation or use case, the Consul.NET version (and whether it is a regression), the Consul Server version, the operating system, a reproducible example or set of steps, any related issues, and a suggested fix if known.
  5. Use the PolicyLink class to represent Consul ACL Policies

    The PolicyLink class (located in the Consul namespace within Consul.dll) serves as the base representation for an Access Control List (ACL) Policy in Consul. It allows developers to track the unique identifier and the human-readable name of a policy.
    using Consul;
    
    // Example of initializing a PolicyLink
    var policy = new PolicyLink("policy-id", "policy-name");
  6. Implement client-side leader election with Consul.Lock

    The Lock class in the Consul namespace (Assembly: Consul.dll) is used to implement client-side leader election. It implements the IDistributedLock interface and follows the standard Consul leader election algorithm. Because Consul sessions prefer liveness over safety, locks can be lost at any time due to session invalidation, communication errors, or operator intervention. Developers must check the IsHeld property before entering critical sections of code.
    while (myLock.IsHeld) 
    {
        // critical section
    }
  7. Use the ConsulLicense class to manage license state

    The ConsulLicense class in the Consul namespace (contained in Consul.dll) provides information about the current license status of the Consul instance. It includes properties to retrieve the license object, check if the license is valid, and view any associated warnings.
    public class ConsulLicense
  8. Use the ClusterPeeringStatus class to track Consul cluster peering

    The ClusterPeeringStatus class in the Consul namespace (Assembly: Consul.dll) represents the current status of a cluster peering connection in Consul. It provides details about the peering identity, server addresses, connection state, and stream status.
    public class ClusterPeeringStatus
  9. Manage ACL Roles using the Role class

    The Role class (Namespace: Consul, Assembly: Consul.dll) is used to interact with ACL Roles in Consul through the API. It implements the IRoleEndpoint interface and provides methods for the full lifecycle of ACL roles.
  10. Use the PolicyEntry class to represent Consul ACL Policies

    The PolicyEntry class in the Consul namespace (Assembly: Consul.dll) is used to define and manage ACL Policies in Consul. It contains metadata about the policy, including its unique identifier, name, description, the actual rules governing access, and the datacenters where the policy applies.
    using Consul;
    
    // Example: Creating a policy entry with basic details
    var policy = new PolicyEntry("policy-id", "Policy Name");
  11. Use the CatalogRegistration class in Consul .NET

    The CatalogRegistration class in the Consul namespace (Assembly: Consul.dll) is used to represent a service registration within the Consul catalog. It contains details about the node, the service instance, and its health check configuration.
    public class CatalogRegistration
    {
        public string Address { get; set; }
        public AgentCheck Check { get; set; }
        public string Datacenter { get; set; }
        public string Node { get; set; }
        public AgentService Service { get; set; }
    }
  12. ISnapshotEndpoint Interface Overview

    The ISnapshotEndpoint interface, located in the Consul namespace within Consul.dll, defines the contract for interacting with the Consul Snapshot API endpoints. It provides the primary mechanisms for backing up (Save) and recovering (Restore) the cluster state.