Answered by:
Azure SignalR Service (Preview) Group Joining from .Net Console

Question
-
Hi All,
I'm currently getting up to speed with the Azure SignalR Service (Preview), and have looked at the aspnet core and straight .net samples.
One of the interesting samples is:
https://www.c-sharpcorner.com/article/azure-signalr-messaging-with-net-core-console-app-server-and-client/
Which allows a connection to the SignalR Hub from a .net console to console.
I would like to utilize this, and have modified it with reference to the Azure SignalR Swagger (https://github.com/Azure/azure-signalr/blob/dev/docs/swagger/v1-preview.json) for definition of services available and am able to broadcast to all clients, or to specifics.
However I am having a problem registering the connecting users to groups for the service to send messages to specific groups.
I can see from the Swagger that I can send messages to groups, in a similar way to users (by posting to /api/v1-preview/hub/{hub}/group/{group}) however, I cannot see anything outside of a Hub class - which this sample would not have, to do the equivalent of
Groups.AddToGroupAsync(userName, groupName);
which works in the aspnet core examples when within a hub, but I am unable to find a non-hub equivalent.
Some direction on how I go about adding a user to a group outside of the hub would be very helpful.
Thanks
- Edited by Dave Thompson 101 Wednesday, September 12, 2018 3:56 PM broken links
Wednesday, September 12, 2018 3:56 PM
Answers
-
Answered at
Though, to avoid link expiration, the suggestion from the ASP.Net forums is to use a hub to accept a "JoinGroup" which is able to do the call into
public void JoinGroup(string groupName) { Groups.AddToGroupAsync(Context.ConnectionId, groupName); }
which will be called when a client calls through to JoinGroup within an aspnet core project connecting to AzureSignalR on startup
public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSignalR() .AddAzureSignalR(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseFileServer(); app.UseAzureSignalR(routes => { routes.MapHub<ConsoleAppBroadcaster>("/ConsoleAppBroadcaster"); }); } }
kudos to Fei Han for this answer
As a further update, it appears as of version 1.0 release (the day after this post), the API was updated to include a PUT and DELETE to groups to add and remove users from groups
https://github.com/Azure/azure-signalr/blob/dev/docs/swagger/v1.json
- Marked as answer by Dave Thompson 101 Friday, September 14, 2018 10:16 AM
- Edited by Dave Thompson 101 Thursday, October 4, 2018 1:50 PM Release 1.0 update
Friday, September 14, 2018 10:15 AM
All replies
-
I suggest you, post your query on ASP.NET SignalR forum: https://forums.asp.net/1254.aspx/ for better assistance.
------------------------------------------------------------------------------------------
If this answer was helpful, click “Mark as Answer” or “Up-Vote”. To provide additional feedback on your forum experience, click here.- Proposed as answer by AshokPeddakotla-MSFTMicrosoft employee Wednesday, September 12, 2018 6:29 PM
Wednesday, September 12, 2018 6:29 PM -
Thanks Ashok,
for reference, here is the other thread:
https://forums.asp.net/t/2146808.aspx?Azure+SignalR+Service+Preview+Group+Joining+from+Net+Console
Thursday, September 13, 2018 8:54 AM -
Sure. Thanks for sharing the link.
Thursday, September 13, 2018 7:46 PM -
Answered at
Though, to avoid link expiration, the suggestion from the ASP.Net forums is to use a hub to accept a "JoinGroup" which is able to do the call into
public void JoinGroup(string groupName) { Groups.AddToGroupAsync(Context.ConnectionId, groupName); }
which will be called when a client calls through to JoinGroup within an aspnet core project connecting to AzureSignalR on startup
public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSignalR() .AddAzureSignalR(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseFileServer(); app.UseAzureSignalR(routes => { routes.MapHub<ConsoleAppBroadcaster>("/ConsoleAppBroadcaster"); }); } }
kudos to Fei Han for this answer
As a further update, it appears as of version 1.0 release (the day after this post), the API was updated to include a PUT and DELETE to groups to add and remove users from groups
https://github.com/Azure/azure-signalr/blob/dev/docs/swagger/v1.json
- Marked as answer by Dave Thompson 101 Friday, September 14, 2018 10:16 AM
- Edited by Dave Thompson 101 Thursday, October 4, 2018 1:50 PM Release 1.0 update
Friday, September 14, 2018 10:15 AM -
Glad to hear that your issue is resolved. Appreciate for sharing the resolution, this would certainly benefit other community members.
Friday, September 14, 2018 11:26 AM