Skip to content

Commit

Permalink
feat(all): upgrade to Olreans RC1 (OrleansContrib#25)
Browse files Browse the repository at this point in the history
* feat(all): upgrade to `olreans RC1`

* extensions: revert `AddApplicationPart` change

* extensions: add `WithReferences` on `AddApplicationPart`
  • Loading branch information
claylaut authored and galvesribeiro committed Mar 5, 2018
1 parent 7bc667c commit 8902398
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 65 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,39 @@ Paket:

## Silo
We need to configure the Orleans Silo with the below:
* Use `.AddSignalR()` on `ClusterConfiguration`.
* Use `.UseSignalR()` on `ISiloHostBuilder`.

***Example***
```cs
var siloConfig = ClusterConfiguration.LocalhostPrimarySilo()
.AddSignalR();
var siloPort = 11111;
int gatewayPort = 30000;
var siloAddress = IPAddress.Loopback;

var silo = new SiloHostBuilder()
.UseConfiguration(siloConfig)
.Configure(options => options.ClusterId = "test-cluster")
.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
.ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
.UseSignalR()
.Build();
await silo.StartAsync();
```

## Client
Now your SignalR application needs to connect to the Orleans Cluster by using an Orleans Client:
* Use `.AddSignalR()` on `ClientConfiguration`.
* Use `.UseSignalR()` on `IClientBuilder`.

***Example***
```cs
var clientConfig = ClientConfiguration.LocalhostSilo()
.AddSignalR();

var client = new ClientBuilder()
.UseConfiguration(clientConfig)
.ConfigureCluster(options => options.ClusterId = "test-cluster")
.UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(siloAddress, gatewayPort).ToGatewayUri()))
.UseSignalR()
.Build();
await client.Connect();
```

Somewhere in your `Startup.cs`:
* Use `.AddSignalR()` on `IServiceCollection` (this is part of `Microsoft.AspNetCore.SignalR` nuget package).
* Use `.AddOrleans()` on `ISignalRBuilder`.

***Example***
```cs
Expand Down
42 changes: 10 additions & 32 deletions src/SignalR.Orleans/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
using System.Reflection;
using Microsoft.AspNetCore.SignalR;
using Orleans;
using Orleans.Hosting;
using Orleans.Runtime.Configuration;
using SignalR.Orleans;
using SignalR.Orleans.Clients;

namespace Microsoft.Extensions.DependencyInjection
{
public static class OrleansServerExtensions
{
public static ClusterConfiguration AddSignalR(this ClusterConfiguration config)
{
config.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER);
try
{
config.AddMemoryStorageProvider("PubSubStore");
}
catch
{
// PubSubStore was already added. Do nothing.
}
config.AddMemoryStorageProvider(Constants.STORAGE_PROVIDER);
return config;
}

public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder)
{
return builder.ConfigureApplicationParts(mgr =>
mgr.AddApplicationPart(typeof(ClientGrain).Assembly));
try { builder = builder.AddMemoryGrainStorage("PubSubStore"); }
catch { /** PubSubStore was already added. Do nothing. **/ }

return builder.AddMemoryGrainStorage(Constants.STORAGE_PROVIDER)
.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER)
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ClientGrain).Assembly).WithReferences());
}
}

public static class OrleansClientExtensions
{
public static ClientConfiguration AddSignalR(this ClientConfiguration config)
{
config.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER);
return config;
}

public static IClientBuilder UseSignalR(this IClientBuilder builder)
{
return builder.ConfigureApplicationParts(mgr =>
mgr.AddApplicationPart(typeof(IClientGrain).Assembly));
}

public static ISignalRBuilder AddOrleans(this ISignalRBuilder builder)
{
builder.Services.AddSingleton(typeof(HubLifetimeManager<>), typeof(OrleansHubLifetimeManager<>));
return builder;
return builder.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER)
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IClientGrain).Assembly).WithReferences())
.ConfigureServices(services => services.AddSingleton(typeof(HubLifetimeManager<>), typeof(OrleansHubLifetimeManager<>)));
}
}
}
8 changes: 4 additions & 4 deletions src/SignalR.Orleans/SignalR.Orleans.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.0.0-alpha2-final" />
<PackageReference Include="Microsoft.Orleans.Core" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansProviders" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.Core" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansProviders" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="2.0.0-rc1" />
</ItemGroup>

</Project>
29 changes: 15 additions & 14 deletions test/SignalR.Orleans.Tests/OrleansFixture.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Net;
using Microsoft.Extensions.DependencyInjection;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using Orleans.Runtime.Configuration;
using Orleans.Serialization;
using System;
using System.Reflection;
using Orleans.Runtime;

namespace SignalR.Orleans.Tests
{
Expand All @@ -15,28 +15,29 @@ public class OrleansFixture : IDisposable

public OrleansFixture()
{
var siloConfig = ClusterConfiguration.LocalhostPrimarySilo()
.AddSignalR();
siloConfig.Globals.FallbackSerializationProvider = typeof(ILBasedSerializer).GetTypeInfo();
var siloPort = 11111;
int gatewayPort = 30000;
var siloAddress = IPAddress.Loopback;

var silo = new SiloHostBuilder()
.UseConfiguration(siloConfig)
.Configure(options => options.ClusterId = "test-cluster")
.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
.ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
.UseSignalR()
.Build();
silo.StartAsync().Wait();
this.Silo = silo;

var clientConfig = ClientConfiguration.LocalhostSilo()
.AddSignalR();

clientConfig.FallbackSerializationProvider = typeof(ILBasedSerializer).GetTypeInfo();

var client = new ClientBuilder().UseConfiguration(clientConfig)
var client = new ClientBuilder()
.ConfigureCluster(options => options.ClusterId = "test-cluster")
.UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(siloAddress, gatewayPort).ToGatewayUri()))
.UseSignalR()
.Build();

client.Connect().Wait();
this.Client = client;
}

public void Dispose()
{
Client.Close().Wait();
Expand Down
10 changes: 5 additions & 5 deletions test/SignalR.Orleans.Tests/SignalR.Orleans.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.0.0-alpha2-final" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-alpha2-final" />
<PackageReference Include="Microsoft.AspNetCore.Sockets" Version="1.0.0-alpha2-final" />
<PackageReference Include="Microsoft.Orleans.Core" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansProviders" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="2.0.0-beta*" />
<PackageReference Include="Microsoft.Orleans.Core" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansProviders" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.0.0-rc1" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="2.0.0-rc1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 8902398

Please sign in to comment.