0

Ivé this code...

public async Task<IActionResult> Run(
   [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v1/Sala")] 
HttpRequest req, [SignalR(HubName = "{query.HubName}")] 
IAsyncCollector<SignalRMessage> signalRMessages) {
     
     await signalRMessages.AddAsync(
           new SignalRMessage {
               Target = "newMessage",
               Arguments = new[] { "Hello" }
           });
}

And this code works good and I am happy. But I've a need, in partiular on my EventGridTrigger... As you could noticed on the code above, the hubname is dinamic and an EventGridTrigger is a sort of special kind of endpoint (Your client app will not call and consume it...SignalR will instead). But I am capable to identify the hubname on my EventGridTrigger...I can do this:

SignalRDataEvent data = 
JsonConvert.DeserializeObject<SignalRDataEvent(eventGridEvent.Data.ToString());

string hubname = data.hubname;

But now...I need to send a signalR message using my variable hubname. Since I can't put [SignalR(HubName = "{query.HubName}")] IAsyncCollector signalRMessages) on my EventGridTrigger, I need to create the object SignalR, probably pass credentials, hubname, etc and then send a message. I can't find any sample for this - At least no samples that can work in serverless c# azure functions. Can someone help me wikth this ?

Marco Jr
  • 6,496
  • 11
  • 47
  • 86

1 Answers1

1

Try the following:

[SignalR(HubName = "{data.hubName}")]
Roman Kiss
  • 7,925
  • 1
  • 8
  • 21
  • Thanx Roman ! You save me twice in 2 days :) Deserve a beer indeed ! Well..Such things are not so good documented and also, it's very against intuitive to deduce. We declare the object with paremeters on top and then in the middle this will receive the parameter. It's something from bottom to top. But it works ! thanks ! – Marco Jr Jun 23 '22 at 13:42