Pular para o conteúdo
DocsTry Aspire
DocsTry

Set up LavinMQ in the Aspire AppHost

Este conteúdo não está disponível em sua língua ainda.

⭐ Community Toolkit LavinMQ logo

This article is the AppHost API reference for the 📦 CommunityToolkit.Aspire.Hosting.LavinMQ package. Start with Get started with LavinMQ and Aspire for the integration workflow, or see Connect Aspire apps to LavinMQ for client examples.

Terminal
aspire add CommunityToolkit.Aspire.Hosting.LavinMQ

Or add the package manually:

AppHost.cs
#:package CommunityToolkit.Aspire.Hosting.LavinMQ@*
AppHost.csproj
<PackageReference Include="CommunityToolkit.Aspire.Hosting.LavinMQ" Version="*" />

Learn more about aspire add and aspire restore.

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq");
builder.AddProject<Projects.Worker>("worker")
.WithReference(lavinmq);
builder.Build().Run();

The integration runs docker.io/cloudamqp/lavinmq:2.1.0. The AMQP endpoint uses container port 5672, and the management endpoint uses 15672. The default username and password are both guest.

Pass fixed host ports when another process needs stable endpoints:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ(
"lavinmq",
amqpPort: 5672,
managementPort: 15672);
builder.Build().Run();

When you omit these parameters, the integration binds host ports 5672 and 15672. Pass alternative values when either port is already occupied.

WithDataVolume and withDataVolume require a volume name and mount it at /var/lib/lavinmq:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq")
.WithDataVolume("lavinmq-data");
builder.Build().Run();

Use a bind mount when you need direct access to broker files on the host:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq")
.WithDataBindMount(@"C:\LavinMQ\Data");
builder.Build().Run();

Both persistence methods accept an optional isReadOnly value. A read-only mount isn’t suitable for a broker that needs to write data.

The resource exports its AMQP endpoint and connection expressions for use in custom AppHost expressions:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq");
var primaryEndpoint = lavinmq.Resource.PrimaryEndpoint;
var host = lavinmq.Resource.Host;
var port = lavinmq.Resource.Port;
var uri = lavinmq.Resource.UriExpression;
var connectionString = lavinmq.Resource.ConnectionStringExpression;
builder.Build().Run();

The management endpoint is added automatically. Open the management HTTP endpoint from the Aspire dashboard, then sign in with the broker credentials.

The hosting integration registers a RabbitMQ-compatible health check against the AMQP endpoint. The dashboard reports the resource healthy after a client connection succeeds.