Skip to content

SignalR Per-hub-method middleware #21722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jon-Murray opened this issue May 11, 2020 · 2 comments
Closed

SignalR Per-hub-method middleware #21722

Jon-Murray opened this issue May 11, 2020 · 2 comments
Labels
area-signalr Includes: SignalR clients and servers

Comments

@Jon-Murray
Copy link

Hi,

I apologise if this has been covered before, but i did google a lot and the best i could find was #7139 which somewhat touches on the issue. I've been using signalr 2.2 in production for a while now. Originally, we modified the "Invoke" function within DefaultHubDispatcher (Microsoft.AspNetCore.SignalR.Core) and added in a custom function to record the hub endpoint, user, arguments, a kick off a timer. Then wrapped the "ExecuteHubMethod" code in a try/catch, and recorded the eventual time taken. This allowed us to pipe the results (status code), which user executed what, how long it took, etc. etc. into our logging system. It worked great and eventually allowed for some funky stats such as the below:

image

I hope this kind of gives enough background information about the use-case. Now you can see the "GET" and "WS" prefixes. The GET was from a typical controller method which was using the standard http request middleware. However, i genuinely can't find a way to have something similar in signalr.

Ideally i'd want exactly the same functionality, a hub method is executed, before execution i am passed the name, arguments, or just the context itself, i can then pass this back, and get either a response object, or just a task success/failure. The issue i linked way back before this wall of text also asked about something similar. Without changing the source again, the only semi-solutions i have found at the moment are that the authorization middleware passes the method/args over (but obviously doesnt not record the outcome or time of the execution) and then i can comb through logging with debug logs enabled. Are there any plans to integrate a "traditional" middleware into signalr? Thanks again for all the awesome work to date.

@mkArtakMSFT mkArtakMSFT added the area-signalr Includes: SignalR clients and servers label May 12, 2020
@BrennanConroy
Copy link
Member

This looks like the HubPipeline work (renamed Hub Filters) in #5353.
Please take a look at the proposal and see if it would meet your needs.

@Jon-Murray
Copy link
Author

Hi Brennan,

I've had a play around with your PR and it looks spot on. Really good timing and a great implementation that has everything that i'd need. Perfect timing too. Will close this now. For anyone else who ends up here via a search engine, the Startup.cs in SignalRSamples has an example filter (CustomHubFilter). Thanks for the quick reply/work!

@ghost ghost locked as resolved and limited conversation to collaborators Jun 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

3 participants