LavinMQ integration
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.
Hosting integration
Section titled “Hosting integration”To get started with the Aspire LavinMQ hosting integration, install the CommunityToolkit.Aspire.Hosting.LavinMQ NuGet package in the app host project.
aspire add communitytoolkit-lavinmqThe Aspire CLI is interactive, be sure to select the appropriate search result when prompted:
Select an integration to add:
> communitytoolkit-lavinmq (CommunityToolkit.Aspire.Hosting.LavinMQ)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.LavinMQ@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.LavinMQ" Version="*" />Add LavinMQ resource
Section titled “Add LavinMQ resource”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:
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.
Data persistence
Section titled “Data persistence”To add data volumes for persisting LavinMQ data, call the WithDataVolume method:
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:
var builder = DistributedApplication.CreateBuilder(args);
var lavinmq = builder.AddLavinMQ("lavinmq") .WithDataBindMount(source: @"C:\LavinMQ\Data");
builder.AddProject<Projects.ExampleProject>() .WithReference(lavinmq);Management UI
Section titled “Management UI”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.
Client integration
Section titled “Client integration”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:
dotnet add package Aspire.RabbitMQ.Client#:package Aspire.RabbitMQ.Client@*<PackageReference Include="Aspire.RabbitMQ.Client" Version="*" />Add RabbitMQ client API
Section titled “Add RabbitMQ client API”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.
Configuration
Section titled “Configuration”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.
Health checks
Section titled “Health checks”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.
Observability and telemetry
Section titled “Observability and telemetry”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.