JasperFx 0.8.2





Jasper.Consul Edit on GitHub

The Jasper.Consul extension is an integration with the outstanding Consul tool for service discovery and configuration. This extension uses the ConsulDotNet library to read and write to Consul using its HTTP API.

Uri Lookups

You can use the Consul Key/Value store for Uri aliasing in any place where Uri's are part of the service bus configuration. Here's an example:

public class ConsulUsingApp : JasperRegistry
    public ConsulUsingApp()
        // These calls are looking up values from the Key/Value
        // store in Consul

In the sample above, the Uri consul://one would refer to a Uri string in the key/value store with the key "one."

See Configuring the Service Bus for more information about Uri lookups.


For dynamic subscriptions, you can opt into using Consul as Jasper's service discovery mechanism by applying the ConsulBackedSubscriptions extension as shown below:

public class AppUsingConsulBackedSubscriptions : JasperRegistry
    public AppUsingConsulBackedSubscriptions()

The subscriptions are stored in Consul's key/value store using the pattern jasper/subscription/[message-type]/[url encoded destination], and the value is a Json document reflecting the valid message representations for the subscriber.

Node Discovery

Node Registration and Discovery with Consul is automatically enabled if you have Jasper.Consul installed in your system.

Customizing Consul Setup

By default, Jasper.Consul will connect to Consul at port 8500, but you can completely configure how the underlying ConsulDotNet ConsulClient will be built out like this:

public class AppUsingConsul : JasperRegistry
    public AppUsingConsul()
        // In this case, we're expecting an environment
        // variable called "Consul.Port"


    public void ConfigureConsul(WebHostBuilderContext context, ConsulSettings settings)
        var config = context.Configuration;

        // Shorthand to use the default Consul setup, but with a different port
        // number retrieved from the application configuration
        settings.Port = config.GetValue<int>("Consul.Port");

        // Configure the underlying ConsulClientConfiguration object
        settings.Configure = _ =>
            // This line is an equivalent to "settings.Port = #" as shown above
            _.Address = $"http://localhost:{config["Consul.Port"]}".ToUri();

            _.Token = config["Consul.Token"];

        // ConsulDotNet allows you to further configure the HttpClient
        // that it uses internallly to talk to Consul
        settings.ClientOverride = httpClient =>
            httpClient.Timeout = 1.Seconds();

        // ConsulDotNet also allows you to configure the HttpClientHandler
        // that it uses internally to talk to Consul
        settings.HandlerOverride = httpClientHandler =>
            httpClientHandler.AutomaticDecompression = DecompressionMethods.None;