Azure Functions bindings for SignalR Service. Project moved to https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/signalr/Microsoft.Azure.WebJobs.Extensions.SignalRService .
MIT License
97
stars
46
forks
source link
localhost signalr service works but not for individual users #259
signalr message is not getting passed to individual users if we use local signalr service emulator
I have given connection string like below,
"AzureSignalRConnectionString": "Endpoint=http://localhost;Port=8888;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH;Version=1.0;"
using command prompt, I have started asrs emulator like below
=> asrs-emulator start
Steps to reproduce:
Install signalr service emulator using below command, => dotnet tool install --global Microsoft.Azure.SignalR.Emulator --version 1.0.0-preview1-10767
Configure signalr service connectionstring like below "AzureSignalRConnectionString": "Endpoint=http://localhost;Port=8888;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH;Version=1.0;"
configure below method in azure function, [FunctionName("negotiate")] public static SignalRConnectionInfo Negotiate( [HttpTrigger(AuthorizationLevel.Anonymous, "post", "get")] HttpRequest req, [SignalRConnectionInfo(HubName = "notifications")] SignalRConnectionInfo connectionInfo, IBinder binder) { string userId = req.Headers["x-ms-signalr-userid"].ToString();
SignalRConnectionInfoAttribute attribute = new SignalRConnectionInfoAttribute { HubName = "notifications", UserId = userId };
connectionInfo = binder.Bind(attribute);
return connectionInfo; }
[FunctionName("broadcast")] public static Task Broadcast( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [SignalR(HubName = "notifications")] IAsyncCollector signalRMessages)
{
var userId = req.Headers["x-ms-signalr-userid"].ToString();
return signalRMessages.AddAsync( new SignalRMessage { UserId = userId, Target = "newMessage", Arguments = new[] { "Notification from SignalR" } }); }
[FunctionName("broadcastall")] public static Task BroadcastAll( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [SignalR(HubName = "notifications")] IAsyncCollector signalRMessages)
{
return signalRMessages.AddAsync(
new SignalRMessage
{
Target = "newMessage",
Arguments = new[] { "Notification from SignalR" }
});
}
try to execute azure function using Postman like below
Expected result: broadcast should work for individual users
Actual result: broadcast is not working for individual users. broadcastall method is working for all users.
Note: If we use below connection string in azure function , it is working fine. I can able to get signalr message for individual users.
"AzureSignalRConnectionString": "Endpoint=https://signalrservice.service.signalr.net;AccessKey=;Version=1.0;"
I have problem with local signalr service emulator.