问题
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