压缩消息未显示在 eventhub 中

发布于 2025-01-16 06:14:22 字数 478 浏览 2 评论 0原文

我正在使用 GZIP 压缩器来压缩消息,并尝试将数据从控制台应用程序推送到 eventhub。当我将消息推送到 eventhub 时,它不会抛出任何异常,同时数据也不会显示。这是我编写的代码,用于在压缩后将数据推送到 eventhub

var eventHubClient = EventHubClient.CreateFromConnectionString("");
                var eventData = new EventData(System.Text.Encoding.UTF8.GetBytes(result.Result.Value));
                eventData.Properties.Add("Compression","GZip");
                eventHubClient.SendAsync(eventData);
                eventHubClient.Close();

I am using GZIP compressor to compress the messages and trying to push the data in to eventhub from my console application. When I push the messages to eventhub it is not throwing any exceptions and at the same time, the data is not showing up. This is the code I wrote to push the data in to eventhub after compressing

var eventHubClient = EventHubClient.CreateFromConnectionString("");
                var eventData = new EventData(System.Text.Encoding.UTF8.GetBytes(result.Result.Value));
                eventData.Properties.Add("Compression","GZip");
                eventHubClient.SendAsync(eventData);
                eventHubClient.Close();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2025-01-23 06:14:22

困难与压缩消息正文无关。在调用 Close 之前,您无需等待 SendAsync 调用完成。这实际上取消了发送,因为您已经关闭了它正在使用的网络连接。

为了确保发送在关闭之前完成,您需要将代码调整为类似以下内容:

var eventHubClient = EventHubClient.CreateFromConnectionString("<< CONNECTION STRING >>");

var eventData = new EventData(System.Text.Encoding.UTF8.GetBytes(result.Result.Value));
eventData.Properties.Add("Compression","GZip");

await eventHubClient.SendAsync(eventData);
eventHubClient.Close();

为了获得更好的性能,我还建议您考虑创建一次 EventHubClient 并将其视为在您的应用程序的整个生命周期中都是单例的。

The difficulties are not related to compressing the message body. You're not awaiting the completion of the SendAsync call before calling Close. This effectively cancels the send because you've closed the network connection that it was using.

To ensure the send is complete before closing, you'll need to adjust your code to something similar to:

var eventHubClient = EventHubClient.CreateFromConnectionString("<< CONNECTION STRING >>");

var eventData = new EventData(System.Text.Encoding.UTF8.GetBytes(result.Result.Value));
eventData.Properties.Add("Compression","GZip");

await eventHubClient.SendAsync(eventData);
eventHubClient.Close();

For better performance, I'd also suggest that you consider creating the EventHubClient once and treating it as a singletone for the lifetime of your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文