Table of Contents

Class ElasticSearchProjectionHostExtensions

Namespace
Excalibur.Data.ElasticSearch.Projections
Assembly
Excalibur.Data.ElasticSearch.dll

Verifies at start-up that the clusters the registered projection stores write to can be reached.

public static class ElasticSearchProjectionHostExtensions
Inheritance
ElasticSearchProjectionHostExtensions
Inherited Members

Remarks

WHAT THIS EXISTS TO PREVENT. A projection store builds its client on first use, so a host that cannot reach its cluster starts normally, reports nothing, and discovers the problem when a background job writes its first document -- as one error per document, inside a job, however long after start-up that job happens to run. The host is up, the logs are quiet, and the read models are not being written. Asking once at start-up turns that into a single answer at the moment a human is watching.

IT IS A SEPARATE CALL, NOT PART OF REGISTRATION, and deliberately so. Refusing to start on an unreachable dependency is a trade, not an improvement: under an orchestrator it converts a transient cluster blip into a crash-loop, and a read-model host that starts degraded and recovers is often the better outcome. The consumer owns that choice, so the consumer makes the call.

IT IS ALSO NOT OPTIONS VALIDATION, which is why it is not expressed as IValidateOptions<TOptions> with ValidateOnStart alongside the configuration checks that already run there. Those answer whether the configuration is well-formed -- a question with the same answer every time it is asked. Reachability has a different answer at two different moments with identical configuration, and reporting it as an invalid-options failure would tell a consumer to go and fix settings that are correct.

Methods

VerifyElasticSearchProjectionConnectivityAsync(IHost, CancellationToken)

Pings every distinct Elasticsearch cluster the registered projection stores are configured to use, and throws when one of them cannot be reached.

public static Task VerifyElasticSearchProjectionConnectivityAsync(this IHost host, CancellationToken cancellationToken = default)

Parameters

host IHost

The application host, after its services are built.

cancellationToken CancellationToken

A token that cancels the probe.

Returns

Task

The asynchronous operation.

Examples

var host = builder.Build();
await host.VerifyElasticSearchProjectionConnectivityAsync();
await host.RunAsync();

Exceptions

ArgumentNullException

Thrown when host is null.

InvalidOperationException

Thrown when no Elasticsearch projection store is registered, or when a configured cluster does not answer. Both are failures: a probe that finds nothing to probe has verified nothing, and reporting success for it would be the silence this method exists to remove.