SignalR Self Service Listening for Messages

I am trying to create a Windows service that contains SignalR hosting.

I have read tutorials like Self-Host SignalR on ASP.Net

I notice that at least they seem to be based on broadcast messages and can't find anything in the listening process.

I need to listen to messages from the service as well as broadcast.

We already have our backplane setup - it's the same as the site.

On the website, I can join a group via Javascript. How to join a group in a self-served SignalR service.

On the website, I register the callback on the hub. How do I register the same callback in a self-service service?

some example code I have to register and run SignalR:

GlobalHost.DependencyResolver.UseSqlServer(Settings.Default.ISDBContext);
        app.Map("/signalr", map =>
        {
            map.UseCors(CorsOptions.AllowAll);
            HubConfiguration hubConfig = new HubConfiguration()
            {
                EnableDetailedErrors = true,
                EnableJSONP = true,
            };

            map.RunSignalR(hubConfig);

        });

      

Then I start my webApp like this:

SignalR = WebApp.Start<Startup>(options);

the parameters are the url i am registering. Startup is a startup class that contains the above signal mapping.

A bit lost here as I haven't created a self service yet before

+3


source to share


1 answer


Overall, SignalR offers a real-time messaging framework with the advantage that it can display messages to clients without asking them to update (you've read the input, that's enough for that). If you are starting your own host from a service, this should not change.

From what I understand from your scenario: you need to consume messages from a self-contained service. I think you may only need a hint of the Desktop SignalR Client . I think your application / service should start with the service and then act as a client for the service itself. This would be the cleanest approach.

As a javascript client, it acts as a consumer of a service with the same capabilities:

HubConnection conn = new HubConnection("http://192.168.1.1:8080");
IHubProxy hub = conn.CreateHubProxy("ChatHub");

// call from hub to client
hub.On<string, string>("addMessage", (name, message) =>
{
     // Handle incoming data update
});

      



and vice versa from desktop client to hub:

await hub.Invoke<string, string>("Send", name, message);

      

To work with groups, logic must be defined inside your hub. Documentation Working with groups provides a clear overview.

+4


source







All Articles