-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 253 add active mq hosting (#273)
* #253 start with ActiveMQ hosting * #253 Add activemq hosting with example using MassTransit * #253 added unittest and README.md * Update examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost.csproj Co-authored-by: Aaron Powell <[email protected]> * Update examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost/Program.cs Co-authored-by: Aaron Powell <[email protected]> * Update examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit.csproj Co-authored-by: Aaron Powell <[email protected]> * #253 resolved comments * Update examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults/CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults.csproj Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQBuilderExtensions.cs Co-authored-by: Aaron Powell <[email protected]> * #253 added AppHostTests for ActiveMQ * #253 masstransit alive added to example * #253 added healthcheck to the MassTransit application, added a counter for received messages, extended integrationtest to check on recieved messages * Update src/CommunityToolkit.Aspire.Hosting.ActiveMQ/ActiveMQServerResource.cs Co-authored-by: Aaron Powell <[email protected]> * #253 changed consumer to Request/Response * #253 added healthcheck first iteration * #253 merge two methods and remove parameters from method * #253 added MassTransit to the meters. --------- Co-authored-by: Aaron Powell <[email protected]>
- Loading branch information
1 parent
8d529ad
commit 713c94a
Showing
27 changed files
with
840 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
23 changes: 23 additions & 0 deletions
23
...t.Aspire.Hosting.ActiveMQ.AppHost/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost.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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
<UserSecretsId>cb846a57-bdaf-4abd-a7fb-0299aa095f5e</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" /> | ||
<PackageReference Include="Aspire.Hosting.AppHost" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.ActiveMQ\CommunityToolkit.Aspire.Hosting.ActiveMQ.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit\CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
17 changes: 17 additions & 0 deletions
17
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost/Program.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,17 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Projects; | ||
|
||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var username = builder.AddParameter("user", "admin"); | ||
var password = builder.AddParameter("password", "admin", secret: true); | ||
|
||
var amq = builder.AddActiveMQ("amq", username, password, 61616, "activemq", webPort: 8161) | ||
.PublishAsConnectionString(); | ||
|
||
builder.AddProject<CommunityToolkit_Aspire_Hosting_ActiveMQ_MassTransit>("masstransitExample") | ||
.WithReference(amq) | ||
.WithHttpHealthCheck(path: "/health") | ||
.WaitFor(amq); | ||
|
||
builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
.../activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost/Properties/launchSettings.json
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:17276;http://localhost:15246", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21269", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22000" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15246", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19099", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20012" | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost/appsettings.json
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" | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
....Hosting.ActiveMQ.MassTransit/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit.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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MassTransit" /> | ||
<PackageReference Include="MassTransit.ActiveMQ" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults\CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
21 changes: 21 additions & 0 deletions
21
...re.Hosting.ActiveMQ.MassTransit/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit.http
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,21 @@ | ||
@CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit_HostAddress = http://localhost:5004 | ||
|
||
POST http://localhost:5004/send/Hello%20World | ||
Accept: application/json | ||
|
||
### | ||
GET http://localhost:5004/alive | ||
Accept: application/json | ||
|
||
### | ||
GET http://localhost:5004/received | ||
Accept: application/json | ||
|
||
### | ||
GET http://admin:admin@localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost,service=Health/CurrentStatus | ||
origin: localhost | ||
|
||
### | ||
GET http://localhost:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost,service=Health/CurrentStatus | ||
origin: localhost | ||
Authorization: Basic YWRtaW46YWRtaW4= |
16 changes: 16 additions & 0 deletions
16
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/HelloWorldConsumer.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,16 @@ | ||
using MassTransit; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit; | ||
|
||
public class HelloWorldConsumer(ILogger<HelloWorldConsumer> logger, MessageCounter messageCounter) : IConsumer<Message> | ||
{ | ||
public async Task Consume(ConsumeContext<Message> context) | ||
{ | ||
logger.LogInformation("Received message: {Text}", context.Message.Text); | ||
messageCounter.ReceivedMessages++; | ||
await context.RespondAsync<MessageReply>(new | ||
{ | ||
Reply = "I've received your message: " + context.Message.Text | ||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/Message.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,6 @@ | ||
namespace CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit; | ||
|
||
public record Message | ||
{ | ||
public required string Text { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/MessageCounter.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,6 @@ | ||
namespace CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit; | ||
|
||
public class MessageCounter | ||
{ | ||
public int ReceivedMessages { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/MessageReply.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,6 @@ | ||
namespace CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit; | ||
|
||
public record MessageReply | ||
{ | ||
public required string Reply { get; set; } | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/Program.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,41 @@ | ||
using CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit; | ||
using MassTransit; | ||
using Microsoft.AspNetCore.Http.HttpResults; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
builder.Services | ||
.AddSingleton(KebabCaseEndpointNameFormatter.Instance) | ||
.AddSingleton<MessageCounter>(); | ||
builder.Services.AddMassTransit(x => | ||
{ | ||
x.UsingActiveMq((context, cfg) => | ||
{ | ||
string connectionString = builder.Configuration.GetConnectionString("amq")!; | ||
cfg.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("aspire", false)); | ||
cfg.Host(new Uri(connectionString), _ => {}); | ||
}); | ||
x.AddConsumers(typeof(HelloWorldConsumer).Assembly); | ||
}); | ||
|
||
WebApplication app = builder.Build(); | ||
|
||
app.MapPost("/send/{text}", async (string text, | ||
[FromServices] IRequestClient<Message> requestClient, | ||
[FromServices] ILogger<Program> logger) => | ||
{ | ||
logger.LogInformation("Send message: {Text}", text); | ||
Response<MessageReply> response = await requestClient.GetResponse<MessageReply>(new { Text = text }); | ||
logger.LogInformation("Sent message: {Text}", text); | ||
return response.Message.Reply; | ||
}) | ||
.WithName("SendMessage"); | ||
|
||
app.MapGet("/received", ([FromServices] MessageCounter messageCounter) => messageCounter) | ||
.WithName("ReceivedMessages"); | ||
|
||
app.MapDefaultEndpoints(); | ||
app.Run(); |
23 changes: 23 additions & 0 deletions
23
...ivemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/Properties/launchSettings.json
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,23 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "http://localhost:5004", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "https://localhost:7038;http://localhost:5004", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/activemq/CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit/appsettings.json
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,12 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"amq": "activemq://localhost:61616" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
21 changes: 21 additions & 0 deletions
21
....ActiveMQ.ServiceDefaults/CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireSharedProject>true</IsAspireSharedProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
|
||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" /> | ||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" /> | ||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" /> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" /> | ||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.