src/AWS/Orleans.Clustering.DynamoDB/README.md
Microsoft Orleans Clustering for DynamoDB provides cluster membership functionality for Microsoft Orleans using Amazon's DynamoDB. This allows Orleans silos to coordinate and form a cluster using DynamoDB as the backing store.
To use this package, install it via NuGet:
dotnet add package Microsoft.Orleans.Clustering.DynamoDB
using Microsoft.Extensions.Hosting;
using Orleans.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
namespace ExampleGrains;
// Define a grain interface
public interface IHelloGrain : IGrainWithStringKey
{
Task<string> SayHello(string greeting);
}
// Implement the grain interface
public class HelloGrain : Grain, IHelloGrain
{
public Task<string> SayHello(string greeting)
{
return Task.FromResult($"Hello, {greeting}!");
}
}
var builder = Host.CreateApplicationBuilder(args)
.UseOrleans(siloBuilder =>
{
siloBuilder
// Configure DynamoDB clustering
.UseDynamoDBClustering(options =>
{
options.AccessKey = "YOUR_AWS_ACCESS_KEY";
options.SecretKey = "YOUR_AWS_SECRET_KEY";
options.Region = "us-east-1";
options.TableName = "OrleansClusteringTable";
options.CreateIfNotExists = true;
});
});
var host = builder.Build();
await host.StartAsync();
// Get a reference to a grain and call it
var client = host.Services.GetRequiredService<IClusterClient>();
var grain = client.GetGrain<IHelloGrain>("user123");
var response = await grain.SayHello("DynamoDB");
// Print the result
Console.WriteLine($"Grain response: {response}");
// Keep the host running until the application is shut down
await host.WaitForShutdownAsync();
For more comprehensive documentation, please refer to: