FastCSharp.RabbitPublisher
0.4.2-alpha
This is a prerelease version of FastCSharp.RabbitPublisher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FastCSharp.RabbitPublisher --version 0.4.2-alpha
NuGet\Install-Package FastCSharp.RabbitPublisher -Version 0.4.2-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FastCSharp.RabbitPublisher" Version="0.4.2-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FastCSharp.RabbitPublisher --version 0.4.2-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FastCSharp.RabbitPublisher, 0.4.2-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FastCSharp.RabbitPublisher as a Cake Addin #addin nuget:?package=FastCSharp.RabbitPublisher&version=0.4.2-alpha&prerelease // Install FastCSharp.RabbitPublisher as a Cake Tool #tool nuget:?package=FastCSharp.RabbitPublisher&version=0.4.2-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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.
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.
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 RabbitDirectExchangeFactory(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
{
"RabbitPublisherConfig" : {
"HostName" : "localhost",
"VirtualHost" : "MyVirtualHost",
"Port" : 5672,
"UserName" : "guest",
"Password" : "guest",
"Timeout" : "00:00:10",
"Exchanges" :
{
"TEST_EXCHANGE" : {
"Name" : "test.direct.exchange.v-1.0",
"Type" : "direct",
"NamedRoutingKeys" : {
"TEST_QUEUE" : "test.direct.q"
}
}
}
}
}
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- FastCSharp.Publisher (>= 0.2.0-alpha)
- FastCSharp.RabbitCommon (>= 1.0.0)
- 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 | 528 | 1/5/2024 |
1.4.0 | 156 | 12/17/2023 |
1.0.1 | 157 | 11/28/2023 |
1.0.0 | 158 | 10/20/2023 |
0.4.3-alpha | 102 | 9/25/2023 |
0.4.2-alpha | 116 | 9/23/2023 |
0.4.1-alpha | 97 | 9/23/2023 |
0.3.1-alpha | 113 | 9/22/2023 |
0.0.1-alpha | 113 | 9/18/2023 |
0.0.0-alpha | 129 | 4/9/2023 |