Skip to content

LavinMQ integration

⭐ Community Toolkit LavinMQ logo

LavinMQ is a high-performance message broker that implements the AMQP 0.9.1 protocol and is wire-compatible with RabbitMQ. The Aspire LavinMQ integration provides a way to connect to existing LavinMQ instances or create new instances from Aspire with the docker.io/cloudamqp/lavinmq container image.

To get started with the Aspire LavinMQ hosting integration, install the CommunityToolkit.Aspire.Hosting.LavinMQ NuGet package in the app host project.

Aspire CLI — Add CommunityToolkit.Aspire.Hosting.LavinMQ package
aspire add communitytoolkit-lavinmq

The Aspire CLI is interactive, be sure to select the appropriate search result when prompted:

Aspire CLI — Example output prompt
Select an integration to add:
> communitytoolkit-lavinmq (CommunityToolkit.Aspire.Hosting.LavinMQ)
> Other results listed as selectable options...

In your app host project, register and consume a LavinMQ server integration using the AddLavinMQ extension method to add the LavinMQ server resource to the builder:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq");
builder.AddProject<Projects.ExampleProject>()
.WithReference(lavinmq);
// After adding all resources, run the app...

When Aspire adds a container image to the app host, as shown in the preceding example with the docker.io/cloudamqp/lavinmq image, it creates a new LavinMQ instance. The default username is guest, and the password is a randomly generated string.

To add data volumes for persisting LavinMQ data, call the WithDataVolume method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq")
.WithDataVolume();
builder.AddProject<Projects.ExampleProject>()
.WithReference(lavinmq);

The data volume is used to persist the LavinMQ data outside the lifecycle of the container.

For development scenarios, you may want to use bind mounts instead of data volumes. To add a data bind mount, call the WithDataBindMount method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq")
.WithDataBindMount(source: @"C:\LavinMQ\Data");
builder.AddProject<Projects.ExampleProject>()
.WithReference(lavinmq);

LavinMQ provides a management UI that you can use to monitor and manage your LavinMQ instance. The management UI is automatically exposed when you add a LavinMQ resource and is accessible through the Aspire dashboard.

LavinMQ is wire-compatible with RabbitMQ and uses the AMQP 0.9.1 protocol. To connect to LavinMQ from your client application, use the Aspire.RabbitMQ.Client NuGet package:

.NET CLI — Add Aspire.RabbitMQ.Client package
dotnet add package Aspire.RabbitMQ.Client

In the Program.cs file of your client-consuming project, call the AddRabbitMQClient extension method to register an IConnection for use through dependency injection. The method takes a connection name parameter:

builder.AddRabbitMQClient(connectionName: "lavinmq");

You can then retrieve the IConnection instance using dependency injection. For example, to retrieve the connection object from an example service:

public class ExampleService(IConnection connection)
{
// Use connection...
}

For more information on using the RabbitMQ client with LavinMQ, see the RabbitMQ integration documentation.

Because LavinMQ is wire-compatible with RabbitMQ, you can use the same configuration options as the RabbitMQ client integration. The Aspire RabbitMQ client integration supports Microsoft.Extensions.Configuration. It loads the RabbitMQClientSettings from configuration using the Aspire:RabbitMQ:Client key.

For more information about configuration options, see the RabbitMQ integration documentation.

By default, the Aspire RabbitMQ client integration handles health checks using the AspNetCore.HealthChecks.RabbitMQ package. Since LavinMQ is wire-compatible with RabbitMQ, the same health checks work for LavinMQ connections.

The LavinMQ integration uses the RabbitMQ client, which provides observability features. For more information about tracing, metrics, and logging with the RabbitMQ client, see the RabbitMQ integration documentation.

FAQCollaborateCommunityDiscussWatch