RabbitMQ messaging library for .NET with SSE support and AI-powered document summarization.
<EnablePreviewFeatures>true</EnablePreviewFeatures>
{
"RabbitMQ": {
"Uri": "amqp://guest:guest@localhost:5672"
}
}
// Add RabbitMQ
builder.Services.AddPaperlessRabbitMq(builder.Configuration);
// With SSE support
services.AddPaperlessRabbitMq(config, includeOcrResultStream: true, includeGenAiResultStream: true);
var command = new OcrCommand(docId, fileName, storagePath);
await publisher.PublishOcrCommandAsync(command);
var result = new OcrEvent(jobId, "Completed", text, DateTimeOffset.UtcNow);
await publisher.PublishOcrEventAsync(result);
await using var consumer = await factory.CreateConsumerAsync<OcrCommand>();
await foreach (var command in consumer.ConsumeAsync(cancellationToken))
{
try
{
// Process message
await consumer.AckAsync();
}
catch
{
await consumer.NackAsync(requeue: true);
}
}
// Map endpoint
app.MapOcrEventStream();
// Client-side
const eventSource = new EventSource('/api/v1/ocr-results');
eventSource.addEventListener('ocr-completed', (event) => {
const data = JSON.parse(event.data);
console.log(data);
});
// Enable GenAI features
builder.Services.AddPaperlessRabbitMq(configuration,
includeOcrResultStream: true,
includeGenAiResultStream: true);
// Configure Gemini
builder.Services.Configure<GeminiOptions>(configuration.GetSection("Gemini"));
builder.Services.AddHttpClient<ITextSummarizer, GeminiService>();
builder.Services.AddHostedService<GenAIWorker>();
// Publish GenAI command
var genAiCommand = new GenAICommand(request.JobId, result.Text!);
await _publisher.PublishGenAICommandAsync(genAiCommand);
{
"Gemini": {
"ApiKey": "your-api-key",
"Model": "gemini-2.0-flash"
}
}
public record OcrCommand(Guid JobId, string FileName, string FilePath);
public record OcrEvent(Guid JobId, string Status, string? Text, DateTimeOffset ProcessedAt);
public record GenAICommand(Guid DocumentId, string Text);
public record GenAIEvent(Guid DocumentId, string? Summary, DateTimeOffset ProcessedAt, string? ErrorMessage = null);
dotnet add package SWEN3.Paperless.RabbitMq
This project is licensed under the MIT License.