-
Notifications
You must be signed in to change notification settings - Fork 443
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
separate handlers for concurrent handlers #48
Conversation
Yea, I experienced this while updating Taking a step back, the reason why I went with the current API is because I believe the best way to think about handlers is to treat them like an HTTP handler for a certain URL (topic). You're getting the same type of messages to the same instance of a handler. It doesn't matter how many concurrent requests are happening. |
I'll let you know what else i uncover but the primary use has been to give each handler unique ID's so that logging inside a handler has an id to prepend to output so that it's clear all the logs that came from a single handler sequence. I think that's a pretty legit use case and works as an example of something that shouldn't require hoops to go through to get 1:1 handler struct and handler functions. |
Looking through the code i don't see any reason not to just drop the check that guards against adding mutliple handlers. Calling multiple times wouldn't be anything different than I think we can just drop:
|
I'll mention that this also removes barriers to the transition to new API naming. |
If we allow you to call this method more than once it should be prefixed with But, I've already explained why I think it should be as it is. Think about how you would handle this if it were an HTTP handler. I think those semantics make sense here too, so I don't think we should make this change. |
#56 made me realize that another motivation for this change is that it would provide a way to use handlers that are not goroutine safe with concurrent handlers because this allows you to keep handler objects 1:1 w/ goroutines. |
I agree that this is a good example of a place where explicitly documenting that message handler state is shared amongst goroutines and that it requires synchronization if modifying. I'm not necessarily convinced that's a bad thing and that we need this API, though 😄. But let's try to wrap this up... I think we discussed offline at one point, my objection is the asymmetry in being able to add but not remove. If we make a change such that calling Agreed? |
edit: and document when it can be used and that it will panic... |
Agreed. i'll update. |
* remove unneeded check for adding more handlers * rename Set->AddHandler * check for handlers on lookupd connect * panic on already connected to nsqd/nsqlookupd
separate handlers for concurrent handlers
An unexpected api regression/change is that you can't set concurrent handlers to each use their own handler object. This was useful when you wanted separate state for each concurrent handler.
The current api doesn't allow you to call
SetHandler
orSetConcurrentHandlers
multiple times, but i don't see a strict reason not to allow that. Thoughts @mreiferson