我们有类似于以下代码的代码,该代码通过signalR将消息发送给userId:
[FunctionName("broadcast")]
public static async Task SendMessageAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "broadcast/{group}/{userId}")]
HttpRequestMessage req,
string group,
string userId,
[SignalR(HubName = Negotitate.HubName)]IAsyncCollector<SignalRMessage> signalRMessages,
ILogger logger)
{
string message = await req.UnzipAsync(); //This is an in-house library to unzip a request.
await signalRMessages.AddAsync(
new SignalRMessage
{
UserId = userId,
GroupName = group,
Target = "finished",
Arguments = new[] { JsonConvert.DeserializeObject(message) } //deserialize the payload using Newtonsoft
});
}
Azure上托管的无服务器SignalR是自由/开发层实体。基本上,该代码的作用是从请求中获取压缩内容(json有效负载),然后将其解压缩,然后让SDK将反序列化的对象发送给组中的用户。当有效载荷产生小的物体时,此功能效果很好。当SDK尝试将有效负载约为2.3 MB的对象提交给Azure SignalR时,它将报告以下失败:
{“响应状态代码不表示成功:413(请求实体 太大)。“}
This documentation by Microsoft建议Azure SignalR服务对邮件大小没有限制,并且SDK负责拆分邮件:
Azure SignalR服务对消息没有大小限制。
大邮件被分成不超过2个的小邮件 每个KB,分别传输。 SDK处理消息拆分和 组装。无需开发人员的努力。
因此,Azure signalR服务中可能有什么错误导致此问题发生。有关该异常的更多信息:
Microsoft.Azure.SignalR.Management.RestHubLifetimeManager.ThrowExceptionOnResponseFailure(Exception innerException,可为空
1 statusCode, String requestUri, String detail) at Microsoft.Azure.SignalR.Management.RestHubLifetimeManager.<CallRestApiAsync>d__23.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.<SendToUser>d__13.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector
1.d__3.MoveNext() 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task 任务) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务),位于System.Runtime.CompilerServices.TaskAwaiter.GetResult()