gpt4 book ai didi

azure - 为什么在发送之前不能调用EventData.GetBytes()?

转载 作者:行者123 更新时间:2023-12-02 06:34:26 25 4
gpt4 key购买 nike

我正在使用 Azure 事件中心,最初在发送数据以尝试计算批量大小时,我有类似于下面的代码,该代码将调用 EventDataGetBytes

EventHubClient client;//initialized before the relevant code

EventData curr = new EventData(data);
//Setting a partition key, and other operations.
long itemLength = curr.GetBytes().LongLength;
client.SendAsync(curr);

不幸的是,我在 SDK 代码中收到了异常。

The message body cannot be read multiple times. To reuse it store the value after reading.

虽然删除对 GetBytes 的最终不必要的调用意味着我可以发送消息,但发生此异常的理由相当令人费解。连续调用 GetBytes() 两次是重现相同异常的简单方法,但单次调用将意味着 EventData 无法成功发送。

看起来很可能在下面使用了 Message,并且如果作为 Message.GetBody 文档多次调用,则设置为抛出异常;但是,EventData 的方法 GetBodyStreamGetBody w/serializerGetBodyGetBytes 中没有这方面的文档。

我想这应该被记录下来,或者被纠正,因为目前它在一个单独的线程中是一个令人不快的惊喜。

最佳答案

您是否尝试过使用 EventData.SerializedSizeInBytes 来获取大小?这是获取批处理计算大小的更准确方法。

关于azure - 为什么在发送之前不能调用EventData.GetBytes()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27241679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com