RabbitMQ is an open-source message-broker software that originally implemented the Advanced Message Queuing Protocol and has since been extended with a plug-in architecture to support Streaming Text Oriented Messaging Protocol, Message Queuing Telemetry Transport, and other protocols.
RabbitMQ can be used in CAP as a message transporter.
To use RabbitMQ transporter, you need to install the following package from NuGet:
PM> Install-Package DotNetCore.CAP.RabbitMQ
Next, add configuration items to the ConfigureServices
method of Startup.cs
.
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddCap(x =>
{
x.UseRabbitMQ(opt=>
{
//RabbitMQOptions
});
// x.UseXXX ...
});
}
The RabbitMQ configuration parameters provided directly by CAP:
NAME | DESCRIPTION | TYPE | DEFAULT |
---|---|---|---|
HostName | Broker host address | string | localhost |
UserName | Broker user name | string | guest |
Password | Broker password | string | guest |
VirtualHost | Broker virtual host | string | / |
Port | Port | int | -1 |
TopicExchangeName | Default exchange name of cap created | string | cap.default.topic |
QueueMessageExpires | Message expries after to delete, in milliseconds | int | (10 days) milliseconds |
If you need more native ConnectionFactory
configuration options, you can set it by ‘ConnectionFactoryOptions’ option:
services.AddCap(x =>
{
x.UseRabbitMQ(o =>
{
o.HostName = "localhost";
o.ConnectionFactoryOptions = opt => {
//rabbitmq client ConnectionFactory config
};
});
});
using comma split connection string, like this:
x=> x.UseRabbitMQ("localhost:5672,localhost:5673,localhost:5674")