Skip to content

Keep a watch on the key which doesn't have children? #112

@TechGeeky

Description

@TechGeeky

I have a node (with data) in Consul like below:

Node: data/stage/process
Data: {"key1":value1,"key2":"value2","key3":"value3"}

I don't have any other children of "process" node in Consul. I just have json data for that node and that's all.

Now I keep a watch on that same node from below code. My idea is to keep a watch on the same node and get the value of "process" key in the code and whenever it is updated again from outside I want my watch to be triggered as well and then get the value of "process" key again on every reload whenever there is a change.

    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddConsul(
            $"data/stage/process",
            options =>
            {
                options.ConsulConfigurationOptions =
                    cco => { cco.Address = new Uri("some-url"); };
                options.Optional = true;
                options.PollWaitTime = TimeSpan.FromSeconds(5);
                options.ReloadOnChange = true;
                options.Parser = new SimpleConfigurationParser();
                options.OnWatchException = ctx => TimeSpan.FromSeconds(ctx.ConsecutiveFailureCount);
            })
        .AddEnvironmentVariables();
    Configuration = builder.Build();

With the above code when I run it, I get an exception as below:

'The key must not be null or empty. Ensure that there is at least one key under the root of the process or that the data there contains more than just a single value.'

But if I just keep a watch on "data/stage" node then it works fine without any error and I can get the value of "process" key in the code so my question is - can I not just keep a watch on the same node for which I want to get the value also?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions