This project provides an example implementation of a message queue system using different backends like RabbitMQ and InMemory queues. The system is designed to be extensible, allowing easy integration of new message queue implementations. The project also includes a setup for configuring and consuming messages from the queues.
SimpleQueue
: Contains the main interfaces and base setup classes.SimpleQueue.RabbitMQ
: Contains the RabbitMQ-specific implementations and setup classes.SimpleQueue.InMemory
: Contains the InMemory-specific implementations and setup classes.SimpleQueue.Kafka
: Contains the Kafka-specific implementations and setup classes.SimpleQueue.Redis
: Contains the Redis-specific implementations and setup classes (not implemented).SimpleQueue.AmazonSQS
: Contains the Amazon SQS-specific implementations and setup classes (not done).SimpleQueue.Demo.Console
: Contains a demo console application to demonstrate the usage of the message queue system.SimpleQueue.Demo.Web
: Contains a demo web application to demonstrate the usage of the message queue system.SimpleQueue.Demo.ServiceDefaults
: Contains the default service configurations for the demo applications. (.NET Aspire)SimpleQueue.Demo.AppHost
: Contains the host configuration for the demo applications. (.NET Aspire)SimpleQueue.Test
: Contains helper classes and methods for testing the project.SimpleQueue.*.Test
: Contains unit tests for the project.
- .NET 8 SDK
- RabbitMQ (if using RabbitMQ backend)
- Redis (if using Redis backend, though it isn't implemented in this example)
- Clone the repository:
git clone https://github.com/mrcode86/SimpleQueue.NET.git cd SimpleQueue.NET
- Restore the dependencies:
dotnet restore
- Build the solution:
dotnet build
Configure the services in your Program.cs or Startup.cs file as follows:
var builder = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
// Configure RabbitMQ
services.ConfigureRabbitMq("your-rabbitmq-connection-string");
// Configure InMemory queue
services.RegisterQueueHandlersAndServices();
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
});
await builder.RunConsoleAsync();
To send a message to the queue, you need to inject the IMessageQueue interface and use the Send method:
public class MessageProducer
{
private readonly IMessageQueue<YourMessageModel> _messageQueue;
public MessageProducer(IMessageQueue<YourMessageModel> messageQueue)
{
_messageQueue = messageQueue;
}
public void ProduceMessage(YourMessageModel message)
{
_messageQueue.Send(message, EventTypes.SomeEventType);
}
}
To consume messages, implement the IMessageHandler interface and handle the messages accordingly:
public class YourMessageHandler : IMessageHandler<YourMessageModel>
{
public Task HandleAsync(YourMessageModel message)
{
// Handle the message
return Task.CompletedTask;
}
}
To run the tests, use the following command:
dotnet test
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
This project is licensed under the MIT License. See the MIT file for details.