Skip to content

Commit 98fd921

Browse files
authored
Update signalr-howto-scale-multi-instances.md
1 parent 7877f1b commit 98fd921

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

articles/azure-signalr/signalr-howto-scale-multi-instances.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,15 @@ The following example overrides the default negotiate behavior and selects the e
9696
private class CustomRouter : EndpointRouterDecorator
9797
{ public override ServiceEndpoint GetNegotiateEndpoint(HttpContext context, IEnumerable<ServiceEndpoint> endpoints)
9898
{
99-
// Override the negotiate behavior to get the endpoint from query string
100-
var endpointName = context.Request.Query["endpoint"];
101-
if (endpointName.Count == 0)
102-
{
103-
context.Response.StatusCode = 400;
104-
var response = Encoding.UTF8.GetBytes("Invalid request");
105-
context.Response.Body.Write(response, 0, response.Length);
106-
return null;
107-
}
108-
109-
return endpoints.FirstOrDefault(s => s.Name == endpointName && s.Online) // Get the endpoint with name matching the incoming request
99+
// Sample code showing how to choose endpoints based on the incoming request endpoint query
100+
var endpointName = context.Request.Query["endpoint"];
101+
if (endpointName.Count == 0)
102+
{
103+
throw new BadHttpRequestException("Invalid request.", 400);
104+
}
105+
106+
// Select from the available endpoints, don't construct a new ServiceEndpoint object here
107+
return endpoints.FirstOrDefault(s => s.Name == endpointName && s.Online) // Get the endpoint with name matching the incoming request
110108
?? base.GetNegotiateEndpoint(context, endpoints); // Or fallback to the default behavior to randomly select one from primary endpoints, or fallback to secondary when no primary ones are online
111109
}
112110
}

0 commit comments

Comments
 (0)