【问题标题】:Using SqlBotDataStore for bot state falls back instead to state.botframework.com将 SqlBotDataStore 用于机器人状态回退到 state.botframework.com
【发布时间】:2018-06-21 23:37:44
【问题描述】:

我正在使用 Nuget Microsoft.Bot.Builder.Azure 包扩展来存储我的机器人的状态。 BotBuilder 3.14.0、Bot.Builder.Azure 3.2.5。

到目前为止,我一直在使用 Azure 表存储成功使用 TableBotDataStore。在开始对话时,我可以立即检查表格并查看其中创建的相关行。

我尝试使用 SqlBotDataStore,运行脚本在我的 (Azure) SQL Server DB 中创建表。我按照sample code 注册了它,但在重新部署时我发现,虽然没有抛出错误,但在 SqlBotDataEntities 表中没有创建任何条目,而是将 state.botframework.com 作为请求依赖项的一部分调用。

var sqlStore = new SqlBotDataStore(ConfigurationManager.
    ConnectionStrings["SqlBotStorage"].ConnectionString);

builder.Register(c => sqlStore)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

已取代(工作)

var azureTableStore = new TableBotDataStore( 
    ConfigurationManager.ConnectionStrings["TableStorageCS"].ConnectionString,
    sBotStorageTableName);

builder.Register(c => azureTableStore)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

builder.Register(c => new CachingBotDataStore(azureTableStore,
                    CachingBotDataStoreConsistencyPolicy
                    .ETagBasedConsistency))
                    .As<IBotDataStore<BotData>>()
                    .AsSelf()
                    .InstancePerLifetimeScope();

我知道连接字符串是 kosher,因为我尝试了一个虚拟操作方法的测试:

IBotDataStore<BotData> sqlds = new SqlBotDataStore( 
    ConfigurationManager.ConnectionStrings["SqlBotStorage"].ConnectionString);

var key = new Address("botidhere", "effbee", "uid1", "c1", "x.com");
var bd = new BotData(data: new Dialogs.SimpleResponseDialog("message here"));
await sqlds.SaveAsync(key, BotStoreType.BotUserData, bd, default(CancellationToken));

添加一行就好了。

我还缺少什么?相关连接字符串存储在 Azure 应用程序设置中,作为“SQLAzure”类型的连接字符串:

Server=tcp:xxxx.database.windows.net;Initial Catalog=xxxx;Persist Security Info=False;User ID=xxxx;Password=xxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

【问题讨论】:

  • 不是存储账户,是数据库连接字符串。这是正确的,正如我上面所说,我尝试显式创建 SqlBotDataStore 的实例,并且它正确写入数据库。
  • 您是否尝试过在 SqlBotDataStore 实现中包含 CachingBotDataStore 注册?我认为 AzureModule 是必需的,如果您不使用 CachingBotDataStore(正如您在下面的回答中所述)
  • 我没有费心在 Eric 上添加 CachingBotDataStore,因为在示例代码 sn-ps 中似乎不需要它,而且我当前的 bot 使用量并不大,以至于不能保证任何还担心缓存机制——而且,最重要的是,我仍然担心 CachingBotDataStore 在 3.15 死亡问题中可能扮演的角色:github.com/Microsoft/BotBuilder/issues/4477
  • 顺便说一句,感谢您的澄清。使用 CachingBotDataStore 意味着您不需要注册 AzureModule。这将是在文档中突出显示的一个方便的方法。
  • (死亡问题 + 1) ...我想它终于解决了

标签: c# azure azure-sql-database botframework azure-bot-service


【解决方案1】:

我似乎*已修复它 - 我缺少 AzureModule 注册行:

builder.RegisterModule(new AzureModule(System.Reflection.Assembly.GetExecutingAssembly()));

这就是问题所在 - 这不是使用 TableBotDataStore 所必需的。只有 SqlBotDataStore。

另一件事:在带有调试版本 system.debug=true 的 Azure 部署槽中添加该行立即修复了该问题。但是,使用发布版本 system.debug=false 部署到主 web 应用程序(非插槽)会导致应用程序无法启动。 '503服务不可用'。没有日志。立即恢复到表存储,一切都恢复正常。

我目前正在尝试..捕捉上面的行,但我看不到抛出异常,但它现在已经开始工作了。值得关注!

*上面有一些警告......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-31
    • 2022-01-07
    • 2022-11-11
    • 1970-01-01
    • 2021-01-14
    • 2019-05-26
    • 1970-01-01
    • 2020-11-06
    相关资源
    最近更新 更多