Mirage Queue is a library designed to provide the benefits of a message broker without introducing additional infrastructure dependencies. Instead, it leverages a database to function as a message broker.
Note: Currently, this library only supports PostgreSQL databases.
You can install the required packages via NuGet:
dotnet add package InovaNotas.MirageQueue.Postgresdotnet add package InovaNotas.MirageQueue.DashboardThe dashboard provides a web-based interface to monitor and manage your message queues, similar to Hangfire's dashboard.
Setting up Mirage Queue is straightforward. Here’s an example of how to configure it in your application:
using MirageQueue;
using MirageQueue.Postgres;
using MirageQueue.Publishers.Abstractions;
var builder = WebApplication.CreateBuilder(args);
//Configure the default options for MirageQueue
builder.Services.AddMirageQueue();
//Configure Mirage Queue to use the postgres database
builder.Services.AddMirageQueuePostgres(builder.Configuration.GetConnectionString("DefaultConnection"));
//Register all consumers in the given assembly
builder.Services.AddConsumersFromAssembly(typeof(TestMessageConsumer).Assembly);
var app = builder.Build();
// Create the database and all tables needed to run the Mirage Queue
app.UseMirageQueue();
app.Run();Instead of registering all consumers from an assembly, you can register them individually like this:
builder.Services.AddConsumer<TestMessageConsumer>();To create a consumer, implement the IConsumer<T> interface, where T is the type of message you want to process.
You can have multiple consumers handling the same message type.
using MirageQueue.Consumers.Abstractions;
using System.Text.Json;
namespace ExampleApi;
public class TestMessageConsumer : IConsumer<TestMessage>
{
private readonly Random _random = new Random();
public async Task Process(TestMessage message)
{
Console.WriteLine($"Test message {DateTime.Now:hh:mm:ss} {JsonSerializer.Serialize(message)}");
await Task.Delay(TimeSpan.FromMicroseconds(_random.Next(40, 100)));
}
}This library provides two methods for delivering messages to the consumer:
-
Instant Processing:
The consumer can receive and process the message immediately after it’s sent. -
Scheduled Processing:
You can schedule the message to be processed at a specified time in the future.
To use these features, inject the IPublisher interface via dependency injection
public class MyService(IPublisher publisher){
public async Task PublishMessage(){
await publisher.Publish(new TestMessage
{
Id = Guid.NewGuid()
});
}
public async Task ScheduleMessage(){
await publisher.Publish(new TestMessage
{
Id = Guid.NewGuid()
},
DateTime.UtcNow.AddSeconds(3));
}
}The MirageQueue Dashboard provides a comprehensive web interface for monitoring and managing your message queues.
- Real-time Statistics: Live metrics for inbound, outbound, and scheduled messages
- Message Management: Browse, filter, and search through all message types
- Message Details: View complete message information with JSON prettification
- Interactive Tooltips: Hover over truncated message content to see full payload
- Advanced Filtering: Filter outbound messages by contract and endpoint
- Requeue Functionality: Requeue failed or processed messages
- Dark/Light Theme: Toggle between themes
- Responsive Design: Works on desktop and mobile devices
Add the dashboard to your ASP.NET Core application:
using MirageQueue;
using MirageQueue.Postgres;
using MirageQueue.Dashboard; // Add this for dashboard
var builder = WebApplication.CreateBuilder(args);
// Configure MirageQueue
builder.Services.AddMirageQueue();
builder.Services.AddMirageQueuePostgres(builder.Configuration.GetConnectionString("DefaultConnection"));
builder.Services.AddConsumersFromAssembly(typeof(Program).Assembly);
// Add dashboard (optional but recommended)
builder.Services.AddMirageQueueDashboard();
var app = builder.Build();
app.UseRouting();
// Map dashboard endpoints
app.MapMirageQueueDashboard();
// Initialize MirageQueue
app.UseMirageQueue();
app.Run();Once configured, the dashboard is available at:
https://your-app-domain/mirage-dashboard
You can customize the route prefix:
// Custom route prefix
app.MapMirageQueueDashboard("my-custom-path");
// Accessible at: https://your-app-domain/my-custom-pathImportant: The dashboard doesn't include built-in authentication. For production environments:
// Secure with authentication
app.MapMirageQueueDashboard()
.RequireAuthorization("AdminPolicy");
// Or restrict to specific roles
app.MapMirageQueueDashboard()
.RequireAuthorization("Admin");
// Or use custom authentication
app.MapMirageQueueDashboard()
.RequireHost("localhost") // Only local access
.RequireAuthorization();- Overview: Real-time statistics and system status
- Inbound Messages: Messages received for processing
- Outbound Messages: Messages being sent to external endpoints (with contract/endpoint filtering)
- Scheduled Messages: Messages scheduled for future processing
- Message Details: Complete message information with requeue options
For detailed dashboard documentation, see the Dashboard README.