【问题标题】:Getting Hangfire to use MongoDB Storage让 Hangfire 使用 MongoDB 存储
【发布时间】:2019-03-10 17:28:33
【问题描述】:

我正在尝试使用 Hangfire.Mongo NuGet 包让 Hanfire 使用 MongoDB 存储。

我正在做Configure() 中必要的最低限度的工作:

app.UseHangfireServer();

这个在ConfigureServices():

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

我已经验证数据库存在并且上面的连接字符串是正确的。

我得到了这个例外:

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

CompositeServerSelector{ 选择器 = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }。集群状态的客户端视图是 { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified /myhost:27017" }",端点:“未指定/myhost:27017”,状态:“断开连接”,类型:“未知”,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/?connect=replicaSet
  • mongodb://myhost:27017/MyDatabase/?connect=replicaSet

【问题讨论】:

    标签: c# mongodb mongodb-.net-driver hangfire asp.net-core-2.2


    【解决方案1】:

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

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

    【讨论】:

    • 您解决了这个问题吗?当我的应用程序部署到 kubernetes 时,我得到了同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 2012-04-26
    • 1970-01-01
    相关资源
    最近更新 更多