2

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.

enter image description here

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.

Connections

Messages

Question

Why aren't the messages being sent to the Azure SignalR? What am I missing?

Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
  • Could you share the details of your function app so we can investigate from our side? We'll need to know the timeframe of the issue, your function app's name (you can share it [privately](https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately)), and region. Invocation IDs of executions that should have sent a signalR message but didn't will also help us pinpoint any issues on our side. – Katy Shimizu Jun 14 '19 at 23:42

1 Answers1

1

Wow.

The message seems to be dropped if the Arguments property is an empty list.

When I changed to Message instance to the following, it immediately worked:

var updateMessage = new SignalRMessage
{
    GroupName = groupName,     
    Target = "notify",
    Arguments = new[] { "Lulz" }
};
Kzryzstof
  • 7,688
  • 10
  • 61
  • 108