FastCSharp.RabbitPublisher
0.4.3-alpha
See the version list below for details.
dotnet add package FastCSharp.RabbitPublisher --version 0.4.3-alpha
NuGet\Install-Package FastCSharp.RabbitPublisher -Version 0.4.3-alpha
<PackageReference Include="FastCSharp.RabbitPublisher" Version="0.4.3-alpha" />
paket add FastCSharp.RabbitPublisher --version 0.4.3-alpha
#r "nuget: FastCSharp.RabbitPublisher, 0.4.3-alpha"
// Install FastCSharp.RabbitPublisher as a Cake Addin #addin nuget:?package=FastCSharp.RabbitPublisher&version=0.4.3-alpha&prerelease // Install FastCSharp.RabbitPublisher as a Cake Tool #tool nuget:?package=FastCSharp.RabbitPublisher&version=0.4.3-alpha&prerelease
FastCSharp's RabbitMQ Publisher
RabbitPublisher provides a simple approach for publishing messages to a RabbitMQ exchange.
It is a wrapper around the RabbitMQ.Client library.
Batch Publishing
It includes an implementation for batch publishing. Send an IEnumerable of messages and they will be published in a single batch. This is useful when you need to publish a large number of messages with very high throughput.
Usage
All you need to do is create a new publisher to an existing exchange and publish a message.
The example below shows how to publish a message to a direct exchange. Swagger is also configured to allow testing.
The code needed to run is manly in the Runner class.
Checkout FastCSharp.TestRabbitImpl project for a more complete example.
Program.cs
using FastCSharp.Publisher;
using FastCSharp.RabbitPublisher;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// http://localhost:5106/swagger/v1/swagger.json
app.UseSwagger();
// http://localhost:5106/swagger
app.UseSwaggerUI();
var runner = new Runner<Message>();
// http://localhost:5106/SendDirectMessage?message=Hello%20World
app.MapGet("/SendDirectMessage", async Task<IResult> (string? message) => {
var msg = new Message();
msg.Text = message;
await runner.Run(msg);
return TypedResults.Accepted("");
})
.WithOpenApi();
app.Run();
public class Runner<T>
{
IPublisher<T> publisher;
public Runner()
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("rabbitsettings.json", true, true)
.Build();
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
IPublisherFactory publisherFactory = new RabbitDirectPublisherFactory(configuration, loggerFactory);
publisher = publisherFactory.NewPublisher<T>("TEST_EXCHANGE", "TEST_QUEUE");
Console.WriteLine(">> Runner Initialized!");
}
public async Task Run(T message)
{
bool isSent = await publisher.Publish(message);
if (!isSent)
{
throw new Exception(">> Message not sent!");
}
Console.WriteLine(">> Message Sent!");
}
}
public class Message
{
public Message()
{
}
public string? Text { get; set; }
}
rabbitsettings.json config file sample
Checkout FastCSharp.TestRabbitImpl project for a more complete configuration files examples.
{
"RabbitPublisherConfig" : {
"ClientName" : "FastCSharp Publisher",
"Hosts" : [
{"HostName":"localhost", "Port":5671},
{"HostName":"localhost", "Port":5672}
],
"UserName" : "guest",
"Password" : "guest",
"Timeout" : "00:00:10",
"Exchanges" :
{
"DIRECT_EXCHANGE" : {
"Name" : "test.direct.exchange.v-1.0",
"Type" : "direct",
"NamedRoutingKeys" : {
"TEST_QUEUE" : "test.direct.q"
}
},
"TOPIC_EXCHANGE" : {
"Name" : "test.topic.exchange.v-1.0",
"Type" : "topic",
"RoutingKeys" : ["#"]
},
"FANOUT_EXCHANGE" : {
"Name" : "test.fanout.exchange.v-1.0",
"Type" : "fanout"
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- FastCSharp.Publisher (>= 0.2.1-alpha)
- FastCSharp.RabbitCommon (>= 1.0.1)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.3)
- Microsoft.Extensions.Logging (>= 7.0.0)
- RabbitMQ.Client (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.0 | 581 | 1/5/2024 |
1.4.0 | 160 | 12/17/2023 |
1.0.1 | 161 | 11/28/2023 |
1.0.0 | 162 | 10/20/2023 |
0.4.3-alpha | 104 | 9/25/2023 |
0.4.2-alpha | 118 | 9/23/2023 |
0.4.1-alpha | 101 | 9/23/2023 |
0.3.1-alpha | 115 | 9/22/2023 |
0.0.1-alpha | 115 | 9/18/2023 |
0.0.0-alpha | 131 | 4/9/2023 |