使用单个应用程序实例(容器)运行网站时 - SignalR工作正常.
当扩展到更多实例(> 1)时,它会抛出错误而无法正常工作.我在互联网上寻找解释,发现我需要将Signalr配置为在群集中工作.我选择Redis作为我的背板.
我已经完成了许多关于如何正确完成它的教程并且它不适合我.
我在Google云端托管了asp.net core v2.1.使用Kestrel + nginx将应用程序部署为Docker容器.docker容器在负载均衡器后面的Kubernetes集群中运行.
Startup.cs:
public class Startup
{
public Startup(IConfiguration configuration,
IHostingEnvironment hostingEnvironment)
{
Configuration = configuration;
HostingEnvironment = hostingEnvironment;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddSignalR().AddRedis(options =>
{
options.Configuration = new ConfigurationOptions
{
EndPoints =
{
{ ConfigurationManager.Configuration["settings:signalR:redis:host"], int.Parse(ConfigurationManager.Configuration["settings:signalR:redis:port"])}
},
KeepAlive = 180,
DefaultVersion = new Version(2, …Run Code Online (Sandbox Code Playgroud) 我正在尝试让我的 asp.net 核心应用程序使用 ASPNETCORE_URLS 来设置启动 URL。它没有按预期工作。
我已经尝试了我在网上找到的所有东西,但我一直被卡住。该应用程序在没有环境变量的情况下工作,并在 docker 容器中正常运行。但是在启用环境变量时不起作用。
期望结果:0.0.0.0:5000 结果:本地主机:5000
启动:
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json")
.AddEnvironmentVariables()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
dockerfile 中的环境变量:
ENV ASPNETCORE_URLS=http://+:5000
Run Code Online (Sandbox Code Playgroud)
码头工人文件:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses
this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Platform/Platform.API/Platform.API.csproj", "Platform.API/"]
COPY ["Platform/Platform.Domain/Platform.Domain.csproj", "Platform.Domain/"]
COPY ["Platform/Platform.DataAccess/Platform.DataAccess.csproj", "Platform.DataAccess/"]
RUN dotnet restore "Platform.API/Platform.API.csproj"
COPY …Run Code Online (Sandbox Code Playgroud) 我确信这个问题有一个简单的解决方案,但我似乎无法做到正确:
我只想在整行与正则表达式匹配时替换一行中的特定模式.
所以在我的情况下|,_只有当整行是数字和管道时,三个管道才应该用下划线代替:
|||10|||-80|||-120|||400 ---> replace
|||10|||asdf|||-120|||400 ---> don't replace
|||10|||-80|||400 ---> replace
|||10|||-80|||-120|||400|||test ---> don't replace
Run Code Online (Sandbox Code Playgroud)
预期结果:
___10___-80___-120___400
|||10|||asdf|||-120|||400
___10___-80___400
|||10|||-80|||-120|||400|||test
Run Code Online (Sandbox Code Playgroud)
我的尝试:
\|\|\|(?=\-?\d+)
Run Code Online (Sandbox Code Playgroud)
如果按照预期后跟数字,则替换管道,但当然也在"无效"行中
^(\|\|\|\-?\d+){1,}$
Run Code Online (Sandbox Code Playgroud)
匹配整行,因此我不能只更换管道
我理解为什么我的模式不起作用,也许我只需要两次通过,但感觉这应该是完全可能的.
似乎debounceTime忽略了对它的主题next方法的内部调用:
var subject: Subject<number> = new Subject<number>();
subject.pipe(
tap((a) => console.log("tab:" + a)),
debounceTime(300),
).subscribe((a) => {
console.log(a);
subject.next(100)
});
subject.next(19);
subject.next(20);
Run Code Online (Sandbox Code Playgroud)
上面的代码应该创建一个无限循环 - 但它不会:
tab:19
tab:20
20
tab:100
Run Code Online (Sandbox Code Playgroud)
如果我将 a 添加delay(1)到管道中,它会按预期工作:
subject.pipe(
tap((a) => console.log("tab:" + a)),
debounceTime(300),
delay(1)
).subscribe((a) => {
console.log(a);
subject.next(100)
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
编辑:添加了一个例子:https : //typescript-fbt2mn.stackblitz.io