Skip to content

Commit

Permalink
Add service scaleout with Redis Backplane (#9)
Browse files Browse the repository at this point in the history
* Add service scaleout with Redis Backplane
* Add small docs about scale with Redis
  • Loading branch information
AMEST authored Jun 4, 2021
1 parent d64dcc0 commit c5afdd8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The service is adjusted based on the mesh model. This network is implemented to
3. Screen sharing (with microphone)
4. Pseudo fullscreen and half screen mode for prticipants blocks
5. Gravatar user avatars
6. Service Scaleout with Redis

### Security
High level of security: all connections are protected and encrypted according to the DTLS and SRTP protocols. At the same time, WebRTC works only over the HTTPS protocol, and the site using the technology must be signed with a certificate.
Expand All @@ -52,5 +53,7 @@ Web sockets for signaling also go only via https.
* AspNet Core 3.1 runtime or Docker for service start
* Reverse proxy for https connection (may be use Cloudflare)

**For scalae service, needed redis server (version >=6 ) with acl user who can create/pub/sub channels with prefix `peermeeting`**

## Getting started
[**Instructions for launching the application are here**](docs/README.md)
17 changes: 17 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@

- [PeerMeeting documentation](#peermeeting-documentation)
- [Getting started](#getting-started)
- [Configuration](#configuration)
- [Configure container](#configure-container)
- [Configure not in container](#configure-not-in-container)
- [Docker compose](#docker-compose)
- [Docker Swarm](#docker-swarm)

## Getting started
For the application to work, several conditions must be met:
1. If the application will be launched locally, then aspnetcore 3.1 runtime must be installed
2. There must be a reverse proxy to establish an https connection
3. If you hav to scale service, you need Redis (*version >=6 with acl user who can create/pub/sub channels with prefix `peermeeting`*)

Next, you need to choose a launch method. It is possible to launch the application:
1. Run the executable file locally
2. Run in docker
1. Using docker compose
2. Using docker swarm


### Configuration

#### Configure container
For configuring you need add environment variable.
Available configurations:
1. `Serilog:MinimumLevel:Default` - configuring logger minimum level
2. `Redis:Enabled` - enable/disable (default false) redis connection. Need for scale service
3. `Redis:ConnectionString` - connection string to redis. (example: `localhost,user=serviceuser,password=VeryHardPass,channelPrefix=peermeeting`)

#### Configure not in container
To configure configurations, you need to make changes to `appsettings.Production.json`. The list of settings is identical to that described in the "Configure container" block.

### Docker compose

For an example of launching via docker compose, a [compose file](compose.yml) has been prepared with a description of starting the service and nginx with a self-signed certificate for quick launch **(For test use only)**.
Expand Down
14 changes: 14 additions & 0 deletions src/PeerMeeting.Host/Configuration/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Extensions.Configuration;

namespace PeerMeeting.Host.Configuration
{
public static class ConfigurationExtensions
{
public static RedisConfiguration GetRedisConfiguration(this IConfiguration configuration)
{
var redisConfiguration = new RedisConfiguration();
configuration.GetSection("Redis").Bind(redisConfiguration);
return redisConfiguration;
}
}
}
18 changes: 18 additions & 0 deletions src/PeerMeeting.Host/Configuration/RedisConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace PeerMeeting.Host.Configuration
{
/// <summary>
/// Redis backplane and distributed cache configuration
/// </summary>
public class RedisConfiguration
{
/// <summary>
/// Is Redis backplane and distributed cache enabled
/// </summary>
public bool Enabled { get; set; } = false;

/// <summary>
/// Redis connection string
/// </summary>
public string ConnectionString { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/PeerMeeting.Host/PeerMeeting.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
<Version>0-develop</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SpaRoot>ClientApp\</SpaRoot>
<UserSecretsId>d5d11dc6-d93d-4008-8343-e3aec50b859b</UserSecretsId>
</PropertyGroup>

<!--Dev only-->
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="3.1.15" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="StackExchange.Redis" Version="2.2.4" />
<PackageReference Include="VueCliMiddleware" Version="3.1.1" />
</ItemGroup>

Expand Down
17 changes: 13 additions & 4 deletions src/PeerMeeting.Host/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Copyright 2021 klabukov.
// SPDX-License-Identifier: GPL-3.0-only

using System;
using System.Net;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.AspNetCore.SpaServices;
using PeerMeeting.Host.Configuration;
using PeerMeeting.Host.Hubs;
using StackExchange.Redis;
using VueCliMiddleware;

namespace PeerMeeting.Host
Expand All @@ -22,16 +26,19 @@ public Startup(IConfiguration configuration)

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddMvc();
services.AddSignalR(o =>
var redisConfiguration = Configuration.GetRedisConfiguration();
var signalRBuilder = services.AddSignalR(o =>
{
o.EnableDetailedErrors = true;
o.MaximumReceiveMessageSize = 256 * 1024; //256 KB
});
if (redisConfiguration.Enabled && !string.IsNullOrEmpty(redisConfiguration.ConnectionString))
signalRBuilder.AddStackExchangeRedis(redisConfiguration.ConnectionString);

services.AddControllers();
services.AddMvc();
services.AddSpaStaticFiles(c => c.RootPath = "ClientApp/dist");
services.AddSingleton<WebRtcHub>();
services.AddResponseCompression(options =>
Expand All @@ -42,6 +49,8 @@ public void ConfigureServices(IServiceCollection services)
});
}

// This method gets called by the runtime. Use this method to add services to the container.

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Expand Down
6 changes: 5 additions & 1 deletion src/PeerMeeting.Host/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
}
]
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Redis": {
"Enabled": false,
"ConnectionString": ""
}
}

0 comments on commit c5afdd8

Please sign in to comment.