Skip to content

Run Orleans Journaling samples

The Journaling with Azure Blob JSON sample exercises the experimental Journaling programming model end to end. It uses .NET Aspire and the Azure Storage emulator and runs with local emulator credentials.

The sample demonstrates:

Install the .NET SDK, the Aspire CLI, and a Docker-compatible container runtime. From the sample directory, run:

Terminal window
aspire run --project JournalingAzureBlobJson.AppHost

The app host starts the Azure Storage emulator and the sample service. The service writes every built-in durable state category, deactivates the grain, verifies the recovered values on a new activation, and prints the stored JSON Lines.

This sample keeps its own NuGet package declarations. While the manager APIs await publication, the repository’s samples\Build-Samples.ps1 supplies packages built from the current sources.

The Redis Journaling snippet project retains keyed injection and the DurableGrain helper. It configures Redis, writes an IDurableValue<T>, deactivates the grain, and verifies recovery on a new activation:

public sealed class RedisJournalCounterGrain(
[FromKeyedServices("count")] IDurableValue<int> count)
: DurableGrain, IRedisJournalCounterGrain
{
private readonly Guid _activationId = Guid.NewGuid();
public async ValueTask<CounterSnapshot> Increment(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
count.Value++;
await WriteStateAsync(cancellationToken);
return GetCurrentSnapshot();
}
public ValueTask<CounterSnapshot> GetSnapshot(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
return ValueTask.FromResult(GetCurrentSnapshot());
}
public ValueTask Deactivate(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
DeactivateOnIdle();
return ValueTask.CompletedTask;
}
private CounterSnapshot GetCurrentSnapshot() =>
new(_activationId, count.Value);
}

The journaling snippet projects reference the current repository sources, so they exercise the documented APIs without substituting an older package. Start a local Redis server, then run the sample from the repository root:

Terminal window
dotnet run --project docs/site/src/content/docs/grains/journaling/snippets/redis-journaling -- "localhost:6379"

Pass a StackExchange.Redis connection string as the first argument when Redis is available at another endpoint. The sample uses the isolated key prefix journaling-docs-sample. Configure Redis persistence and replication before evaluating server-restart recovery.