Portal Community

Interface Definition

public interface IRuleEngineClient
{
    Task<RuleEvaluationResult> EvaluateAsync(
        RuleEvaluationRequest request,
        CancellationToken cancellationToken = default);
}

public record RuleEvaluationRequest
{
    public string RuleSetId { get; init; } = default!;
    public Dictionary<string, object?> Facts { get; init; } = [];
    public string TenantId { get; init; } = default!;
    public string? CorrelationId { get; init; }
}

public record RuleEvaluationResult
{
    public string Outcome { get; init; } = default!;
    public string[] FiredRules { get; init; } = [];
    public string? Explanation { get; init; }
    public decimal? Score { get; init; }
    public DateTimeOffset EvaluatedAt { get; init; }
    public string RuleSetId { get; init; } = default!;
    public string RuleSetVersion { get; init; } = default!;
}

Implementation Notes

// DI registration:
services.AddHttpClient<IRuleEngineClient, HttpRuleEngineClient>(client =>
{
    client.BaseAddress = new Uri(configuration["RuleEngine:BaseUrl"]!);
    client.Timeout = TimeSpan.FromSeconds(10);
});

// The HttpRuleEngineClient uses Polly for retry:
// - TransientHttpRequestException → retry up to 3 times with exponential backoff
// - HttpStatusCode 429 (rate limited) → retry after Retry-After header delay
// - HttpStatusCode 5xx → retry up to 2 times
CorrelationId: The executor automatically sets CorrelationId to the execution ID (ctx.ExecutionId). This allows the rule engine service logs to be correlated with Flow Studio execution logs for debugging.