Skip to content

Commit

Permalink
Feature/issue 253 add active mq hosting (#273)
Browse files Browse the repository at this point in the history
* #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
anoordover and aaronpowell authored Nov 27, 2024
1 parent 8d529ad commit 713c94a
Show file tree
Hide file tree
Showing 27 changed files with 840 additions and 0 deletions.
38 changes: 38 additions & 0 deletions CommunityToolkit.Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hos
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Bun.Tests", "tests\CommunityToolkit.Aspire.Hosting.Bun.Tests\CommunityToolkit.Aspire.Hosting.Bun.Tests.csproj", "{DA5DD2CB-51D9-429F-91F5-BF3D1A13A21A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.ActiveMQ", "src\CommunityToolkit.Aspire.Hosting.ActiveMQ\CommunityToolkit.Aspire.Hosting.ActiveMQ.csproj", "{56C3C409-10FF-4CA5-99AD-0D35C5418B2A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "activemq", "activemq", "{BF4C4E57-DAAF-4EE5-B330-1923106BAE69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost", "examples\activemq\CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost\CommunityToolkit.Aspire.Hosting.ActiveMQ.AppHost.csproj", "{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults", "examples\activemq\CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults\CommunityToolkit.Aspire.Hosting.ActiveMQ.ServiceDefaults.csproj", "{978EED2A-43BB-4DE6-8563-3A9972869661}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit", "examples\activemq\CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit\CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit.csproj", "{A87F7800-BD24-4577-8F15-50D33C8DACF1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.ActiveMQ.Tests", "tests\CommunityToolkit.Aspire.Hosting.ActiveMQ.Tests\CommunityToolkit.Aspire.Hosting.ActiveMQ.Tests.csproj", "{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -371,6 +383,26 @@ Global
{DA5DD2CB-51D9-429F-91F5-BF3D1A13A21A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA5DD2CB-51D9-429F-91F5-BF3D1A13A21A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA5DD2CB-51D9-429F-91F5-BF3D1A13A21A}.Release|Any CPU.Build.0 = Release|Any CPU
{56C3C409-10FF-4CA5-99AD-0D35C5418B2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56C3C409-10FF-4CA5-99AD-0D35C5418B2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56C3C409-10FF-4CA5-99AD-0D35C5418B2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56C3C409-10FF-4CA5-99AD-0D35C5418B2A}.Release|Any CPU.Build.0 = Release|Any CPU
{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12}.Release|Any CPU.Build.0 = Release|Any CPU
{978EED2A-43BB-4DE6-8563-3A9972869661}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{978EED2A-43BB-4DE6-8563-3A9972869661}.Debug|Any CPU.Build.0 = Debug|Any CPU
{978EED2A-43BB-4DE6-8563-3A9972869661}.Release|Any CPU.ActiveCfg = Release|Any CPU
{978EED2A-43BB-4DE6-8563-3A9972869661}.Release|Any CPU.Build.0 = Release|Any CPU
{A87F7800-BD24-4577-8F15-50D33C8DACF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A87F7800-BD24-4577-8F15-50D33C8DACF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A87F7800-BD24-4577-8F15-50D33C8DACF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A87F7800-BD24-4577-8F15-50D33C8DACF1}.Release|Any CPU.Build.0 = Release|Any CPU
{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -444,6 +476,12 @@ Global
{A7614F2B-E810-412E-91E7-8B6272DD5DBB} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{36FC2579-582A-4DAF-9B20-AB33331624C6} = {A7614F2B-E810-412E-91E7-8B6272DD5DBB}
{DA5DD2CB-51D9-429F-91F5-BF3D1A13A21A} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{56C3C409-10FF-4CA5-99AD-0D35C5418B2A} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{BF4C4E57-DAAF-4EE5-B330-1923106BAE69} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{CF6CF1C3-EBE1-41CE-9B34-0C2F931AEA12} = {BF4C4E57-DAAF-4EE5-B330-1923106BAE69}
{978EED2A-43BB-4DE6-8563-3A9972869661} = {BF4C4E57-DAAF-4EE5-B330-1923106BAE69}
{A87F7800-BD24-4577-8F15-50D33C8DACF1} = {BF4C4E57-DAAF-4EE5-B330-1923106BAE69}
{1200FB2E-F476-4151-BDFD-1DAEE3E99FF5} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<!-- External packages -->
<PackageVersion Include="JsonSchema.Net" Version="7.2.3" />
<PackageVersion Include="OllamaSharp" Version="4.0.8" />
<PackageVersion Include="MassTransit" Version="8.3.1" />
<PackageVersion Include="MassTransit.ActiveMQ" Version="8.3.1" />
<PackageVersion Include="MeiliSearch" Version="0.15.4" />
<PackageVersion Include="Microsoft.SqlServer.DacFx" Version="162.5.57" />
<PackageVersion Include="Microsoft.Build" Version="17.11.4" />
Expand Down
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>
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();
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"
}
}
}
}
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"
}
}
}
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>
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=
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
});
}
}
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; }
}
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; }
}
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; }
}
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();
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"
}
}
}
}
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": "*"
}
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>
Loading

0 comments on commit 713c94a

Please sign in to comment.