首页 文章

Azure文档Db工作者角色

提问于
浏览
0

我在获取Microsoft.Azure.Documents库以在azure worker角色中初始化客户端时遇到问题 . 我正在使用Nuget Package 0.9.1-preview .

我模仿了example for azure document所做的一切

通过模拟器在本地运行时,我可以与documentdb良好连接,并按预期运行 . 在worker角色中运行时,我得到一系列NullReferenceException,然后是ArgumentNullException .

enter image description here

上面突出显示的底部System.NullReferenceException具有此调用堆栈
enter image description here

所以nullReferenceExceptions在新的DocumentClient的这个调用中开始 .

var endpoint = "myendpoint";
var authKey = "myauthkey";
var enpointUri = new Uri(endpoint);
DocumentClient client = new DocumentClient(endpointUri, authKey);

在本地运行它与除了环境之外的工作者角色之间没有任何变化(显然) .

有没有人让DocumentDb处理工作角色,或者是否有人知道为什么会抛出空引用异常?传递到DocumentClient()的参数被填充 .

UPDATE: 我试图重写它更通用,这至少让工作者角色运行,让我附加一个调试器 . 它将错误抛给新的DocumentClient . 似乎某些安全传递是null . 初始化时所需的两个参数都不为空 . 是否有一个安全设置我需要更改我的worker角色才能连接到我的documentdb? (仍在当地工作正常)

UPDATE 2: 我可以让实例在发布模式下运行,但不能在调试模式下运行 . 所以它必须与某些安全设置或存储设置有关,我猜错误配置?

看来我正在使用System.Security.SecurityExceptions - 只有在使用DocumentDb时 - 队列不会给我这个错误 . 该错误的所有调用堆栈似乎都与System.Diagnostics.EventLog有关 . 我在Intellitrace Summary中看到的第一个Exception是System.Threading.WaitHandleCannotBeOpenedException .

More Info Intellitrace摘要异常数据:
enter image description here

enter image description here

top是最早的,bottom是最新的(所以System.Security.SecurityException首先发生,然后是NullReference)

2 回答

  • 3

    我摆脱安全异常和空引用异常的解决方案是禁用intellitrace . 一旦我这样做,我就能够部署和连接调试器并看到一切正常 .

    不确定intellitrace中的null和DocumentClient之间是什么,但希望它只是与nuget有关,它将在下一次迭代中修复 .

  • 4

    无法复制 .

    我创建了一个新的工作者角色 . 单个实例 . 添加了authkey和endoint配置到cscfg .

    在WorkerRole类级别创建私有静态DocumentClient

    OnStart中的Init DocumentClient在OnStop中处理DocumentClient

    在RunAsync内部循环中,按预期执行查询Works .

    在模拟器中测试工作 . 部署为发布到 生产环境 槽 . 作品 . 通过远程调试部署为调试到暂存 . 作品 . 附加VS到CloudService,断点内部循环 .

    工作方案:http://ryancrawcour.blob.core.windows.net/samples/AzureCloudService1.zip

相关问题