让Hangfire使用MongoDB存储

问题描述 投票:0回答:1

我试图让Hanfire使用Hangfire.Mongo NuGet包来使用MongoDB存储。

我在Configure()做了最小的必要:

app.UseHangfireServer();

这在ConfigureServices()

services.AddHangfire(
    config => config.UseMongoStorage("mongodb://myhost:27017"),
    "MyDatabase");

我已验证数据库是否存在且上述连接字符串是否正确。

我得到这个例外:

无法清除资源“迁移”上的锁定。 System.TimeoutException:在30000ms选择使用的服务器后发生超时

CompositeServerSelector {Selectors = MongoDB.Driver.MongoClient + AreSessionsSupportedServerSelector,LatencyLimitingServerSelector {AllowedLatencyRange = 00:00:00.0150000}}。集群状态的客户端视图是{ClusterId:“1”,ConnectionMode:“Automatic”,类型:“Unknown”,状态:“Disconnected”,服务器:[{ServerId:“{ClusterId:1,EndPoint:”Unspecified / myhost: 27017“}”,EndPoint:“Unspecified / myhost:27017”,状态:“Disconnected”,类型:“Unknown”,HeartbeatException:“MongoDB.Driver.MongoConnectionException:

打开与服务器的连接时发生异常。 ---> System.Net.Sockets.SocketException:System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)中没有这样的主机...在Hangfire.Mongo.DistributedLock.MongoDistributedLock.Cleanup()[Hangfire.Mongo.DistributedLock .MongoDistributedLock]

大胆的部分让我相信某些信息没有设置或在某处丢失,但我没有做任何与众不同的事情。我检查了防火墙问题,并尝试了这个answer中的许多想法给别人的类似问题。

我也尝试将连接字符串更改为所有这些

  • MongoDB中://为myhost:27017 / MyDatabase的
  • mongodb的://为myhost:27017 /连接= replicaSet
  • mongodb的://为myhost:27017 / MyDatabase的/连接= replicaSet
c# mongodb mongodb-.net-driver hangfire asp.net-core-2.2
1个回答
0
投票

我没有在我的问题中添加的是我的应用程序是容器化的,就像我的机器上的MongoDB一样。

我在Visual Studio中的容器上下文之外的调试中运行应用程序。这意味着它无法看到容器网络,因此无法连接。

© www.soinside.com 2019 - 2024. All rights reserved.