在使用客户端UI连接生成器协商azure函数中的连接后,如何在azure函数中存在从azure signalR向特定用户发送数据的方法。在azure函数目标中存在。在UI中使用javascript的用户ID的任何完整解决方案用户ID如何可以传递给Azure Function并使用SignalR将数据发送给特定用户
谈判
[FunctionName("negotiate")]
public static SignalRConnectionInfo GetOrderNotificationsSignalRInfo(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
[SignalRConnectionInfo(HubName = "notifications")] SignalRConnectionInfo connectionInfo)
{
return connectionInfo;
}
SignalR代码
[FunctionName("PlacedOrderNotification")]
public static async Task Run(
[QueueTrigger("new-order-notifications")] OrderPlacement orderPlacement,
[SignalR(HubName = "notifications")] IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log)
{
log.LogInformation($"Sending notification for {orderPlacement.CustomerName}");
await signalRMessages.AddAsync(
new SignalRMessage
{
Target = "productOrdered",
Arguments = new[] { orderPlacement }
});
}
UI-Javascript
const connection = new signalR.HubConnectionBuilder()
.withUrl('http://localhost:7071/api')
.configureLogging(signalR.LogLevel.Information)
.build();
connection.on('productOrdered', (productOrdered));
connection.onclose(() => console.log('disconnected'));
console.log('connecting...');
connection.start()
.then(() => data.ready = true)
.catch(console.error);