-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a10bb8
commit a0ffa07
Showing
19 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Aspire/Aspire.Hosting.EventStore/Aspire.Hosting.EventStore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Description>EventStore support for .NET Aspire.</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
43 changes: 43 additions & 0 deletions
43
src/Aspire/Aspire.Hosting.EventStore/EventStoreBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
using Aspire.Hosting.EventStore; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
public static class EventStoreBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds an EventStore resource to the application model. A container is used for local development. | ||
/// This package defaults to the 20.10.0-buster-slim tag of the eventstore container image. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param> | ||
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param> | ||
/// <param name="httpPort">The port on which the EventStore HTTP endpoint will be exposed.</param> | ||
/// <param name="tcpPort">The port on which the EventStore TCP endpoint will be exposed.</param> | ||
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||
public static IResourceBuilder<EventStoreResource> AddEventStore( | ||
this IDistributedApplicationBuilder builder, string name, int? httpPort = null, int? tcpPort = null) | ||
{ | ||
var eventStoreContainer = new EventStoreResource(name); | ||
|
||
return builder | ||
.AddResource(eventStoreContainer) | ||
.WithEndpoint(port: tcpPort, targetPort: EventStoreResource.DefaultTcpPort, name: EventStoreResource.TcpEndpointName) | ||
.WithHttpEndpoint(port: httpPort, targetPort: EventStoreResource.DefaultHttpPort, name: EventStoreResource.HttpEndpointName) | ||
.WithImage(EventStoreContainerImageTags.Image, EventStoreContainerImageTags.Tag) | ||
.WithImageRegistry(EventStoreContainerImageTags.Registry) | ||
.WithEnvironment(context => ConfigureEventStoreContainer(context, eventStoreContainer)); | ||
} | ||
|
||
private static void ConfigureEventStoreContainer(EnvironmentCallbackContext context, EventStoreResource resource) | ||
{ | ||
context.EnvironmentVariables.Add("EVENTSTORE_CLUSTER_SIZE", "1"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_RUN_PROJECTIONS", "All"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_START_STANDARD_PROJECTIONS", "true"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_EXT_TCP_PORT", EventStoreResource.DefaultTcpPort.ToString()); | ||
context.EnvironmentVariables.Add("EVENTSTORE_HTTP_PORT", EventStoreResource.DefaultHttpPort.ToString()); | ||
context.EnvironmentVariables.Add("EVENTSTORE_INSECURE", "true"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_DEV", "true"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP", "true"); | ||
context.EnvironmentVariables.Add("EVENTSTORE_ENABLE_EXTERNAL_TCP", "true"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Aspire/Aspire.Hosting.EventStore/EventStoreContainerImageTags.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Aspire.Hosting.EventStore; | ||
|
||
internal static class EventStoreContainerImageTags | ||
{ | ||
public const string Registry = "docker.io"; | ||
public const string Image = "eventstore/eventstore"; | ||
public const string Tag = "20.10.0-buster-slim"; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Aspire/Aspire.Hosting.EventStore/EventStoreResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// A resource that represents an EventStore container. | ||
/// </summary> | ||
/// <param name="name">The name of the resource.</param> | ||
public class EventStoreResource(string name) : ContainerResource(name), IResourceWithConnectionString | ||
{ | ||
internal const string HttpEndpointName = "http"; | ||
internal const string TcpEndpointName = "tcp"; | ||
internal const int DefaultHttpPort = 2113; | ||
internal const int DefaultTcpPort = 1113; | ||
|
||
private EndpointReference? _primaryEndpoint; | ||
|
||
/// <summary> | ||
/// Gets the primary endpoint for the EventStore server. | ||
/// </summary> | ||
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, HttpEndpointName); | ||
|
||
/// <summary> | ||
/// Gets the connection string for the EventStore server. | ||
/// </summary> | ||
public ReferenceExpression ConnectionStringExpression => | ||
ReferenceExpression.Create( | ||
$"esdb://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}?tls=false"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>6e4e7f77-0985-41fb-8ac7-7a26000ea41d</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" /> | ||
<PackageReference Include="Aspire.Hosting.RabbitMQ" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Admin\NCafe.Admin.Api\NCafe.Admin.Api.csproj" /> | ||
<ProjectReference Include="..\..\Barista\NCafe.Barista.Api\NCafe.Barista.Api.csproj" /> | ||
<ProjectReference Include="..\..\Cashier\NCafe.Cashier.Api\NCafe.Cashier.Api.csproj" /> | ||
<ProjectReference Include="..\..\UI\NCafe.Web\NCafe.Web.csproj" /> | ||
<ProjectReference Include="..\Aspire.Hosting.EventStore\Aspire.Hosting.EventStore.csproj" IsAspireProjectResource="false" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var eventStore = builder.AddEventStore("eventstore"); | ||
var rabbitMq = builder.AddRabbitMQ("rabbitmq"); | ||
|
||
var adminProject = builder.AddProject<Projects.NCafe_Admin_Api>("admin-api") | ||
.WithReference(eventStore); | ||
|
||
var baristaProject = builder.AddProject<Projects.NCafe_Barista_Api>("barista-api") | ||
.WithReference(eventStore) | ||
.WithReference(rabbitMq); | ||
|
||
var cashierProject = builder.AddProject<Projects.NCafe_Cashier_Api>("cashier-api") | ||
.WithReference(eventStore) | ||
.WithReference(rabbitMq); | ||
|
||
var webUiProject = builder.AddProject<Projects.NCafe_Web>("web-ui") | ||
.WithExternalHttpEndpoints(); | ||
|
||
builder.Build().Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:17129;http://localhost:15064", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22264" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15064", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19224", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20043" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Aspire.Hosting.Dcp": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Metrics; | ||
using OpenTelemetry.Trace; | ||
|
||
namespace Microsoft.Extensions.Hosting; | ||
|
||
public static class Extensions | ||
{ | ||
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder) | ||
{ | ||
builder.ConfigureOpenTelemetry(); | ||
|
||
builder.AddDefaultHealthChecks(); | ||
|
||
builder.Services.AddServiceDiscovery(); | ||
|
||
builder.Services.ConfigureHttpClientDefaults(http => | ||
{ | ||
// Turn on resilience by default | ||
http.AddStandardResilienceHandler(); | ||
|
||
// Turn on service discovery by default | ||
http.AddServiceDiscovery(); | ||
}); | ||
|
||
return builder; | ||
} | ||
|
||
public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder) | ||
{ | ||
builder.Logging.AddOpenTelemetry(logging => | ||
{ | ||
logging.IncludeFormattedMessage = true; | ||
logging.IncludeScopes = true; | ||
}); | ||
|
||
builder.Services.AddOpenTelemetry() | ||
.WithMetrics(metrics => | ||
{ | ||
metrics.AddAspNetCoreInstrumentation() | ||
.AddHttpClientInstrumentation() | ||
.AddRuntimeInstrumentation(); | ||
}) | ||
.WithTracing(tracing => | ||
{ | ||
tracing.AddAspNetCoreInstrumentation() | ||
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) | ||
//.AddGrpcClientInstrumentation() | ||
.AddHttpClientInstrumentation(); | ||
}); | ||
|
||
builder.AddOpenTelemetryExporters(); | ||
|
||
return builder; | ||
} | ||
|
||
private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder) | ||
{ | ||
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); | ||
|
||
if (useOtlpExporter) | ||
{ | ||
builder.Services.AddOpenTelemetry().UseOtlpExporter(); | ||
} | ||
|
||
// Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) | ||
// builder.Services.AddOpenTelemetry() | ||
// .WithMetrics(metrics => metrics.AddPrometheusExporter()); | ||
|
||
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) | ||
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) | ||
//{ | ||
// builder.Services.AddOpenTelemetry() | ||
// .UseAzureMonitor(); | ||
//} | ||
|
||
return builder; | ||
} | ||
|
||
public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder) | ||
{ | ||
builder.Services.AddHealthChecks() | ||
// Add a default liveness check to ensure app is responsive | ||
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); | ||
|
||
return builder; | ||
} | ||
|
||
public static WebApplication MapDefaultEndpoints(this WebApplication app) | ||
{ | ||
// Adding health checks endpoints to applications in non-development environments has security implications. | ||
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
// All health checks must pass for app to be considered ready to accept traffic after starting | ||
app.MapHealthChecks("/health"); | ||
|
||
// Only health checks tagged with the "live" tag must pass for app to be considered alive | ||
app.MapHealthChecks("/alive", new HealthCheckOptions | ||
{ | ||
Predicate = r => r.Tags.Contains("live") | ||
}); | ||
|
||
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) | ||
// app.MapPrometheusScrapingEndpoint(); | ||
} | ||
|
||
return app; | ||
} | ||
} |
Oops, something went wrong.