Excalibur.Outbox.Firestore 3.0.0-alpha.19

This is a prerelease version of Excalibur.Outbox.Firestore.
dotnet add package Excalibur.Outbox.Firestore --version 3.0.0-alpha.19
                    
NuGet\Install-Package Excalibur.Outbox.Firestore -Version 3.0.0-alpha.19
                    
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="Excalibur.Outbox.Firestore" Version="3.0.0-alpha.19" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Excalibur.Outbox.Firestore" Version="3.0.0-alpha.19" />
                    
Directory.Packages.props
<PackageReference Include="Excalibur.Outbox.Firestore" />
                    
Project file
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 Excalibur.Outbox.Firestore --version 3.0.0-alpha.19
                    
#r "nuget: Excalibur.Outbox.Firestore, 3.0.0-alpha.19"
                    
#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 Excalibur.Outbox.Firestore@3.0.0-alpha.19
                    
#: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=Excalibur.Outbox.Firestore&version=3.0.0-alpha.19&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Excalibur.Outbox.Firestore&version=3.0.0-alpha.19&prerelease
                    
Install as a Cake Tool

Excalibur.Outbox.Firestore

Google Cloud Firestore implementation of the cloud-native outbox pattern for reliable message delivery.

Features

  • Transactional outbox pattern with partition-aware storage
  • Real-time listeners for push-based message processing
  • Automatic TTL cleanup for published messages (via scheduled Cloud Functions)
  • Serverless-friendly - designed for Cloud Functions triggers

Installation

dotnet add package Excalibur.Outbox.Firestore

Configuration

services.AddFirestoreOutboxStore(options =>
{
    options.ProjectId = "my-gcp-project";
    options.CollectionName = "outbox";
    options.DefaultTimeToLiveSeconds = 604800; // 7 days
});

Or via configuration:

services.AddFirestoreOutboxStore(configuration.GetSection("FirestoreOutbox"));

Local Development (Emulator)

services.AddFirestoreOutboxStore(options =>
{
    options.EmulatorHost = "localhost:8080";
    options.CollectionName = "outbox";
});

Service Account Credentials

services.AddFirestoreOutboxStore(options =>
{
    options.ProjectId = "my-gcp-project";
    options.CredentialsPath = "/path/to/service-account.json";
    // OR
    options.CredentialsJson = "{ ... }";
});

Usage

Adding Messages to the Outbox

public class MyService
{
    private readonly ICloudNativeOutboxStore _outbox;

    public MyService(ICloudNativeOutboxStore outbox)
    {
        _outbox = outbox;
    }

    public async Task PublishEventAsync(OrderPlaced @event, CancellationToken ct)
    {
        var message = new CloudOutboxMessage
        {
            MessageId = Guid.NewGuid().ToString(),
            MessageType = nameof(OrderPlaced),
            Payload = JsonSerializer.SerializeToUtf8Bytes(@event),
            AggregateId = @event.OrderId,
            AggregateType = "Order",
            PartitionKeyValue = @event.OrderId,
            CreatedAt = DateTimeOffset.UtcNow
        };

        var partitionKey = new PartitionKey(@event.OrderId);
        var result = await _outbox.AddAsync(message, partitionKey, ct);

        if (!result.Success)
        {
            // Handle failure
        }
    }
}

Processing Messages with Real-time Listener

// Subscribe to new outbox messages
var subscription = await _outbox.SubscribeToNewMessagesAsync(ct);

await foreach (var change in subscription.ReadChangesAsync(ct))
{
    if (change.Document != null)
    {
        // Publish to message broker
        await _messageBroker.PublishAsync(change.Document);

        // Mark as published
        await _outbox.MarkAsPublishedAsync(
            change.DocumentId,
            change.PartitionKey,
            ct);
    }
}

Using with Cloud Functions

For serverless scenarios, use Firestore triggers:

[FirestoreFunction("outbox")]
public async Task ProcessOutboxMessage(
    FirestoreEvent<OutboxDocument> firestoreEvent,
    CancellationToken ct)
{
    var doc = firestoreEvent.Value;

    // Only process unpublished messages
    if (doc.IsPublished)
        return;

    var payload = Convert.FromBase64String(doc.Payload);

    // Publish to message broker
    await _messageBroker.PublishAsync(payload);

    // Mark as published
    await _outbox.MarkAsPublishedAsync(
        doc.MessageId,
        new PartitionKey(doc.PartitionKey),
        ct);
}

Document Schema

The outbox uses the following Firestore document schema:

Field Type Description
messageId String Unique message identifier
partitionKey String Partition key value for querying
messageType String Message type name
payload String Base64-encoded message payload
headers String JSON-encoded headers
aggregateId String Associated aggregate ID
aggregateType String Associated aggregate type
correlationId String Correlation ID for tracing
causationId String Causation ID linking to causing message
createdAt String ISO 8601 timestamp
publishedAt String ISO 8601 timestamp when published
isPublished Boolean Publication status
retryCount Number Number of retry attempts
lastError String Last error message
expireAt Timestamp TTL expiration timestamp

TTL Cleanup

Firestore does not have native TTL support. Use one of these approaches:

  1. Cloud Scheduler + Cloud Function: Periodic cleanup function
  2. Firebase Extensions: firestore-bigquery-export or custom extension
  3. Manual cleanup: Call CleanupOldMessagesAsync periodically

Example Cloud Function for cleanup:

[CloudSchedulerFunction("0 0 * * *")] // Daily at midnight
public async Task CleanupOutbox(CancellationToken ct)
{
    var partitions = await GetActivePartitionsAsync(ct);

    foreach (var partition in partitions)
    {
        await _outbox.CleanupOldMessagesAsync(
            new PartitionKey(partition),
            TimeSpan.FromDays(7),
            ct);
    }
}

Requirements

  • .NET 9.0+
  • Google Cloud Firestore or Firestore Emulator
  • Excalibur.Data.Abstractions for cloud-native interfaces
  • Excalibur.Data.Firestore for Firestore SDK setup

License

See LICENSE files in repository root.

Product 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 is compatible.  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 is compatible.  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.

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
3.0.0-alpha.19 29 2/26/2026