Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a4dcc11
NATS Aspire container
mtmk Dec 2, 2023
135a213
Use central package management
ReubenBond Dec 2, 2023
2088f5b
Merge branch 'main' into nats
sebastienros Dec 13, 2023
7b9690f
Add telemetry to defaults
mtmk Jan 14, 2024
732c8f1
Add JetStream option
mtmk Jan 14, 2024
6c2d73c
Merge branch 'main' into nats
mtmk Jan 14, 2024
56126f5
Fixed build
mtmk Jan 14, 2024
35a8972
Merge branch 'main' into nats
mtmk Feb 12, 2024
35f22fe
Fixed sln merge issue
mtmk Feb 12, 2024
7d94f67
Moved sample to playgrounds
mtmk Feb 12, 2024
27ec961
sln fixes
mtmk Feb 12, 2024
70987ad
Updated playground nats
mtmk Feb 12, 2024
b5c2c37
Moved hosting bits
mtmk Feb 12, 2024
28b2112
Merge fix
mtmk Feb 12, 2024
47d5268
Fixed spelling
mtmk Feb 12, 2024
4d2ca61
Slightly more involved NATS sample
mtmk Feb 12, 2024
7916e6b
NATS sample tweak
mtmk Feb 12, 2024
27a8609
Rename to Aspire.Nats.Client and added config
mtmk Feb 13, 2024
3e8fc4f
Merge remote-tracking branch 'upstream/main' into nats
mtmk Feb 13, 2024
4e27824
Fixed build
mtmk Feb 13, 2024
ec581ba
Merge remote-tracking branch 'upstream/main' into nats
mtmk Feb 14, 2024
f2884de
Added NATS publish as container
mtmk Feb 14, 2024
f52811d
NATS conformance tests
mtmk Feb 14, 2024
2eb8acd
NATS health check
mtmk Feb 14, 2024
607f025
NATS health checks
mtmk Feb 14, 2024
f772de8
NATS client extension docs
mtmk Feb 14, 2024
cec35c9
Added a simple ping example
mtmk Feb 14, 2024
54d5946
Bit more elaborate NATS example
mtmk Feb 14, 2024
6e255ae
Removed `nats` scheme
Feb 22, 2024
4d37047
Update src/Aspire.Hosting/Nats/NatsBuilderExtensions.cs
mtmk Feb 23, 2024
ee10f49
Merge remote-tracking branch 'upstream/main' into nats
mtmk Feb 24, 2024
b583065
Catch up to main
mtmk Feb 24, 2024
d138aa9
NATS ConnectionStringExpression
mtmk Feb 24, 2024
9b950eb
ConnectionStringExpression fix
mtmk Feb 24, 2024
2f77b55
Merge remote-tracking branch 'upstream/main' into nats
mtmk Feb 24, 2024
08e26aa
Fixed test
mtmk Feb 24, 2024
48d6bd3
Nats VerifyManifest test
mtmk Feb 25, 2024
f6fd1b0
Merge remote-tracking branch 'upstream/main' into nats
mtmk Mar 2, 2024
ff2cb10
nats catches up to main
mtmk Mar 2, 2024
bf74eda
nats endpoint tweak
mtmk Mar 3, 2024
a40a832
Merge remote-tracking branch 'upstream/main' into nats
mtmk Mar 3, 2024
1405623
nats with image
mtmk Mar 3, 2024
8eb4d94
nats image tweaks
mtmk Mar 3, 2024
4d488e2
revert
mtmk Mar 3, 2024
4afdad8
Merge remote-tracking branch 'upstream/main' into nats
mtmk Mar 4, 2024
1a62a75
nats manifest test
mtmk Mar 4, 2024
3606984
Update tests/Aspire.Nats.Client.Tests/ConfigurationTests.cs
mtmk Mar 5, 2024
6eefa74
rename nats AppHost
mtmk Mar 5, 2024
388bd85
rename Aspire.NATS.Net
mtmk Mar 5, 2024
f31d49f
nats health checks tweak
mtmk Mar 5, 2024
2c10732
nats component test tweaks
mtmk Mar 5, 2024
f98cfa6
Merge remote-tracking branch 'upstream/main' into nats
mtmk Mar 5, 2024
0eab699
nats component docs
mtmk Mar 5, 2024
1f773f9
nats resource string constants
mtmk Mar 5, 2024
15ffa21
Merge branch 'main' into nats
sebastienros Mar 7, 2024
7836160
Add manifest
sebastienros Mar 7, 2024
d005020
Rename AddNats to AddNatsClient
sebastienros Mar 7, 2024
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
47 changes: 46 additions & 1 deletion Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.MySqlConnector.Tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject.IntegrationServiceA", "tests\testproject\TestProject.IntegrationServiceA\TestProject.IntegrationServiceA.csproj", "{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nats", "nats", "{91F22EEA-EB23-425A-9B32-9438A0809F4B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nats.ApiService", "playground\nats\Nats.ApiService\Nats.ApiService.csproj", "{74F89D52-645B-4283-98AF-D04DA794EE37}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nats.AppHost", "playground\nats\Nats.AppHost\Nats.AppHost.csproj", "{A0BB6F6B-9543-4525-81D6-95DC07BD3D02}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.NATS.Net", "src\Components\Aspire.NATS.Net\Aspire.NATS.Net.csproj", "{303E6308-740C-4673-96D2-0E81934C9E69}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{2136E31D-2CBB-41BB-8618-716FF8E46E9E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfigurationSchemaGenerator", "src\Tools\ConfigurationSchemaGenerator\ConfigurationSchemaGenerator.csproj", "{39FA2A64-012F-4EB9-A14F-E8AC54C975F6}"
Expand Down Expand Up @@ -237,7 +245,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostgresEndToEnd.ApiService
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mysql", "mysql", "{621991F1-854A-4743-835B-10CAF11A0CFF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlDb.AppHost", "Playground\mysql\MySqlDb.AppHost\MySqlDb.AppHost.csproj", "{7E2AD00B-60E0-46C2-8640-7217D678F312}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlDb.AppHost", "playground\mysql\MySqlDb.AppHost\MySqlDb.AppHost.csproj", "{7E2AD00B-60E0-46C2-8640-7217D678F312}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySql.ApiService", "playground\mysql\MySql.ApiService\MySql.ApiService.csproj", "{F699F3AD-2AD9-454B-BA40-82AC3D6250FE}"
EndProject
Expand Down Expand Up @@ -265,8 +273,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureStorageEndToEnd.AppHos
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureStorageEndToEnd.ApiService", "playground\AzureStorageEndToEnd\AzureStorageEndToEnd.ApiService\AzureStorageEndToEnd.ApiService.csproj", "{921CB408-5E37-4354-B4CF-EAE517F633DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.NATS.Net.Tests", "tests\Aspire.NATS.Net.Tests\Aspire.NATS.Net.Tests.csproj", "{C774BE00-EE93-4148-B866-8F0F2BA1E473}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Dashboard.Components.Tests", "tests\Aspire.Dashboard.Components.Tests\Aspire.Dashboard.Components.Tests.csproj", "{0870A667-FB0C-4758-AEAF-9E5F092AD7C1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nats.Backend", "playground\nats\Nats.Backend\Nats.Backend.csproj", "{C4833DEC-0A4F-4504-B8D0-06C60B84119C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nats.Common", "playground\nats\Nats.Common\Nats.Common.csproj", "{9CA94707-E801-444F-A582-D5BD0104CF9B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{A7C6452C-FEDB-4883-9AE7-29892D260AA3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Testing", "src\Aspire.Hosting.Testing\Aspire.Hosting.Testing.csproj", "{3216CF59-84B0-46FF-8572-D0AFB0155423}"
Expand Down Expand Up @@ -581,6 +595,18 @@ Global
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8}.Release|Any CPU.Build.0 = Release|Any CPU
{74F89D52-645B-4283-98AF-D04DA794EE37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74F89D52-645B-4283-98AF-D04DA794EE37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74F89D52-645B-4283-98AF-D04DA794EE37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74F89D52-645B-4283-98AF-D04DA794EE37}.Release|Any CPU.Build.0 = Release|Any CPU
{A0BB6F6B-9543-4525-81D6-95DC07BD3D02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0BB6F6B-9543-4525-81D6-95DC07BD3D02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0BB6F6B-9543-4525-81D6-95DC07BD3D02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0BB6F6B-9543-4525-81D6-95DC07BD3D02}.Release|Any CPU.Build.0 = Release|Any CPU
{303E6308-740C-4673-96D2-0E81934C9E69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{303E6308-740C-4673-96D2-0E81934C9E69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{303E6308-740C-4673-96D2-0E81934C9E69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{303E6308-740C-4673-96D2-0E81934C9E69}.Release|Any CPU.Build.0 = Release|Any CPU
{39FA2A64-012F-4EB9-A14F-E8AC54C975F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39FA2A64-012F-4EB9-A14F-E8AC54C975F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39FA2A64-012F-4EB9-A14F-E8AC54C975F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -745,10 +771,22 @@ Global
{921CB408-5E37-4354-B4CF-EAE517F633DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{921CB408-5E37-4354-B4CF-EAE517F633DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{921CB408-5E37-4354-B4CF-EAE517F633DC}.Release|Any CPU.Build.0 = Release|Any CPU
{C774BE00-EE93-4148-B866-8F0F2BA1E473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C774BE00-EE93-4148-B866-8F0F2BA1E473}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C774BE00-EE93-4148-B866-8F0F2BA1E473}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C774BE00-EE93-4148-B866-8F0F2BA1E473}.Release|Any CPU.Build.0 = Release|Any CPU
{0870A667-FB0C-4758-AEAF-9E5F092AD7C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0870A667-FB0C-4758-AEAF-9E5F092AD7C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0870A667-FB0C-4758-AEAF-9E5F092AD7C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0870A667-FB0C-4758-AEAF-9E5F092AD7C1}.Release|Any CPU.Build.0 = Release|Any CPU
{C4833DEC-0A4F-4504-B8D0-06C60B84119C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4833DEC-0A4F-4504-B8D0-06C60B84119C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4833DEC-0A4F-4504-B8D0-06C60B84119C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4833DEC-0A4F-4504-B8D0-06C60B84119C}.Release|Any CPU.Build.0 = Release|Any CPU
{9CA94707-E801-444F-A582-D5BD0104CF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9CA94707-E801-444F-A582-D5BD0104CF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CA94707-E801-444F-A582-D5BD0104CF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CA94707-E801-444F-A582-D5BD0104CF9B}.Release|Any CPU.Build.0 = Release|Any CPU
{3216CF59-84B0-46FF-8572-D0AFB0155423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3216CF59-84B0-46FF-8572-D0AFB0155423}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3216CF59-84B0-46FF-8572-D0AFB0155423}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -891,6 +929,10 @@ Global
{CA283D7F-EB95-4353-B196-C409965D2B42} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{C8079F06-304F-49B1-A0C1-45AA3782A923} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{DCF2D47A-921A-4900-B5B2-CF97B3531CE8} = {975F6F41-B455-451D-A312-098DE4A167B6}
{91F22EEA-EB23-425A-9B32-9438A0809F4B} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{74F89D52-645B-4283-98AF-D04DA794EE37} = {91F22EEA-EB23-425A-9B32-9438A0809F4B}
{A0BB6F6B-9543-4525-81D6-95DC07BD3D02} = {91F22EEA-EB23-425A-9B32-9438A0809F4B}
{303E6308-740C-4673-96D2-0E81934C9E69} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{39FA2A64-012F-4EB9-A14F-E8AC54C975F6} = {2136E31D-2CBB-41BB-8618-716FF8E46E9E}
{20A5A907-A135-4735-B4BF-E13514F360E3} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{E592E447-BA3C-44FA-86C1-EBEDC864A644} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
Expand Down Expand Up @@ -943,7 +985,10 @@ Global
{8AA07A14-A4A7-45EC-B0F6-4690B516B16D} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{157A434E-E3CA-4080-96CF-903CC3DF66E9} = {8AA07A14-A4A7-45EC-B0F6-4690B516B16D}
{921CB408-5E37-4354-B4CF-EAE517F633DC} = {8AA07A14-A4A7-45EC-B0F6-4690B516B16D}
{C774BE00-EE93-4148-B866-8F0F2BA1E473} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{0870A667-FB0C-4758-AEAF-9E5F092AD7C1} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{C4833DEC-0A4F-4504-B8D0-06C60B84119C} = {91F22EEA-EB23-425A-9B32-9438A0809F4B}
{9CA94707-E801-444F-A582-D5BD0104CF9B} = {91F22EEA-EB23-425A-9B32-9438A0809F4B}
{3216CF59-84B0-46FF-8572-D0AFB0155423} = {A7C6452C-FEDB-4883-9AE7-29892D260AA3}
{BE46B5B3-DFD4-4565-A2CD-7D95C623B03D} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{8B1802BC-6CB0-4027-850C-2AED42A82C9E} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<PackageVersion Include="Microsoft.Orleans.Reminders.AzureStorage" Version="8.1.0-nightly.20240111.1" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.3.5" />
<PackageVersion Include="MySqlConnector.Logging.Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageVersion Include="NATS.Net" Version="2.1.0" />
<PackageVersion Include="Npgsql.DependencyInjection" Version="8.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageVersion Include="Oracle.EntityFrameworkCore" Version="8.21.121" />
Expand Down
20 changes: 20 additions & 0 deletions playground/nats/Nats.ApiService/Nats.ApiService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Components\Aspire.NATS.Net\Aspire.NATS.Net.csproj" />
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
<ProjectReference Include="..\Nats.Common\Nats.Common.csproj" />
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions playground/nats/Nats.ApiService/Nats.ApiService.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@HostAddress = http://localhost:5156

POST {{HostAddress}}/ping/

###

POST {{HostAddress}}/stream/
Content-Type: application/json

{
"name": "EVENTS",
"description": "Events Description",
"subjects": ["events.>"],
"max_msgs": 10
}

###

GET {{HostAddress}}/stream/EVENTS
Accept: application/json

###

POST {{HostAddress}}/publish/
Content-Type: application/json

{
"subject": "events.mouse.click",
"name": "Mouse Event",
"description": "Mouse Event Description",
"priority": 0.1
}

###

POST {{HostAddress}}/publish/
Content-Type: application/json

{
"subject": "events.key.a",
"name": "Key Event",
"description": "Key Event Description",
"priority": 0.5
}

###

GET {{HostAddress}}/consume/EVENTS
Accept: application/json

###
85 changes: 85 additions & 0 deletions playground/nats/Nats.ApiService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using NATS.Client.Core;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this app a little more real? Can it use pubsub as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, let me have a go!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a simple JetStream example since it's easier demonstrate persisted messages using Web API. As for pubsub I suppose we'd need a frontend using SignalR or Blazor. Maybe a simple chat or something?

using NATS.Client.JetStream;
using NATS.Client.JetStream.Models;
using Nats.Common;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.AddServiceDefaults();

builder.AddNatsClient("nats", configureOptions: opts =>
{
var jsonRegistry = new NatsJsonContextSerializerRegistry(AppJsonContext.Default);
return opts with { SerializerRegistry = jsonRegistry };
Comment on lines +17 to +18

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required or optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's optional. required for json serialization. Would you suggests to make it easier for ad hoc JSON serialization?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but I don't know enough about your API design to suggest something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Challenge is our core NuGet packages are AOT ready and for ad-hoc JSON we have an extra package. I can bring NATS ad-hoc JSON package into Aspite.Nats.Client if AOT is not a concern (yet?).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Aspire component packages are intended to be AOT compatible if the associated client library is AOT compatible. For example, we are using the Configuration Binder source generator, so config binding works in native AOT.

We have 2 service apps in https://github.com/dotnet/eShop that support being published to native AOT:

So, yes, AOT is a concern for Aspire.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments. I'm going to leave this as it is for now since it looks like we're going to need some changes on NATS Client side as well (nats-io/nats.net#417)

});

builder.AddNatsJetStream();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.MapGet("/ping", async (INatsConnection nats) =>
{
var rtt = await nats.PingAsync();
return Results.Json(new { rtt, nats.ServerInfo });
});

app.MapPost("/stream", async (StreamConfig config, INatsJSContext jetStream) =>
{
var stream = await jetStream.CreateStreamAsync(config);
var name = stream.Info.Config.Name;
return Results.Created($"/stream/{name}", name);
});

app.MapGet("/stream/{name}", async (string name, INatsJSContext jetStream) =>
{
var stream = await jetStream.GetStreamAsync(name);
return Results.Ok(stream.Info);
});

app.MapPost("/publish/", async (AppEvent @event, INatsJSContext jetStream) =>
{
try
{
var ack = await jetStream.PublishAsync(@event.Subject, @event);
ack.EnsureSuccess();
}
catch (NatsJSPublishNoResponseException)
{
return Results.Problem("Make sure the stream is created before publishing.");
}

return Results.Created();
});

app.MapGet("/consume/{name}", async (string name, INatsJSContext jetStream) =>
{
var stream = await jetStream.GetStreamAsync(name);
var consumer = await stream.CreateOrderedConsumerAsync();

var events = new List<AppEvent>();
await foreach(var msg in consumer.ConsumeAsync<AppEvent>())
{
events.Add(msg.Data!);

if (msg.Metadata?.NumPending == 0)
{
break;
}
}

return Results.Ok(events);
});

app.Run();
38 changes: 38 additions & 0 deletions playground/nats/Nats.ApiService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:12538",
"sslPort": 44308
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5156",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7060;http://localhost:5156",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions playground/nats/Nats.ApiService/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions playground/nats/Nats.ApiService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
8 changes: 8 additions & 0 deletions playground/nats/Nats.AppHost/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
<Import Project="../../../src/Aspire.Hosting/build/Aspire.Hosting.props" />

</Project>
9 changes: 9 additions & 0 deletions playground/nats/Nats.AppHost/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
<Import Project="..\..\..\src\Aspire.Hosting\build\Aspire.Hosting.targets" />
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />

</Project>
24 changes: 24 additions & 0 deletions playground/nats/Nats.AppHost/Nats.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<RootNamespace>Nats.AppHosting</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\Nats.ApiService\Nats.ApiService.csproj" />
<ProjectReference Include="..\Nats.Backend\Nats.Backend.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions playground/nats/Nats.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var builder = DistributedApplication.CreateBuilder(args);

var nats = builder.AddNats("nats")
.WithJetStream();

builder.AddProject<Projects.Nats_ApiService>("api")
.WithReference(nats);

builder.AddProject<Projects.Nats_Backend>("backend")
.WithReference(nats);

builder.Build().Run();
Loading