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:
- An ordinary Grain with an injected IDurableStateManager, using constructor-time
GetOrAdddeclarations and activation lifecycle recovery. - IDurableDictionary<T, U>, IDurableList<T>, IDurableQueue<T>, and IDurableSet<T>.
- IDurableValue<T>, journal-backed IPersistentState<T>, and IDurableTaskCompletionSource<T>.
- JSON source-generation metadata for all journaled payload types.
- Azure Blob WAL and checkpoint name customization.
- An acknowledged write, grain deactivation, reactivation, and recovered-state verification.
- Inspection of the raw JSON Lines journal.
Run with Aspire
Section titled “Run with Aspire”Install the .NET SDK, the Aspire CLI, and a Docker-compatible container runtime. From the sample directory, run:
aspire run --project JournalingAzureBlobJson.AppHostThe 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.
Run the Redis sample
Section titled “Run the Redis sample”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:
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.
