Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/mediator-framework/progress/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ the framework libraries.
3. [x] AZF-01 → [x] AZF-02 → [x] AZF-03.
4. [x] AZF-04 → [x] AZF-05.
5. [x] [AZF-06](azure-functions/AZF-06-files-streaming.md) → [x] [AZF-07](azure-functions/AZF-07-one-way-rebus.md) (independent after AZF-05).
6. [ ] AZF-08.
6. [x] AZF-08.
Comment thread
AndreaCuneo marked this conversation as resolved.
Resolved
7. [ ] AZF-10. AZF-09 remains deferred until AZD-11 is reopened.

Also see [`../future-improvements.md`](../future-improvements.md) (WebApplicationFactory auth substitution, AoT sample, N6, N9).
Expand Down
1 change: 1 addition & 0 deletions samples/Ark.MediatorFramework.Sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Rebus client. Use a namespace with `DefaultAzureCredential` in managed
environments, or a connection string from external configuration for local use.
The Function process has no input queue, workers, subscriptions, handlers, or
request/reply bus semantics; messages are consumed by the separate processor.
The anonymous readiness endpoint is `/healthCheck`, using the shared ASP.NET Core health check middleware.
Comment thread
AndreaCuneo marked this conversation as resolved.
Resolved

## gRPC operations panel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public static void Register(
container.Register<IRequestHandler<CompleteGreetingCompositionRequest, GreetingResponse>, CompleteGreetingCompositionHandler>();
container.Register<IQueryHandler<GetGreetingQuery, GreetingResponse>, GetGreetingHandler>();
container.Register<IQueryHandler<GetGreetingV2Query, GreetingResponseV2>, GetGreetingV2Handler>();
container.Register<IQueryHandler<HealthCheckQuery, HealthCheckResponse>, HealthCheckHandler>();
container.Register<IQueryHandler<GetAuditsQuery, PagedResult<AuditRecord>>, GetAuditsHandler>();
container.Register<IQueryHandler<SearchGreetingsQuery, GreetingPage>, SearchGreetingsHandler>();
container.Register<IQueryHandler<GetGreetingsStreamQuery, IAsyncEnumerable<GreetingStreamItem>>, GetGreetingsStreamHandler>();
Expand Down
Comment thread
AndreaCuneo marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@

namespace Ark.MediatorFramework.Sample.Application;

/// <summary>Returns the readiness state of a function host.</summary>
public sealed record HealthCheckQuery : IQuery<HealthCheckResponse>;

/// <summary>Readiness response returned by both HTTP hosts.</summary>
public sealed record HealthCheckResponse
{
/// <summary>Gets the readiness state.</summary>
public string Status { get; init; } = "Healthy";

/// <summary>Gets the health check duration.</summary>
public string TotalDuration { get; init; } = "00:00:00";

/// <summary>Gets the individual health check results.</summary>
public IReadOnlyDictionary<string, string> Entries { get; init; } =
new Dictionary<string, string>(StringComparer.Ordinal);
}

/// <summary>Response returned by the greeting operations.</summary>
[ProtoContract]
[MessagePackObject(true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@

namespace Ark.MediatorFramework.Sample.Application;

/// <summary>Handles the anonymous host readiness query.</summary>
public sealed class HealthCheckHandler : IQueryHandler<HealthCheckQuery, HealthCheckResponse>
Comment thread
AndreaCuneo marked this conversation as resolved.
Resolved
{
/// <inheritdoc />
public async Task<HealthCheckResponse> ExecuteAsync(
HealthCheckQuery query,
CancellationToken ctk = default)
{
ArgumentNullException.ThrowIfNull(query);
await Task.CompletedTask.ConfigureAwait(false);
return new HealthCheckResponse();
}
}

/// <summary>Handles the synchronous refresh command.</summary>
public sealed class RefreshGreetingHandler : ICommandHandler<RefreshGreetingCommand>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Ark.MediatorFramework.Sample.Application;
using Ark.MediatorFramework.Sample.RebusProcessor;

using Ark.Tools.Solid.Authorization;

using Azure.Identity;

using Rebus.Config;
Expand Down Expand Up @@ -31,6 +33,8 @@ public static Container BuildContainer(string? serviceBusConnectionString)

var container = new Container();
ApplicationComposition.Register(container, useSqlStore: false);
container.RegisterAuthorization();
container.RegisterAuthorizationHandler<ScopeAuthorizationHandler>();
Comment thread
AndreaCuneo marked this conversation as resolved.
Resolved
ApplicationComposition.RegisterOutboundRebus(
container,
transport => ConfigureTransport(transport, serviceBusConnectionString),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Ark.MediatorFramework.Sample.Application;
using Ark.MediatorFramework.AzureFunctions;

using Microsoft.AspNetCore.Authorization;
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -32,6 +33,12 @@ public static void Main(string[] args)
#pragma warning restore CA2000
builder.Services.AddArkAzureFunctions(rebusContainer);
builder.Services.AddArkAzureFunctionsBearerAuthentication();
builder.Services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});
builder.Services.AddHostedService(_ => new AzureFunctionsRebusHostedService(rebusContainer));

builder.Build().Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Ark.Tools.Rebus" />
<PackageReference Include="Ark.Tools.AspNetCore.MessagePack" />
<PackageReference Include="Ark.Tools.AspNetCore.ApplicationInsights" />
<PackageReference Include="Ark.Tools.AspNetCore.HealthChecks" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="protobuf-net.Grpc.AspNetCore.Reflection" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Ark.MediatorFramework.Sample.WebInterface.Auth;
using Ark.Tools.AspNetCore.MessagePackFormatter;
using Ark.Tools.AspNetCore.ProblemDetails;
using Ark.Tools.AspNetCore.HealthChecks;
using Ark.Tools.MediatorFramework.Grpc;
using Ark.Tools.MediatorFramework.MinimalApi;
using Ark.Tools.Nodatime;
Expand Down Expand Up @@ -142,6 +143,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddRouting();
services.AddControllers();
services.AddArkHealthChecks();

var messagePackResolver = CompositeResolver.Create(
MessagePack.NodaTime.NodatimeResolver.Instance,
Expand Down Expand Up @@ -198,6 +200,7 @@ public void Configure(IApplicationBuilder app)
// Source-generated endpoints for the selected [HttpEndpoint] contracts.
endpoints.MapArkEndpointsFromAssembly<global::Ark.MediatorFramework.Sample.Application.RefreshGreetingCommand>(
versionPrefix: "/api/v{version}");
endpoints.MapArkHealthChecks();
endpoints.MapArkGrpcServicesFromAssembly<global::Ark.MediatorFramework.Sample.Application.RefreshGreetingCommand>();
endpoints.MapGrpcService<DocumentsGrpcService>();
endpoints.MapCodeFirstGrpcReflectionService().AllowAnonymous();
Expand Down
Loading
Loading