• This repository has been archived on 27/Apr/2019
  • Stars
    star
    693
  • Rank 65,262 (Top 2 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.NET API for Consul (http://www.consul.io/)

Consul.NET

Build Status

  • Consul API: v0.7.2
  • .NET: >= 4.5 - .NET Core: >= 1.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, 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 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: cluster leadership acquired) in your command prompt, then do the following steps in your project.

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

using Consul;

Write a function to talk to the KV store:

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)
        {
            var getPair = await client.KV.Get("hello");
            return Encoding.UTF8.GetString(getPair.Response.Value, 0,
                getPair.Response.Value.Length);
        }
        return "";
    }
}

And call it:

Console.WriteLine(HelloConsul().GetAwaiter().GetResult());

You should see Hello Consul in the output of your program. You should also see the following lines in your command prompt, if you're running a local Consul server:

[DEBUG] http: Request /v1/kv/hello (6.0039ms)
[DEBUG] http: Request /v1/kv/hello (0)

The API just went out to Consul, wrote "Hello Consul" under the key "hello", then fetched the data back out and wrote it to your prompt.

Usage

All operations are done using a ConsulClient object. First, instantiate a ConsulClient object, which connects to localhost:8500, the default Consul HTTP API port. Once you've got a ConsulClient object, various functionality is exposed as properties under the ConsulClient.

All responses are wrapped in QueryResponse and WriteResponse classes, which provide metadata about the request, like how long it took and the monotonic Consul index when the operation occured.

This API also assumes some knowledge of Consul, including things like blocking queries and consistency modes

ACL

The ACL endpoints are used to create, update, destroy, and query ACL tokens.

Agent

The Agent endpoints are used to interact with the local Consul agent. Usually, services and checks are registered with an agent which then takes on the burden of keeping that data synchronized with the cluster. For example, the agent registers services and checks with the Catalog and performs anti-entropy to recover from outages.

Catalog

The Catalog is the endpoint used to register and deregister nodes, services, and checks. It also provides query endpoints.

Event

The Event endpoints are used to fire new events and to query the available events.

Health

The Health endpoints are used to query health-related information. They are provided separately from the Catalog since users may prefer not to use the optional health checking mechanisms. Additionally, some of the query results from the Health endpoints are filtered while the Catalog endpoints provide the raw entries.

KV

The KV endpoint is used to access Consul's simple key/value store, useful for storing service configuration or other metadata.

Query

The Prepared Query endpoints are used to create, update, destroy, and execute prepared queries. Prepared queries allow you to register a complex service query and then execute it later via its ID or name to get a set of healthy nodes that provide a given service.

Session

The Session endpoints are used to create, destroy, and query sessions.

Status

The Status endpoints are used to get information about the status of the Consul cluster. This information is generally very low level and not often useful for clients.

Additional Functions

Functionality based on the Consul guides using the available primitives has been implemented as well, just like the Go API.

Lock

Lock is used to implement client-side leader election for a distributed lock. It is an implementation of the Consul Leader Election guide.

Semaphore

Semaphore is used to implement a distributed semaphore using the Consul KV primitives. It is an implementation of the Consul Semaphore guide.

Using with .NET Core and Mono

Both .NET 4.5+ and .NET Core 1.0+ are fully supported. Mono is supported on a best-effort basis. It should compile and run happily on Mono but this is not as heavily tested as Microsoft .NET stacks. If you have any issues using the Nuget package or compiling this code with .NET, .NET Core, or Mono, please file a Github issue with details of the problem.

More Repositories

1

UnitySDK

Unity C# SDKs for PlayFab
C#
349
star
2

thundernetes

Thundernetes makes it easy to run your game servers on Kubernetes
Go
311
star
3

PlayFab-Samples

This repository contains Sample code, Recipes and Video Tutorials demonstrating how to integrate various PlayFab features
C#
203
star
4

MpsSamples

Samples that show how to use PlayFab's Gameserver SDK for Multiplayer Servers
C#
149
star
5

gsdk

Game Server SDK for PlayFab Multiplayer Servers
C++
145
star
6

UnrealMarketplacePlugin

Source code for the PlayFab Marketplace Plugin for Unreal
C++
125
star
7

UnicornBattle

A complete example title showing a complete PlayFab integration with complex game systems.
C#
120
star
8

PlayFabGameServer

Out of the Box Game Server for PlayFab.com
C#
99
star
9

CSharpSDK

SDK for C#/.net environments other than Unity
C#
71
star
10

PlayFab

