Microsoft Orleans Documentation
repository·main·Indexed 27 days ago
https://github.com/dotnet/orleansA cross-platform framework for building robust, scalable distributed applications using the Virtual Actor Model. It enables the creation of distributed systems using .NET concepts like objects, interfaces, and async/await. Key features include grains (entities with identity, behavior, and state), silos for hosting grains, and an admin dashboard (orleans-dashboard-app) for development and testing.
What's inside Orleans
- Orleans is a cross-platform framework for building robust, scalable distributed applications using the Virtual Actor Model. It allows developers to build distributed systems using familiar .NET concepts like objects, interfaces, and async/await. Orleans scales from single on-premises servers to globally distributed cloud applications, providing elastic scalability and fault tolerance.
Overview of Microsoft Orleans Dashboard Core features
mainThe
Microsoft.Orleans.Dashboard.Abstractionspackage includes the following core components for monitoring Orleans clusters:- Metrics Collection Services: Grain-based services that collect runtime statistics.
- Data Models: Shared types for representing silo and grain statistics.
- History Tracking: Time-series data storage for performance metrics.
- Grain Profiling: Method-level performance tracking infrastructure.
Explore Orleans Samples
mainThe official collection of Orleans samples has been moved to thedotnet/samplesrepository. You can browse them via the Samples browser or access the source directly on GitHub. These samples cover a wide range of use cases from basic 'Hello World' applications to complex distributed systems involving transactions, streaming, and Kubernetes deployment.Understand the Orleans Runtime and Silos
mainThe Orleans runtime implements the programming model.
- Silo: The main component of the runtime responsible for hosting grains. Silos typically run in a cluster to provide scalability and fault tolerance.
- Cluster: A group of silos that coordinate to distribute work and recover from failures. Grains in a cluster communicate as if they were in a single process.
- Client Library: Used by external clients to call grains. It manages network communication automatically. Clients can be co-hosted in the same process as silos.
Compatibility:
- .NET Standard 2.0 and above.
- Runs on Windows, Linux, and macOS.
- Supports .NET Framework and .NET Core.
Understand the Durable Job lifecycle
mainJobs follow a specific lifecycle managed by the Orleans runtime:
- Scheduled: The job is created and added to a time-based shard.
- Waiting: The job resides in a queue until its
DueTimeis reached. - Executing: The
IDurableJobHandler.ExecuteJobAsyncmethod is invoked on the target grain. - Completion:
- Success: The job is removed.
- Failure: The
ShouldRetrypolicy determines if the job is re-queued with a new due time or removed.
Explore Orleans community extensions via OrleansContrib
mainFor community-driven add-ons, including monitoring tools, design patterns, and storage providers, visit the OrleansContrib GitHub organization.Host the Orleans Dashboard in a separate web application
mainYou can host the Orleans Dashboard in a standalone web application that connects to an Orleans cluster as a client, rather than co-hosting it within the silos. This separates the dashboard web service from your Orleans silos.
Implementation Steps
- Configure the Silo: Ensure your silo is configured with appropriate endpoints and has
AddDashboard()called in its configuration. - Configure the Dashboard Client: In your web application, use
UseOrleansClientto connect to the cluster gateways and callAddDashboard()to register the necessary services. - Map Endpoints: Use
MapOrleansDashboard()in your web application to expose the dashboard routes.
WARNING The Orleans Dashboard is designed for development and testing scenarios only. It is not recommended for production deployments as it can have a significant performance impact on your cluster.
// 1. Silo Configuration var siloHost = Host.CreateDefaultBuilder(args) .UseOrleans((_, builder) => { builder.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(IPAddress.Loopback, 11111)); builder.ConfigureEndpoints(IPAddress.Loopback, 11111, 30000); builder.AddDashboard(); }) .Build(); // 2. Dashboard Web App Configuration var dashboardBuilder = WebApplication.CreateBuilder(args); dashboardBuilder.UseOrleansClient(clientBuilder => { clientBuilder.UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(IPAddress.Loopback, 30000).ToGatewayUri())); clientBuilder.AddDashboard(); }); var app = dashboardBuilder.Build(); // 3. Map Endpoints app.MapOrleansDashboard(); await app.RunAsync();- Configure the Silo: Ensure your silo is configured with appropriate endpoints and has
Integrate Orleans Redis Persistence with .NET Aspire
mainWhen using .NET Aspire, use the .NET Aspire Redis integration for automatic service discovery and telemetry. In your AppHost, use
.WithGrainStorage("storageName", redisResource)to link the Redis resource to your Orleans deployment.// In your AppHost/Program.cs var builder = DistributedApplication.CreateBuilder(args); var redis = builder.AddRedis("redis"); var orleans = builder.AddOrleans("orleans") .WithGrainStorage("redisStore", redis); builder.AddProject<Projects.MyOrleansApp>("orleans-app") .WithReference(orleans); builder.Build().Run();Use Open Iconic SVGs
mainYou can display Open Iconic icons as standard SVG images. It is recommended to use the
altattribute for accessibility.<img src="/open-iconic/svg/icon-name.svg" alt="icon name">Cohost the Orleans Dashboard within an ASP.NET Core application
mainYou can host the Orleans Dashboard within the same process as your Orleans silo using ASP.NET Core minimal APIs. This is the simplest setup for development and testing, allowing the dashboard to run on the same port as your web application.
To implement this, follow these steps:
- Configure Orleans using
builder.UseOrleans(). - Add the dashboard to the silo builder using
siloBuilder.AddDashboard(). - Map the dashboard endpoints to the application using
app.MapOrleansDashboard().
var builder = WebApplication.CreateBuilder(args); // Configure Orleans builder.UseOrleans(siloBuilder => { siloBuilder.UseLocalhostClustering(); siloBuilder.UseInMemoryReminderService(); siloBuilder.AddMemoryGrainStorageAsDefault(); // Add the dashboard siloBuilder.AddDashboard(); }); var app = builder.Build(); // Map dashboard endpoints app.MapOrleansDashboard(); app.Run();- Configure Orleans using
Install Microsoft Orleans Clustering for Azure Cosmos DB
mainTo use Azure Cosmos DB for Orleans cluster membership, install the
Microsoft.Orleans.Clustering.CosmosNuGet package.dotnet add package Microsoft.Orleans.Clustering.CosmosInstall Microsoft Orleans Serialization for MessagePack
mainTo use MessagePack serialization in your Orleans application, install the
Microsoft.Orleans.Serialization.MessagePackpackage via NuGet.dotnet add package Microsoft.Orleans.Serialization.MessagePack