Get started with the RabbitMQ integration
Este conteúdo não está disponível em sua língua ainda.
RabbitMQ is a reliable messaging and streaming broker, which is easy to deploy on cloud environments, on-premises, and on your local machine. The Aspire RabbitMQ integration enables you to connect to existing RabbitMQ instances, or create new instances from the docker.io/library/rabbitmq container image.
In this introduction, you’ll see how to install and use the Aspire RabbitMQ integrations in a simple configuration. If you already have this knowledge, see RabbitMQ hosting integration for full reference details.
Set up hosting integration
Section titled “Set up hosting integration”To begin, install the Aspire RabbitMQ hosting integration in your Aspire AppHost project:
aspire add rabbitmqA Aspire CLI é interativa; escolha o resultado adequado quando solicitado:
Select an integration to add:
> rabbitmq (Aspire.Hosting.RabbitMQ)> Other results listed as selectable options...#:package Aspire.Hosting.RabbitMQ@*<PackageReference Include="Aspire.Hosting.RabbitMQ" Version="*" />Next, in the AppHost project, create instances of RabbitMQ resources and pass them to the consuming client projects:
var builder = DistributedApplication.CreateBuilder(args);
var rabbitmq = builder.AddRabbitMQ("messaging");
builder.AddProject<Projects.ExampleProject>() .WithReference(rabbitmq);
builder.Build().Run();When Aspire adds a container image to the app host, it creates a new RabbitMQ server instance on your local machine. The RabbitMQ server resource includes default credentials with a username of "guest" and randomly generated password.
Set up client integration
Section titled “Set up client integration”To get started with the Aspire RabbitMQ client integration, install the package:
dotnet add package Aspire.RabbitMQ.Client#:package Aspire.RabbitMQ.Client@*<PackageReference Include="Aspire.RabbitMQ.Client" Version="*" />In the Program.cs file of your client-consuming project, call the AddRabbitMQClient extension method to register an IConnection for use via the dependency injection container:
builder.AddRabbitMQClient(connectionName: "messaging");You can then retrieve the IConnection instance using dependency injection:
public class ExampleService(IConnection connection){ // Use connection...}