LavinMQ integration
Konten ini belum tersedia dalam bahasa Anda.
This article is the reference for the Aspire LavinMQ Hosting integration. It enumerates the AppHost APIs that you use to model a LavinMQ resource in your AppHost project. LavinMQ is a high-performance message broker that implements the AMQP 0.9.1 protocol and is wire-compatible with RabbitMQ. The integration provisions a LavinMQ instance using the docker.io/cloudamqp/lavinmq container image.
Installation
Section titled “Installation”To start building an Aspire app that uses LavinMQ, install the 📦 CommunityToolkit.Aspire.Hosting.LavinMQ NuGet package in the AppHost project:
aspire add lavinmqOr, choose a manual installation approach:
#:package CommunityToolkit.Aspire.Hosting.LavinMQ@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.LavinMQ" Version="*" />Add LavinMQ resource
Section titled “Add LavinMQ resource”Once you’ve installed the hosting integration in your AppHost project, you can add a LavinMQ server resource as shown in the following examples:
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 AppHost, 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.
Add LavinMQ resource with data volume
Section titled “Add LavinMQ resource with data volume”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);
// After adding all resources, run the app...The data volume is used to persist the LavinMQ data outside the lifecycle of the container.
Add LavinMQ resource with data bind mount
Section titled “Add LavinMQ resource with data bind mount”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);
// After adding all resources, run the app...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, install the 📦 Aspire.RabbitMQ.Client NuGet package:
dotnet add package Aspire.RabbitMQ.ClientAdd 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.