Azure IoTHub ExportDevicesAsync引发内部服务器错误

编程入门 行业动态 更新时间:2024-10-28 10:36:22
本文介绍了Azure IoTHub ExportDevicesAsync引发内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究一种解决方案,其中我希望将所有设备从IoTHub导出到BLOB.

I'm working on a solution in which I want to export all the devices from an IoTHub to a BLOB.

Microsoft为此提供了一个API,并说明了如何执行此操作此处.

Microsoft has an API for this and explains how to do this here.

我已经为10台设备执行了此代码,并且可以正常工作,Azure需要花费几秒钟的时间来处理它,否则,它就可以正常工作.

I've executed this code for 10 devices and it works fine, it takes a few seconds for Azure to process this but otherwise it works just fine.

但是我在S1平台上使用了10多个设备(目前正在测试100个设备),这应该支持数量不确定的设备

However I'm working with more than 10 devices (currently testing with 100 devices) on a S1 platform, which should support an undetermined amount of devices

这是我使用的代码.

Program.cs

private static void Main(string[] args) { IoTExporter.ExportIoTDevices(); }

IoTExporter

public class IoTExporter { private const string Containername = "iot"; public static void ExportIoTDevices() { // Create a blobclient which is used to connect to the blob storage. var blobClient = CreateBlobClient(); //Get a reference to a container to use for the sample code, and create it if it does not exist. var container = blobClient.GetContainerReference(Containername); container.CreateIfNotExists(); //Generate a SAS token and assign it to the current job. var storageUri = GetContainerSasUri(container); CreateJob(storageUri); Console.ReadLine(); } /// <summary> /// Create a blobclient which is used to connect to the blob storage. /// </summary> /// <returns>A Blob client.</returns> private static CloudBlobClient CreateBlobClient() { var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("BlobConnString")); return storageAccount.CreateCloudBlobClient(); } private static string GetContainerSasUri(CloudBlobContainer container) { ConsoleWriter.WriteLine("Generating Uri"); // Set constraints on the SAS token. var sasConstraints = new SharedAccessBlobPolicy { SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10), Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Delete }; var sasContainerToken = container.GetSharedAccessSignature(sasConstraints); //Return the URI string for the container, including the SAS token. return container.Uri + sasContainerToken; } private static async void CreateJob(string storageUri) { ConsoleWriter.WriteLine("Creating Job"); var manager = RegistryManager.CreateFromConnectionString(ConfigurationManager.AppSettings["IoT:ConnectionString"]); await TestConnection(manager); ConsoleWriter.WriteLine("Initiating Job"); var job = await manager.ExportDevicesAsync(storageUri, "devices.txt", false); await DoJob(job, manager); } private static async Task TestConnection(RegistryManager manager) { ConsoleWriter.WriteLine("Testing if connected to IoTHub"); var devices = await manager.GetDevicesAsync(1); if (!devices.Any()) { Environment.Exit(-1); } else { ConsoleWriter.WriteLine("IoT connected"); } } private static async Task DoJob(JobProperties job, RegistryManager manager) { while (true) { job = await manager.GetJobAsync(job.JobId); switch (job.Status) { case JobStatus.Completed: FileWriter.WriteBlobToFile(GetContainer()); ConsoleWriter.WriteLine($"Job {job.Status}"); break; case JobStatus.Failed: ConsoleWriter.WriteLine($"Job failed due to {job.FailureReason}"); break; case JobStatus.Cancelled: ConsoleWriter.WriteLine($"Job {job.Status}"); break; default: ConsoleWriter.WriteLine($"Status of job: {job.Status}"); await Task.Delay(TimeSpan.FromSeconds(5)); continue; } break; } } private static CloudBlobContainer GetContainer() { var blobClient = CreateBlobClient(); // Retrieve a reference to a container and give it blob permissions. var container = blobClient.GetContainerReference(Containername); return container; }}}

ConsoleWriter

public static class ConsoleWriter { public static void WriteLine(string line) { var date = DateTime.Now; var toWrite = $"{date} : {line}"; Console.WriteLine(toWrite); } }

我的代码是问题所在,还是罐中还有其他东西正在酝酿?

Is my code the problem, or is there something else brewing in the pot?

推荐答案

事实证明,我正在使用的服务器(西欧)出现故障.我在北欧进行了测试,现在可以使用了.

It turns out that the server upon which I was working (West-Europe) had a malfunction. I tested it on North Europe and now it works.

更多推荐

Azure IoTHub ExportDevicesAsync引发内部服务器错误

本文发布于:2023-10-24 23:49:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   服务器   Azure   IoTHub   ExportDevicesAsync

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!