-
-
Notifications
You must be signed in to change notification settings - Fork 97
Aspire sample application #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quezlatch
wants to merge
49
commits into
Eventuous:dev
Choose a base branch
from
quezlatch:aspire-only
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
12e568e
initial aspire
quezlatch fb3c88a
test: add Eventuous.Tests.Azure.Storage.Blobs project with tests for …
quezlatch ceab0b4
refactor: extract duplication from StorageBlobsProjectorTests and sur…
quezlatch b154f98
feat: add constructor overload to StorageBlobsProjector that takes Bl…
quezlatch fa5ded0
fix tests
quezlatch 6251ad9
make context typed in On methods
quezlatch 7dc10ad
update azure sample to use blob storage
quezlatch e47c589
update aspire sql databases
quezlatch 5f07032
add race condition check
quezlatch ad263da
refactor
quezlatch 4872b2d
add projector options
quezlatch b70b26e
enhance blob name resolution in projection
quezlatch b09e9f0
adjust blob name generation
quezlatch 83664b4
refactor
quezlatch 2b6cdad
add xml docs
quezlatch 86c9933
documentation
quezlatch ff371ba
add scalar as swagger/openapi client
quezlatch b0812fa
refactor
quezlatch 5fbaf53
retries on race conditions
quezlatch 3b1fbcb
tidy
quezlatch eae7f04
oops
quezlatch 4022b4d
review feedback
quezlatch 8471b94
add .NoContext()
quezlatch f21f2df
correct aspire http endpoints
quezlatch d5142c6
remove azure sample
quezlatch 88b47c8
add idempotency functionality
quezlatch c07f9d5
refactor tests
quezlatch 5406f30
update readme
quezlatch bafa903
Merge branch 'dev' into aspire-and-blob-storage
quezlatch 4fe57c2
tidy
quezlatch f0c9a4a
tidy
quezlatch 70cfd2d
update readme
quezlatch aa05e06
make options non-generic by removing serialisation overrides
quezlatch 4e0e2ee
initial aspire
quezlatch e0bcf76
enable openapi through scalar
quezlatch 1add1d3
correctly configure noda time
quezlatch 44c83f5
add readme
quezlatch bed911b
add structured logs to aspire dashboard
quezlatch 4d90e23
correctly pass through json options from DI
quezlatch 5bc95ad
do not use IOptions wrapper
quezlatch c2bbabd
Merge branch 'aspire-and-blob-storage' into aspire-only
quezlatch 71a6bf0
rename files
quezlatch 998b297
Merge branch 'aspire-and-blob-storage' into aspire-only
quezlatch 08ab02b
Merge branch 'dev' into aspire-and-blob-storage
quezlatch 001b75d
Merge branch 'aspire-and-blob-storage' into aspire-only
quezlatch 6420e1a
fix rename
quezlatch 3341b1d
add nocontext
quezlatch 260c2d4
align otel package versions
quezlatch 129eace
tidy azure client initialisation
quezlatch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <clear /> | ||
| <add key="https://api.nuget.org/v3/index.json" value="https://api.nuget.org/v3/index.json" /> | ||
| </packageSources> | ||
| <packageSourceMapping> | ||
| <packageSource key="https://api.nuget.org/v3/index.json"> | ||
| <package pattern="*" /> | ||
| </packageSource> | ||
| </packageSourceMapping> | ||
| </configuration> |
This file contains hidden or 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,41 @@ | ||
| using Scalar.Aspire; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var sql = builder.AddAzureSqlServer("sql").RunAsContainer(); | ||
| var bookingsDb = sql.AddDatabase("bookings-db"); | ||
| var paymentsDb = sql.AddDatabase("payments-db"); | ||
|
|
||
| var serviceBus = builder.AddAzureServiceBus("sbemulators").RunAsEmulator(); | ||
| var queue = serviceBus.AddServiceBusQueue("PaymentsIntegration"); | ||
|
|
||
| var blobs = builder.AddAzureStorage("storage").RunAsEmulator().AddBlobs("blobs"); | ||
| var containers = blobs.AddBlobContainer("bookings-container"); | ||
|
|
||
| var bookings = builder.AddProject<Projects.Bookings>("bookings") | ||
| .WithHttpEndpoint() | ||
| .WithHttpHealthCheck("/health") | ||
| .WithReference(bookingsDb) | ||
| .WithReference(serviceBus) | ||
| .WithReference(blobs) | ||
| .WaitFor(bookingsDb) | ||
| .WaitFor(serviceBus) | ||
| .WaitFor(blobs); | ||
|
|
||
| var payments = builder.AddProject<Projects.Bookings_Payments>("payments") | ||
| .WithHttpEndpoint() | ||
| .WithHttpHealthCheck("/health") | ||
| .WithReference(paymentsDb) | ||
| .WithReference(serviceBus) | ||
| .WithReference(blobs) | ||
| .WaitFor(paymentsDb) | ||
| .WaitFor(serviceBus) | ||
| .WaitFor(blobs); | ||
|
|
||
| var scalar = builder.AddScalarApiReference() | ||
| .WithApiReference(bookings) | ||
| .WithApiReference(payments) | ||
| .WaitFor(bookings) | ||
| .WaitFor(payments); | ||
|
|
||
| builder.Build().Run(); |
This file contains hidden or 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,25 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.4.6"> | ||
|
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
|
||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>301020ec-674b-4bcd-ba8f-2eddd4c017df</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Bookings\Bookings.csproj" /> | ||
| <ProjectReference Include="..\Bookings.Payments\Bookings.Payments.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.Azure.ServiceBus" /> | ||
| <PackageReference Include="Aspire.Hosting.Azure.Sql" /> | ||
| <PackageReference Include="Aspire.Hosting.Azure.Storage" /> | ||
| <PackageReference Include="Scalar.Aspire" /> | ||
| </ItemGroup> | ||
| </Project> | ||
This file contains hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Configurations>Debug;Release</Configurations> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="NodaTime"/> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(CoreRoot)\Eventuous.Domain\Eventuous.Domain.csproj" /> | ||
| <ProjectReference Include="$(CoreRoot)\Eventuous.Shared\Eventuous.Shared.csproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="..\..\kurrentdb\Bookings.Domain\*.cs" /> | ||
| <Compile Include="..\..\kurrentdb\Bookings.Domain\Bookings\*.cs" LinkBase="Bookings" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,47 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| <PropertyGroup> | ||
| <Configurations>Debug;Release</Configurations> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Storage.Blobs" /> | ||
| <PackageReference Include="Microsoft.Extensions.Azure" /> | ||
| <PackageReference Include="NodaTime.Serialization.SystemTextJson"/> | ||
| <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.Zipkin" /> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" /> | ||
| <PackageReference Include="Serilog.Extensions.Hosting" /> | ||
| <PackageReference Include="Serilog.Sinks.Console" /> | ||
| <PackageReference Include="Serilog.Sinks.OpenTelemetry" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="..\Bookings\Infrastructure\Logging.cs"> | ||
| <Link>Infrastructure\Logging.cs</Link> | ||
| </Compile> | ||
| <Compile Include="..\Bookings\Infrastructure\Telemetry.cs"> | ||
| <Link>Infrastructure\Telemetry.cs</Link> | ||
| </Compile> | ||
| <Compile Include="..\..\kurrentdb\Bookings.Payments\Domain\*.cs"> | ||
| <Link>Domain\%(Filename)%(Extension)</Link> | ||
| </Compile> | ||
| <Compile Include="..\..\kurrentdb\Bookings.Payments\Application\*.cs"> | ||
| <Link>Application\%(Filename)%(Extension)</Link> | ||
| </Compile> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(SrcRoot)\Extensions\src\Eventuous.Extensions.AspNetCore\Eventuous.Extensions.AspNetCore.csproj"/> | ||
| <ProjectReference Include="$(SrcRoot)\Extensions\src\Eventuous.Extensions.DependencyInjection\Eventuous.Extensions.DependencyInjection.csproj"/> | ||
| <ProjectReference Include="$(SrcRoot)\Diagnostics\src\Eventuous.Diagnostics.OpenTelemetry\Eventuous.Diagnostics.OpenTelemetry.csproj"/> | ||
| <ProjectReference Include="$(SrcRoot)\Gateway\src\Eventuous.Gateway\Eventuous.Gateway.csproj"/> | ||
| <ProjectReference Include="$(SrcRoot)\Core\gen\Eventuous.Subscriptions.Generators\Eventuous.Subscriptions.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(SrcRoot)\Core\gen\Eventuous.Shared.Generators\Eventuous.Shared.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(SrcRoot)\Experimental\src\Eventuous.Spyglass\Eventuous.Spyglass.csproj"/> | ||
| <ProjectReference Include="$(SrcRoot)\Experimental\gen\Eventuous.Spyglass.Generators\Eventuous.Spyglass.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
| <ProjectReference Include="$(SrcRoot)\SqlServer\src\Eventuous.SqlServer\Eventuous.SqlServer.csproj" /> | ||
| <ProjectReference Include="$(SrcRoot)\Azure\src\Eventuous.Azure.ServiceBus\Eventuous.Azure.ServiceBus.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,31 @@ | ||
| using Bookings.Payments.Domain; | ||
| using Eventuous; | ||
| using Eventuous.Azure.ServiceBus.Producers; | ||
| using Eventuous.Gateway; | ||
| using Eventuous.Subscriptions.Context; | ||
| using static Bookings.Payments.Integration.IntegrationEvents; | ||
|
|
||
| namespace Bookings.Payments.Integration; | ||
|
|
||
| public static class PaymentsGateway { | ||
| static readonly StreamName Stream = new("PaymentsIntegration"); | ||
| static readonly ServiceBusProduceOptions ProduceOptions = new(); | ||
|
|
||
| public static ValueTask<GatewayMessage<ServiceBusProduceOptions>[]> Transform(IMessageConsumeContext original) { | ||
| var result = original.Message is PaymentEvents.PaymentRecorded evt | ||
| ? new GatewayMessage<ServiceBusProduceOptions>( | ||
| Stream, | ||
| new BookingPaymentRecorded(original.Stream.GetId(), evt.BookingId, evt.Amount, evt.Currency), | ||
| new(), | ||
| ProduceOptions | ||
| ) | ||
| : null; | ||
|
|
||
| return ValueTask.FromResult<GatewayMessage<ServiceBusProduceOptions>[]>(result != null ? [result] : []); | ||
| } | ||
| } | ||
|
|
||
| public static class IntegrationEvents { | ||
| [EventType("BookingPaymentRecorded")] | ||
| public record BookingPaymentRecorded(string PaymentId, string BookingId, float Amount, string Currency); | ||
| } |
This file contains hidden or 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 Bookings.Infrastructure; | ||
| using Bookings.Payments; | ||
| using Bookings.Payments.Domain; | ||
| using Eventuous; | ||
| using Microsoft.OpenApi.Models; | ||
| using NodaTime; | ||
| using NodaTime.Serialization.SystemTextJson; | ||
| using Serilog; | ||
| using static Bookings.Payments.Application.PaymentCommands; | ||
|
|
||
| TypeMap.RegisterKnownEventTypes(); | ||
| Logging.ConfigureLog(); | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.Host.UseSerilog(); | ||
|
|
||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services | ||
| .AddControllers() | ||
| .AddJsonOptions(cfg => cfg.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)); | ||
| builder.Services.ConfigureHttpJsonOptions(cfg => cfg.SerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)); | ||
| builder.Services.AddSwaggerGen(c => { | ||
| c.SwaggerDoc("v1", new() { Title = "Bookings API", Version = "v1" }); | ||
| c.AddServer(new OpenApiServer { Url = "/" }); // Relative path | ||
| }); | ||
| // OpenTelemetry instrumentation must be added before adding Eventuous services | ||
| builder.Services.AddTelemetry(); | ||
| builder.Services.AddEventuous(builder.Configuration); | ||
|
|
||
| builder.Services.AddHealthChecks(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.Services.AddEventuousLogs(); | ||
| app.UseSwagger(c=>c.RouteTemplate = "openapi/{documentName}.json"); | ||
| app.UseOpenTelemetryPrometheusScrapingEndpoint(); | ||
|
|
||
| app.MapHealthChecks("/health"); | ||
|
|
||
| // Here we discover commands by their annotations | ||
| app.MapCommands<PaymentState>().MapCommand<RecordPayment>(); | ||
|
|
||
| app.Run(); |
This file contains hidden or 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,37 @@ | ||
| using Bookings.Payments.Application; | ||
| using Bookings.Payments.Domain; | ||
| using Bookings.Payments.Integration; | ||
| using Eventuous.Azure.ServiceBus.Producers; | ||
| using Eventuous.SqlServer; | ||
| using Eventuous.SqlServer.Subscriptions; | ||
| using Microsoft.Extensions.Azure; | ||
|
|
||
| namespace Bookings.Payments; | ||
|
|
||
| public static class Registrations { | ||
| public static void AddEventuous(this IServiceCollection services, IConfiguration configuration) { | ||
| services.AddAzureClients(builder => { | ||
| var sbConnectionString = configuration.GetConnectionString("sbemulators") ?? throw new InvalidOperationException("Connection string 'sbemulators' not found."); | ||
| builder.AddServiceBusClient(sbConnectionString); | ||
| var blobConnectionString = configuration.GetConnectionString("blobs") ?? throw new InvalidOperationException("Connection string 'blobs' not found."); | ||
| builder.AddBlobServiceClient(blobConnectionString); | ||
| }); | ||
|
|
||
| var connectionString = configuration.GetConnectionString("payments-db") ?? throw new InvalidOperationException("Connection string 'payments-db' not found."); | ||
|
|
||
| services.AddEventuousSqlServer(connectionString, initializeDatabase: true); | ||
| services.AddEventStore<SqlServerStore>(); | ||
| services.AddSqlServerCheckpointStore(); | ||
| services.AddCommandService<CommandService, PaymentState>(); | ||
| services.AddProducer<ServiceBusProducer>(); | ||
| services.AddSingleton(new ServiceBusProducerOptions { | ||
| QueueOrTopicName = "PaymentsIntegration", | ||
| }); | ||
|
|
||
| services | ||
| .AddGateway<SqlServerAllStreamSubscription, SqlServerAllStreamSubscriptionOptions, ServiceBusProducer, ServiceBusProduceOptions>( | ||
| "IntegrationSubscription", | ||
| PaymentsGateway.Transform | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,14 @@ | ||
| { | ||
| "ConnectionStrings": { | ||
| "database": "from aspire", | ||
| "sbemulators": "from aspire", | ||
| "blobs": "from aspire" | ||
| }, | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Debug", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.