如何在Azure流分析中解压缩Gzip数据?

时间:2019-04-09 05:11:20

标签: azure stream compression gzip analytics

我们正在使用IOT集线器从启用IP的设备接收数据,随着数据的增长,我们希望在启用ip的设备中进行压缩并将其发送到iot集线器。我们正在使用Azure流分析来处理遥测消息。根据Microsoft documentation,我们可以使用Gzip流解压缩并获取数据。

在流分析中,我们使用了以下设置 事件压缩类型:Gzip enter image description here

我们正在尝试下面的代码进行压缩:

string fltext = File.ReadAllText("input_new.txt");
            var buffer = Encoding.UTF8.GetBytes(fltext);
            Console.WriteLine("Before Converting message:" + buffer.Length);
            MemoryStream ms = new MemoryStream();
            using (var zip = new GZipStream(ms, CompressionLevel.Optimal, true))
            {
                zip.Write(buffer, 0, buffer.Length);
            }
            ms.Position = 0;
            var compressed = new byte[ms.Length];
            ms.Read(compressed, 0, compressed.Length);

            var gzBuffer = new byte[compressed.Length];
            Buffer.BlockCopy(compressed, 0, gzBuffer, 0, compressed.Length);




            var fullyConverted =  Convert.ToBase64String(gzBuffer);

            Console.WriteLine("Before Converting message:" + gzBuffer.Length);

            var deviceClient = DeviceClient.CreateFromConnectionString(deviceSpecificConnection);

            var message = new Microsoft.Azure.Devices.Client.Message(gzBuffer);


            deviceClient.SendEventAsync(message);
            Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, gzBuffer.Length);
            Task.Delay(5000);

0 个答案:

没有答案