This repo is the official home of PlayFab on GitHub. Subscribe to it to be notified of announcements and service releases.
71
star
11

SDKGenerator

SDK Generator, produces the source code for all PlayFab SDKs.
C#
69
star
12

MpsAgent

Azure PlayFab Multiplayer Servers LocalMultiplayerAgent project and helper libraries
C#
48
star
13

PostmanCollection

PlayFab Postman Collection
45
star
14

JavaScriptSDK

JavaScriptSDK for the Client API of PlayFab
JavaScript
45
star
15

vanguard-outrider

A demo game for populating Azure PlayFab titles
TypeScript
41
star
16

PlayFabPartyUnity

39
star
17

LuaSdk

PlayFab Lua SDK for LuaDist command-line, Defold, and more
Lua
39
star
18

PlayFabMultiplayerUnreal

PlayFab Online Subsystem Plugin for Unreal Engine
C++
39
star
19

API_Specs

JSON files describing PlayFab's HTTP APIs
JavaScript
36
star
20

NodeSDK

Playfab SDK for node.js applications
JavaScript
34
star
21

XPlatCppSdk

Cross Platform C++ SDK
C++
33
star
22

CloudScriptSamples

Sample scripts demonstrating custom game logic for hosting in PlayFab.
JavaScript
29
star
23

SdkTestingCloudScript

This is the Cloud Script used for the internal testing of all SDKs.
TypeScript
26
star
24

vscode-playfab-explorer

PlayFab Explorer extension for VS Code
TypeScript
23
star
25

UnityEditorExtensions

The home for PlayFab's Unity Editor plugin. This plugin houses a custom inspector for viewing and configuring the PlayFab SDK.
C#
23
star
26

LocalMultiplayerAgent

An executable that mimics PlayFab Multiplayer (Thunderhead) operations to aid in local debugging.
22
star
27

JavaSDK

PlayFab SDK for Java applications
Java
20
star
28

PlayFabParty

The libraries, headers, and documentation for accessing the PlayFab Party feature.
C++
20
star
29

mpscommunity

Community content for Azure PlayFab Multiplayer Servers
18
star
30

ActionScriptSDK

ActionScript3 SDK for use in Adobe Flash and AIR.
ActionScript
16
star
31

PlayFabCLI

Tool for using PlayFab via CLI
C#
16
star
32

MultiplayerServerSecureWebsocket

Reverse proxy sample project to enable web socket connections over https to PlayFab hosted game servers.
C#
13
star
33

pf-af-devfuncs

Azure Functions related to the PlayFab developer experience
C#
11
star
34

PlayFabAssetBundleManager

Modification To AssetBundleManager for use with PlayFab
C#
11
star
35

PythonSdk

PlayFab Python Sdk
Python
9
star
36

Cocos2d-xSDK

PlayFab SDKs for c++ based Cocos2d-x game development
C++
7
star
37

Objective_C_SDK

OSX / iOS native SDK
Objective-C
7
star
38

MpsPowershell

Powershell client for the PlayFab Multiplayer Servers API.
PowerShell
7
star
39

PhpSdk

PHP Sdk for PlayFab https://api.playfab.com/sdks/php
PHP
7
star
40

PlayFabMultiplayerUnity

PlayFab Multiplayer Unity SDK
7
star
41

PlayFabUnityRumble

A sample multiplayer game intended to demonstrate the use of PlayFab Party and Multiplayer Unity SDKs in games.
C#
4
star
42

MultiplayerPowershell

Powershell cmdlets for Multiplayer service
C#
4
star
43

VmStartupScriptGallery

Repository containing samples and starter templates for the VmStartupScript feature of Azure PlayFab Multiplayer Servers
PowerShell
4
star
44

PlayFabCSdk

C++
3
star
45

PlayFabPowerBITemplates

This repository contains Power BI templates to quickly access key game KPIs.
3
star
46

thundernetescontrib

Helpful utilities for Thundernetes
Go
3
star
47

XPlatCoreTemplate

The template files for the XPlat build, and core template files for private builds
C++
3
star
48

thundernetes-ui

Thundernetes UI is a frontend for Thundernetes that allows you to visualize and interact with your game server clusters
TypeScript
3
star
49

UeDemo

A Breakout game with the UE PlayFab Plugin integrated and utilized
C++
2
star
50

PlayFabMultiplayer

PlayFab Multiplayer C++ SDK
PowerShell
2
star
51

PlayFabNetRumble

A sample multiplayer game intended to demonstrate the use of PlayFab Party and Multiplayer C++ SDKs in games.
C++
2
star
52

.github

1
star