简体   繁体   English

Azure Document Db Worker角色

[英]Azure Document Db Worker Role

I am having problems getting the Microsoft.Azure.Documents library to initialize the client in an azure worker role. 我在获取Microsoft.Azure.Documents库以azure worker角色初始化客户端时遇到问题。 I'm using Nuget Package 0.9.1-preview. 我正在使用Nuget Package 0.9.1-preview。

I have mimicked what was done in the example for azure document 我模仿了天蓝色文档示例中的操作

When running locally through the emulator I can connect fine with the documentdb and it runs as expected. 通过模拟器在本地运行时,我可以与documentdb连接良好,并且可以按预期运行。 When running in the worker role, I am getting a series of NullReferenceException and then ArgumentNullException. 当以worker角色运行时,我得到了一系列NullReferenceException,然后是ArgumentNullException。

在此处输入图片说明

The bottom System.NullReferenceException that is highlighted above has this call stack 上面突出显示的底部System.NullReferenceException具有此调用堆栈 在此处输入图片说明

so the nullReferenceExceptions start in this call at the new DocumentClient. 因此nullReferenceExceptions将从此调用中的新DocumentClient开始。

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

Nothing changes between running it locally vs on the worker role other then the environment (obviously). 在本地运行它与在工作角色上运行(除了环境之外)之间没有任何变化(很明显)。

Has anyone gotten DocumentDb to work on a worker role or does anyone have an idea why it would be throwing null reference exceptions? 有没有人得到DocumentDb来充当工作者角色,还是有人知道为什么它会引发空引用异常? The parameters getting passed into the DocumentClient() are filled. 传递给DocumentClient()的参数将被填充。

UPDATE: I tried to rewrite it being more generic which helped at least let the worker role run and let me attached a debugger. 更新:我试图将其改写为更通用的名称,这至少有助于让worker角色运行并让我附加了调试器。 It is throwing the error on the new DocumentClient. 它在新的DocumentClient上引发错误。 Seems like some security passing is null. 似乎某些安全传递为空。 Both the required parameters on initialization are not null. 初始化时两个必需的参数都不为空。 Is there a security setting I need to change for my worker role to be able to connect to my documentdb? 我是否需要更改安全设置才能使工作角色能够连接到documentdb? (still works locally fine) (仍然可以在本地正常工作)

UPDATE 2: I can get the instance to run in release mode, but not debug mode. 更新2:我可以让实例在发布模式下运行,但不能在调试模式下运行。 So it must be something to do with some security setting or storage setting that is misconfigured I guess? 因此,这一定与某些安全性设置或存储设置配置错误有关。

It seems I'm getting System.Security.SecurityExceptions - only when using The DocumentDb - queues do not give me that error. 看来我正在得到System.Security.SecurityExceptions-仅在使用The DocumentDb时-队列不会给我该错误。 All Call Stacks for that error seem to be with System.Diagnostics.EventLog. 该错误的所有调用堆栈似乎都与System.Diagnostics.EventLog有关。 The very first Exception I see in the Intellitrace Summary is System.Threading.WaitHandleCannotBeOpenedException. 我在Intellitrace摘要中看到的第一个异常是System.Threading.WaitHandleCannotBeOpenedException。

More Info Intellitrace summary exception data: 更多信息 Intellitrace摘要异常数据: 在此处输入图片说明在此处输入图片说明

top is the earliest and bottom is the latest (so System.Security.SecurityException happens first then the NullReference) 顶部是最早的,底部是最新的(因此,首先发生System.Security.SecurityException,然后是NullReference)

The solution for me to get rid of the security exception and null reference exception was to disable intellitrace. 我摆脱安全异常和空引用异常的解决方案是禁用intellitrace。 Once I did that, I was able to deploy and attach debugger and see everything working. 完成此操作后,我便能够部署并附加调试器,并看到一切正常。

Not sure what is between the null in intellitrace and the DocumentClient, but hopefully it's just in relation to the nuget and it will be fixed in the next iteration. 不确定intellitrace中的null和DocumentClient之间是什么,但希望它只是与nuget有关,它将在下一次迭代中修复。

unable to repro. 无法复制。

I created a new Worker Role. 我创建了一个新的工作者角色。 Single instance. 单实例。 Added authkey & endoint config to cscfg. 已将authkey和endint配置添加到cscfg。

Created private static DocumentClient at WorkerRole class level 在WorkerRole类级别创建了私有静态DocumentClient

Init DocumentClient in OnStart Dispose DocumentClient in OnStop 在OnStart中初始化DocumentClient在OnStop中处置DocumentClient

In RunAsync inside loop, execute a query Works as expected. 在RunAsync内部循环中,执行查询按预期运行。

Test in emulator works. 在仿真器中进行测试。 Deployed as Release to Production slot. 部署为生产版插槽。 works. 作品。 Deployed as Debug to Staging with Remote Debug. 作为调试部署到通过远程调试登台。 works. 作品。 Attached VS to CloudService, breakpoint hit inside loop. 将VS附加到CloudService,断点在循环内。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM