src/Library/Consul.AspNetCore/README.md

(开头部分) 8KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

## Background Information 

This library is fork from another library [consuldotnet
](https://github.com/G-Research/consuldotnet)

current library support ttl health check
<p align="left"><img width="500" height="250" src=logo/svg/Consul.NET_SignatureLogo_RGB-Black.svg alt="Consul.NET"/></p>

[![CI](https://github.com/G-Research/consuldotnet/actions/workflows/ci.yml/badge.svg?branch=master&event=push)](https://github.com/G-Research/consuldotnet/actions/workflows/ci.yml?query=branch%3Amaster+event%3Apush)
[![](https://img.shields.io/nuget/vpre/consul)](https://www.nuget.org/packages/Consul/absoluteLatest)
[![](https://img.shields.io/feedz/vpre/consuldotnet/preview/consul)](#preview-versions)

* Consul API: [v1.6.10](https://github.com/hashicorp/consul/tree/v1.6.10/api)
* .NET: >= 4.6.1 - .NET Core: >= 2.0.0

Consul.NET is a .NET port of the Go Consul API, but reworked to use .NET
idioms such as Tasks/CancellationTokens instead of Goroutines/Channels.
The majority of the calls directly track the [HTTP
API](https://www.consul.io/docs/agent/http.html), but this API does have
additional functionality that is provided in the Go API, like Locks and
Semaphores.

## Example

You'll need a running Consul Server on your local machine, or a Consul
Agent connected to a Consul Server cluster. To run a local server:

1. [Download a copy](https://www.consul.io/downloads.html) of the latest Windows
version and unzip it into the `Consul.Test` folder.
2. Open a command prompt and `cd` to the `Consul.Test` folder.
3. Run `.\consul.exe agent -dev -config-file test_config.json`

This creates a 1-server cluster that operates in "dev" mode (does not
write data to disk) and listens on `127.0.0.1:8500`.

Once Consul is running (you'll see something like `==> Consul
agent running!`) in your command prompt, then do the following
steps in your project.

Add a reference to the Consul library and add a using statement:

```csharp
using Consul;
```

Write a function to talk to the KV store:

```csharp
public static async Task<string> HelloConsul()
{
    using (var client = new ConsulClient())
    {
        var putPair = new KVPair("hello")
        {
            Value = Encoding.UTF8.GetBytes("Hello Consul")
        };

        var putAttempt = await client.KV.Put(putPair);

        if (putAttempt.Response)
后面还有 170 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。