title: Local development configuration

Local development configuration

For a working sample application that targets Orleans 3.0 see: https://github.com/dotnet/orleans/tree/master/Samples/3.0/HelloWorld. The sample hosts the client and the silo in .NET Core console applications that work in different platforms, while the grains and interfaces target .NET Standard 2.0.

For older versions of Orleans please see their respective Sample projects: https://github.com/dotnet/orleans/tree/master/Samples/.

Silo configuration

For local development, please refer to the below example of how to configure a silo for that case. It configures and starts a silo listening on loopback address and 11111 and 30000 as silo and gateway ports respectively.

Add the Microsoft.Orleans.Server NuGet meta-package to the project. After you get comfortable with the API, you can pick and choose which exact packages included in Microsoft.Orleans.Server you actually need, and reference them instead.

  1. PM> Install-Package Microsoft.Orleans.Server

You need to configure ClusterOptions via ISiloBuilder.Configure method, specify that you want DevelopmentClustering as your clustering choice with this silo being the primary, and then configure silo endpoints.

ConfigureApplicationParts call explicitly adds the assembly with grain classes to the application setup. It also adds any referenced assembly due to the WithReferences extension. After these steps are completed, the silo host gets built and the silo gets started.

You can create an empty console application project targeting .NET Framework 4.6.1 or higher for hosting a silo, as well as a .NET Core console application.

Here is an example of how a local silo can be started:

  1. public class Program
  2. {
  3. public static async Task Main(string[] args)
  4. {
  5. try
  6. {
  7. var host = await StartSilo();
  8. Console.WriteLine("Press Enter to terminate...");
  9. Console.ReadLine();
  10. await host.StopAsync();
  11. return;
  12. }
  13. catch (Exception ex)
  14. {
  15. Console.WriteLine(ex);
  16. return;
  17. }
  18. }
  19. private static async Task<ISiloHost> StartSilo()
  20. {
  21. var builder = new SiloHostBuilder()
  22. // Use localhost clustering for a single local silo
  23. .UseLocalhostClustering()
  24. // Configure ClusterId and ServiceId
  25. .Configure<ClusterOptions>(options =>
  26. {
  27. options.ClusterId = "dev";
  28. options.ServiceId = "MyAwesomeService";
  29. })
  30. // Configure connectivity
  31. .Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
  32. // Configure logging with any logging framework that supports Microsoft.Extensions.Logging.
  33. // In this particular case it logs using the Microsoft.Extensions.Logging.Console package.
  34. .ConfigureLogging(logging => logging.AddConsole());
  35. var host = builder.Build();
  36. await host.StartAsync();
  37. return host;
  38. }
  39. }

Client configuration

For local development, please refer to the below example of how to configure a client for that case. It configures a client that would connect to a loopback silo.

Add the Microsoft.Orleans.Client NuGet meta-package to the project. After you get comfortable with the API, you can pick and choose which exact packages included in Microsoft.Orleans.Client you actually need, and reference them instead.

  1. PM> Install-Package Microsoft.Orleans.Client

You need to configure ClientBuilder with a cluster ID that matches the one you specified for local silo and specify static clustering as your clustering choice pointing it to the gateway port of the silo

ConfigureApplicationParts call explicitly adds the assembly with grain interfaces to the application setup.

After these steps are completed, we can build the client and Connect() method on it to connect to the cluster.

You can create an empty console application project targeting .NET Framework 4.6.1 or higher for running a client or reuse the console application project you created for hosting a silo.

Here is an example of how a client can connect to a local silo:

  1. client = new ClientBuilder()
  2. // Use localhost clustering for a single local silo
  3. .UseLocalhostClustering()
  4. // Configure ClusterId and ServiceId
  5. .Configure<ClusterOptions>(options =>
  6. {
  7. options.ClusterId = "dev";
  8. options.ServiceId = "MyAwesomeService";
  9. })
  10. .ConfigureLogging(logging => logging.AddConsole())
  11. var client = builder.Build();
  12. await client.Connect();