skip to Main Content
[Function("DoSomething")]
[SignalROutput(HubName = "serverless", ConnectionStringSetting ="SignalRConnection")]
public async Task<SignalRMessageAction> DoSomething([ServiceBusTrigger("queue", Connection = "BusConnection")] ServiceBusReceivedMessage message)
{
      return new SignalRMessageAction("newMessage")
      {
           Arguments = new[] { message.Body.ToString() }
      };
}

everything is fine while getting message from ServiceBus, trigger is working but when method triggers return method is not broadcasting message. This is the only code block btw. I don’t have any client or something I expect to see connection or message on Azure SignalR Dashboard but there is 0 connection and 0 message. What am I missing?

Additionaly is it normal to see SignalR Trigger Empty on Azure Portal? it’s Linux Azure Function enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I couldn't solve it without SignalR client...

    What I did is I wrote an very basic SignalR client https://github.com/sercandumansiz/Matchmaking/blob/master/src/TriggerFunction/index.html

    But still not sure how to use SignalTrigger without client...

    I hope the repository that I shared will help you all the triggers inside TriggerFunction is working you can ask me for details the one I would like to mention is

    https://github.com/sercandumansiz/Matchmaking/blob/master/src/TriggerFunction/ServiceBusQueueTrigger.cs

    "negotiate" function that I shared above, I hope that project details help you too...


  2. Isolated ServiceBusTrigger Triggering but not broadcasting message to Azure Serverless SignalR with SignalROutput

    AFAIK, By using Isolated servicebus queue trigger function integrate with SignalR hub some SDK issues will come. If the requirement is sending servicebus queue message to signalR hub use another approach like directly servicebus integrate with signalR hub and send messages.

    By using below code will send messages from servicebus message to signalR.

    using Azure.Messaging.ServiceBus;
    using Microsoft.AspNetCore.SignalR.Client;
    using System;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;
    
    class Program
    {
        private const string ServiceBusConnectionString = "servicebus conn-string";
        private const string QueueName = "hiii";
        private const string SignalRHubUrl = "helloservice";
    
        private static HubConnection hubConnection;
    
        static async Task Main(string[] args)
        {
            var serviceBusClient = new ServiceBusClient(ServiceBusConnectionString, new ServiceBusClientOptions { });
    
            hubConnection = new HubConnectionBuilder()
                .WithUrl(SignalRHubUrl)
                .Build();
    
            try
            {
                await hubConnection.StartAsync();
                Console.WriteLine("SignalR connection established.");
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine($"Error connecting to SignalR Hub: {ex.Message}");
                return;
            }
    
            var processor = serviceBusClient.CreateProcessor(QueueName, new ServiceBusProcessorOptions { AutoCompleteMessages = false, MaxConcurrentCalls = 1 });
            processor.ProcessMessageAsync += ProcessMessagesAsync;
            processor.ProcessErrorAsync += ExceptionReceivedHandler;
            await processor.StartProcessingAsync();
    
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
    
            await processor.StopProcessingAsync();
            await hubConnection.StopAsync();
        }
    
        static async Task ProcessMessagesAsync(ProcessMessageEventArgs args)
        {
            var messageBody = Encoding.UTF8.GetString(args.Message.Body);
            await SendToSignalR(messageBody);
    
            await args.CompleteMessageAsync(args.Message);
        }
    
        static Task ExceptionReceivedHandler(ProcessErrorEventArgs args)
        {
            Console.WriteLine($"Error in Azure Service Bus message processing: {args.Exception}.");
            return Task.CompletedTask;
        }
    
        static async Task SendToSignalR(string message)
        {
            try
            {
                await hubConnection.InvokeAsync("SendMessage", message);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error sending message to SignalR Hub: {ex.Message}");
            }
        }
    }
    
    

    The servicebus message will be sending followed like below:

    enter image description here

    For any further clarification required Refer this DOC

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search