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.

The compiled Redis Journaling sample 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()
{
count.Value++;
await WriteStateAsync();
return GetCurrentSnapshot();
}
public ValueTask<CounterSnapshot> GetSnapshot() =>
ValueTask.FromResult(GetCurrentSnapshot());
public ValueTask Deactivate()
{
DeactivateOnIdle();
return ValueTask.CompletedTask;
}
private CounterSnapshot GetCurrentSnapshot() =>
new(_activationId, count.Value);
}

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.