I have deployed a set of Azure Functions (v2).
I want to have an iOS application being notified when something happens on the server side so I created an Azure SignalR Service, configured as Serverless
.
I have created and deployed a new negotiate
Azure Function, as explained in the documentation, that publishes subscription information on a service bus queue:
[FunctionName("negotiate")]
public async Task<SignalRConnectionInfo> Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous)]
HttpRequest httpRequest,
ClaimsPrincipal claimsPrincipal,
[SignalRConnectionInfo(HubName = "updates", UserId = "{headers.x-ms-client-principal-id}")]
SignalRConnectionInfo connectionInfo)
{
try
{
// Uses the name identifier for now.
Claim nameIdentifierClaim = claimsPrincipal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
string userId = nameIdentifierClaim.Value;
foreach (Guid groupId in claimsPrincipal.GetGroups())
{
var subscription = new SynchronizationSubscriptionContract {UserId = userId, GroupId = groupId};
await m_serviceBus.SendAsync(JsonConvert.SerializeObject(subscription));
}
return connectionInfo;
}
catch (Exception exc)
{
//
}
}
The Service Bus is bound to an Azure Function that adds the user to the list of groups:
[ServiceBusAccount(Constants.Configuration.ServiceBusConnectionString)]
[FunctionName("subscribe")]
public async Task AddToGroupAsync(
[ServiceBusTrigger("synchronization-subscriptions")] string requestMessage,
[SignalR(HubName = "updates")] IAsyncCollector<SignalRGroupAction> signalRGroupActions)
{
var synchronizationSubscriptionContract = JsonConvert.DeserializeObject<SynchronizationSubscriptionContract>(requestMessage);
string groupName = synchronizationSubscriptionContract.GroupId;
var addGroupAction = new SignalRGroupAction
{
UserId = synchronizationSubscriptionContract.UserId,
GroupName = groupName,
Action = GroupAction.Add
};
await signalRGroupActions.AddAsync(addGroupAction);
}
So far so good.
Whenever one of my existing Azure Functions needs to publish a message on the SignalR channel, it sends a message on a dedicated service bus queue that is bound to another Azure Function. The Azure Function then grabs the message and sends it to the Azure SignalR Service:
[ServiceBusAccount(Constants.Configuration.ServiceBusConnectionString)]
[FunctionName(Api.Functions.Synchronization.UpdateSynchronizationInfo)]
public async Task Run(
[ServiceBusTrigger("synchronization-requests")] string requestMessage,
[SignalR(HubName = "updates")]
IAsyncCollector<SignalRMessage> signalRMessages
)
{
var requestContract = JsonConvert.DeserializeObject<SynchronizationUpdateRequestContract>(requestMessage);
var request = m_mapper.Map<SynchronizationUpdateRequest>(requestContract);
// Do more stuff.
string groupName = request.GroupId;
var updateMessage = new SignalRMessage
{
GroupName = groupName,
Target = "notify",
Arguments = new string[] {}
};
await signalRMessages.AddAsync(updateMessage);
}
Based on the logs that I added at different places in the Azure Functions, I see no errors and everything seemed to be called properly. However, I am not seeing any messages on signalR: the message count stays at 0 even if the connection count increases. My application does not received any messages.
Question
Why aren't the messages being sent to the Azure SignalR? What am I missing?