इसे छोड़कर कंटेंट पर जाएं

Get started with the RabbitMQ integration

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

RabbitMQ logo

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.

To begin, install the Aspire RabbitMQ hosting integration in your Aspire AppHost project:

Aspire CLI — Aspire.Hosting.RabbitMQ पैकेज जोड़ें
aspire add rabbitmq

Aspire CLI इंटरैक्टिव है; प्रॉम्प्ट पर उपयुक्त परिणाम चुनें:

Aspire CLI — उदाहरण आउटपुट
Select an integration to add:
> rabbitmq (Aspire.Hosting.RabbitMQ)
> Other results listed as selectable options...

Next, in the AppHost project, create instances of RabbitMQ resources and pass them to the consuming client projects:

C# — AppHost.cs
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.

To get started with the Aspire RabbitMQ client integration, install the 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 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...
}