QueuePublisher 1.0.1
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 QueuePublisher --version 1.0.1
NuGet\Install-Package QueuePublisher -Version 1.0.1
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="QueuePublisher" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QueuePublisher" Version="1.0.1" />
<PackageReference Include="QueuePublisher" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add QueuePublisher --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QueuePublisher, 1.0.1"
#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.
#:package QueuePublisher@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=QueuePublisher&version=1.0.1
#tool nuget:?package=QueuePublisher&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
QueuePublisher
QueuePublisher es una librería en .NET 8 que proporciona una interfaz unificada para trabajar con diferentes brokers de mensajería como AWS SQS y RabbitMQ.
El objetivo es simplificar el envío y consumo de mensajes sin acoplar tu aplicación a un proveedor específico.
Características
- Interfaz común
IQueueProduceryIQueueConsumerpara todos los brokers. - Implementación para AWS SQS.
- Implementación para RabbitMQ (compatible con CloudAMQP y servidores locales).
- Mensajes persistentes.
- Configuración flexible vía
appsettings.json. - Ejemplo de uso con
Program.cspara pruebas rápidas.
Estructura del Proyecto
QueuePublisher/
│── Interfaces/
│ ├── IQueueProducer.cs # Interfaz para publicar mensajes
│ ├── IQueueConsumer.cs # Interfaz para consumir mensajes
│
│── SQS/
│ ├── AwsSqsService.cs # Implementación de SQS (Producer + Consumer)
│ ├── AwsSqsMessage.cs # Representación de un mensaje recibido
│
│── RabbitMQ/
│ ├── RabbitMQProducer.cs # Implementación de RabbitMQ Producer
│ ├── RabbitMQConsumer.cs # Implementación de RabbitMQ Consumer
│ ├── RabbitMQMessage.cs # Representación de un mensaje recibido
│ ├── RabbitMQSettings.cs # Configuración de RabbitMQ
│
│── Configuration/
│ ├── QueueSettings.cs # Configuración unificada para colas
│
│── Program.cs (ejemplo de prueba rápida)
│── QueuePublisher.csproj
Instalación
Agrega las dependencias necesarias en tu proyecto:
<ItemGroup>
<PackageReference Include="AWSSDK.Core" Version="4.0.0.22" />
<PackageReference Include="AWSSDK.SQS" Version="4.0.0.20" />
<PackageReference Include="RabbitMQ.Client" Version="7.1.2" />
</ItemGroup>
Configuración
Ejemplo de appsettings.json:
{
"AWS": {
"Region": "us-east-1",
"Profile": "default",
"AccessKey": "your-access-key",
"SecretKey": "your-secret-key"
},
"SQSQueueName": "notification-queue-dev",
"RabbitMQ": {
"HostName": "leopard-01.lmq.cloudamqp.com",
"UserName": "your-username",
"Password": "your-password",
"VirtualHost": "your-vhost",
"QueueName": "mi-cola-rabbit"
}
}
Ejemplo de Uso
using Amazon.SQS;
using Microsoft.Extensions.Configuration;
using QueuePublisher.SQS;
using QueuePublisher.RabbitMQ;
using RabbitMQ.Client;
class Program
{
public static async Task Main()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
await TestSqs(config);
await TestRabbitMq(config);
}
private static async Task TestSqs(IConfiguration config)
{
var sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.GetBySystemName(config["AWS:Region"]));
var sqsService = new AwsSqsService(sqsClient, config["SQSQueueName"]);
Console.WriteLine("📤 Enviando mensaje a SQS...");
await sqsService.SendMessageAsync("Hola desde SQS 🚀");
Console.WriteLine("📥 Recibiendo mensajes de SQS...");
await sqsService.ReceiveMessagesAsync(async message =>
{
Console.WriteLine($"➡️ SQS: {message}");
await Task.CompletedTask;
});
}
private static async Task TestRabbitMq(IConfiguration config)
{
var rabbit = config.GetSection("RabbitMQ");
var factory = new ConnectionFactory
{
HostName = rabbit["HostName"],
UserName = rabbit["UserName"],
Password = rabbit["Password"],
VirtualHost = rabbit["VirtualHost"]
};
using var connection = await factory.CreateConnectionAsync();
var producer = new RabbitMQProducer(connection, rabbit["QueueName"]);
var consumer = new RabbitMQConsumer(connection, rabbit["QueueName"]);
Console.WriteLine("📤 Enviando mensaje a RabbitMQ...");
await producer.SendMessageAsync("Hola desde RabbitMQ 🚀");
Console.WriteLine("📥 Escuchando mensajes de RabbitMQ...");
await consumer.ReceiveMessagesAsync(async message =>
{
Console.WriteLine($"➡️ RabbitMQ: {message}");
await Task.CompletedTask;
});
await Task.Delay(-1); // Mantener app viva
}
}
Interfaces
Producer
public interface IQueueProducer
{
Task SendMessageAsync(string message);
}
Consumer
public interface IQueueConsumer
{
Task ReceiveMessagesAsync(Func<string, Task> handleMessage);
}
RabbitMQ Ejemplo con CloudAMQP
var factory = new ConnectionFactory
{
HostName = "your-host",
UserName = "your-user",
Password = "your-pass",
VirtualHost = "your-vhost"
};
using var connection = await factory.CreateConnectionAsync();
var producer = new RabbitMQProducer(connection, "mi-cola-rabbit");
await producer.SendMessageAsync("Mensaje de prueba 🚀");
AWS SQS Ejemplo
var sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USEast1);
var sqsService = new AwsSqsService(sqsClient, "notification-queue-dev");
await sqsService.SendMessageAsync("Mensaje de prueba en SQS 🚀");
await sqsService.ReceiveMessagesAsync(async message =>
{
Console.WriteLine($"➡️ SQS: {message}");
});
Roadmap
- Soporte para Azure Service Bus
- Manejo avanzado de Dead Letter Queues (DLQ)
- Integración con Polly para resiliencia
- Publicación como NuGet Package
📝 Licencia
MIT License © 2025 - Desarrollado por Jhoan Hurtado
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- AWSSDK.Core (>= 4.0.0.22)
- AWSSDK.SQS (>= 4.0.0.20)
- RabbitMQ.Client (>= 7.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Versión inicial con soporte para RabbitMQ y AWS SQS.