Read BrokeredMessage body multiple time

我只是一个虾纸丫 提交于 2019-12-13 05:13:05

问题


I know that error message is self-explanatory, we can't read message body multiple times. here I'm using AOP (Aspect Oriented Programming) for audit log.

[AuditServiceMethod(AttributePriority = 0)]
[FunctionName("ValidateSubscriber")]
    public static async Task RunAsync([ServiceBusTrigger("validate-message", AccessRights.Manage,
        Connection = "ServiceBusConnection")]BrokeredMessage message,
        TraceWriter log,
        [Inject(typeof(ICommonUtilities))] ICommonUtilities commonUtility)
    {
        string body;
        using (var stream = message.GetBody<Stream>())
        using (var streamReader = new StreamReader(stream, Encoding.UTF8))
        {
            body = await streamReader.ReadToEndAsync();
        }
}

[AuditServiceMethod] is my aspect for audit request, response and error log. Is there any good workaround to get body multiple time in Azure function??


回答1:


You need to clone BrokeredMessage and use the clone rather than the original message.



来源:https://stackoverflow.com/questions/50869208/read-brokeredmessage-body-multiple-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!