Couchbase.Extensions.DnsDiscovery 2.0.1

A .Net Core compatible DNS SRV mechanism for discovering a Couchbase cluster dynamically.

There is a newer version of this package available.
See the version list below for details.
Install-Package Couchbase.Extensions.DnsDiscovery -Version 2.0.1
dotnet add package Couchbase.Extensions.DnsDiscovery --version 2.0.1
<PackageReference Include="Couchbase.Extensions.DnsDiscovery" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Couchbase.Extensions.DnsDiscovery --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Couchbase.Extensions.DnsDiscovery, 2.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Couchbase.Extensions.DnsDiscovery as a Cake Addin
#addin nuget:?package=Couchbase.Extensions.DnsDiscovery&version=2.0.1

// Install Couchbase.Extensions.DnsDiscovery as a Cake Tool
#tool nuget:?package=Couchbase.Extensions.DnsDiscovery&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Couchbase.Extensions.DnsDiscovery

A .Net Core compatible DNS SRV mechanism for discovering a Couchbase cluster dynamically.

Getting Started

Assuming you have an installation of Couchbase Server and Visual Studio (examples with VSCODE forthcoming), do the following:

  • Create a .NET Core Web Application using Visual Studio or VsCodeor CIL
  • Install the package from NuGet or build from source and add reference

Configuration

To use, call AddCouchbaseDnsDiscovery during the service registration process, usually in your Startup class. You may choose whether or not to add this step based on the environment. Be sure to add the basic Couchbase configuration first.

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();

        Configuration = builder.Build();
        Environment = env;
    }

    public IConfigurationRoot Configuration { get; }
    public IHostingEnvironment Environment { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // Register Couchbase with configuration section
        services.AddCouchbase(Configuration.GetSection("Couchbase"));
        services.AddCouchbaseDnsDiscovery();

        // Register other services, like .AddMvc()
    }

Example configuration file:

{
    "Couchbase": {
        "Username": "Administrator",
        "Password": "Password",
        "Servers": [
            "couchbase://services.local/"
        ]
    }
}

The above configuration will perform a DNS SRV query for _couchbase._tcp.services.local, based on the single entry in the Servers section of the configuration. The results will be used to replace the Servers list in the Couchbase client configuration.

The following rules will be applied:

  1. There must be only one URI in the Servers collection
  2. The URI must use either the "couchbase://" or "couchbases://" scheme
  3. The URI must not have a port number
  4. If these rules aren't matched, or if no DNS SRV records is found, then the client will fallback to directly connecting to the listed URIs

Note that only the servers with the highest priority in the DNS SRV response will be used. For example, if the response returns 2 servers with a priority of 10 and 2 different servers with a priority of 20, the first set will be used to initialize the cluster. SRV record failover is not supported.

Additionally, due to the nature of Couchbase clusters, the weight fields in the DNS SRV records are ignored. However, the port is used and should normally be set to 8091.

Couchbase.Extensions.DnsDiscovery

A .Net Core compatible DNS SRV mechanism for discovering a Couchbase cluster dynamically.

Getting Started

Assuming you have an installation of Couchbase Server and Visual Studio (examples with VSCODE forthcoming), do the following:

  • Create a .NET Core Web Application using Visual Studio or VsCodeor CIL
  • Install the package from NuGet or build from source and add reference

Configuration

To use, call AddCouchbaseDnsDiscovery during the service registration process, usually in your Startup class. You may choose whether or not to add this step based on the environment. Be sure to add the basic Couchbase configuration first.

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();

        Configuration = builder.Build();
        Environment = env;
    }

    public IConfigurationRoot Configuration { get; }
    public IHostingEnvironment Environment { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // Register Couchbase with configuration section
        services.AddCouchbase(Configuration.GetSection("Couchbase"));
        services.AddCouchbaseDnsDiscovery();

        // Register other services, like .AddMvc()
    }

Example configuration file:

{
    "Couchbase": {
        "Username": "Administrator",
        "Password": "Password",
        "Servers": [
            "couchbase://services.local/"
        ]
    }
}

The above configuration will perform a DNS SRV query for _couchbase._tcp.services.local, based on the single entry in the Servers section of the configuration. The results will be used to replace the Servers list in the Couchbase client configuration.

The following rules will be applied:

  1. There must be only one URI in the Servers collection
  2. The URI must use either the "couchbase://" or "couchbases://" scheme
  3. The URI must not have a port number
  4. If these rules aren't matched, or if no DNS SRV records is found, then the client will fallback to directly connecting to the listed URIs

Note that only the servers with the highest priority in the DNS SRV response will be used. For example, if the response returns 2 servers with a priority of 10 and 2 different servers with a priority of 20, the first set will be used to initialize the cluster. SRV record failover is not supported.

Additionally, due to the nature of Couchbase clusters, the weight fields in the DNS SRV records are ignored. However, the port is used and should normally be set to 8091.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.2 16,580 5/9/2018
2.0.1 5,168 3/1/2018
2.0.0 993 11/8/2017
1.0.2 3,670 8/7/2017
1.0.0 1,102 2/15/2017
1.0.0-beta4 622 1/26/2017
1.0.0-beta2 572 1/8/2017