Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orleans MultiClient                 中文

NuGet GitHub license

Orleans.MultiClient is an Orleans multi-client, with simple configuration you can easily connect to Orleans Slio. Orleans.MultiClient can connect to many different Orleans Slio, Orleans.MultiClient Orleans Grain automatically finds Orleans clients upon request.

Note:Orleans.MultiClient only supports .NET Core platform.

Getting Started

NuGet

PM> dotnet add package Orleans.MultiClient

Simple example

A simple example demonstrates how Orleans.MultiClient connects to two different services (A, B).

Note:The source code for the simple example is in the example folder in the Github repository

1、Add the Grain interface package of A and B to the project of Orleans Client

<ItemGroup>
    <PackageReference Include="Orleans.MultiClient" Version="3.1.0" />
    <!--A Slio Grain interface package-->
    <ProjectReference Include="..\Orleans.Grain2\Orleans.Grain2.csproj" /> 
    <!--B Slio Grain interface package-->
    <ProjectReference Include="..\Orleans.Grain\Orleans.Grain.csproj" /> 
</ItemGroup>

2、Configure Orleans.MultiClient and inject Orleans.MultiClient into IServiceCollection

services.AddOrleansMultiClient(build =>
{
    build.AddClient(opt =>
    {
        opt.ServiceId = "A";
        opt.ClusterId = "AApp";
        opt.SetServiceAssembly(typeof(IHelloA).Assembly);
        opt.Configure = (b =>
        {
            b.UseLocalhostClustering(gatewayPort: 30000);
        });
    });
    build.AddClient(opt =>
    {
        opt.ServiceId = "B";
        opt.ClusterId = "BApp";
        opt.SetServiceAssembly(typeof(IHelloB).Assembly);
        opt.Configure = (b =>
        {
            b.UseLocalhostClustering(gatewayPort: 30001);
        });
    });
});

3、Request A Slio and B Slio separately

Note: Before requesting, A Slio and B Slio need to be started, otherwise the request will fail.

// Request A Slio.
var serviceA = _serviceProvider.GetRequiredService<IOrleansClient>().GetGrain<IHelloA>(1);
var resultA = serviceA.SayHello("Hello World Success GrainA").GetAwaiter().GetResult();

// Request B Slio.
var serviceB = _serviceProvider.GetRequiredService<IOrleansClient>().GetGrain<IHelloB>(1);
var resultB = serviceB.SayHello("Hello World Success GrainB").GetAwaiter().GetResult();

Configuration

AddOrleansMultiClient method supports IServiceCollection and GenericHost configuration.

Configure Orleans Slio connection

Configure connectivity for a single Orleans Slio.

services.AddOrleansMultiClient(build =>
{
    build.AddClient(opt =>
    {
        opt.ServiceId = "A";
        opt.ClusterId = "AApp";
        opt.SetServiceAssembly(typeof(IHelloA).Assembly);
        opt.Configure = (b =>
        {
            b.UseLocalhostClustering(gatewayPort: 30000);
         // b.UseStaticClustering(...);  
         // b.UseConsulClustering(...); // Configure Consul
         // b.UseKubeGatewayListProvider(); // Configure Kubernetes
         // b.UseAdoNetClustering(...); // Configure MySql and SQLServer
        });
    });
}

Global configuration, common to all clients

services.AddOrleansMultiClient(build =>{
    build.Configure(b =>{
        b.UseConsulClustering(...);
     // b.UseKubeGatewayListProvider(); // Configure Kubernetes
     // b.UseAdoNetClustering(...); // Configure MySql and SQLServer
    });
    build.AddClient(opt =>
    {
        opt.ServiceId = "A";
        opt.ClusterId = "AApp";
        opt.SetServiceAssembly(typeof(IHelloA).Assembly);
    }
}

About

A library to simplify access to multiple Orleans Clusters from a single point.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages