Add request_id in subscription events by default
ranzbak opened this issue · comments
Is your feature request related to a problem? Please describe.
After many days of frustration, asking myself why the dcrf-client works with my old code but not with the @model_observer code.
I found out that the ObserverModelInstanceMixin automatically sends the request_id back with every event after a subscribe.
The examples in the readme however don't mention this, this results in dcrf-client, silently dropping the events.
Describe the solution you'd like
I would like the framework to reply the original subscription request_id with every subscription Event, just like ObserverModelInstanceMixin does. Or at least have a list of request_id's included in the arguments.
Describe alternatives you've considered
An alternative is to include in the documentation that the example given, does not send the request_id back, and that some frameworks NEED the request_id (like dcrf-client).
(Perhaps provide example code on how to preserve the request_id?)
Additional context
dcrf-client: https://github.com/theY4Kman/dcrf-client
paragraph of the documentation: https://github.com/hishnash/djangochannelsrestframework#subscribing-to-a-filtered-list-of-models
@ranzbak this is not possible to do automatically since its common for people to subscribe in the accept
method were there is not request id to connect to.
so instead I propose a few changes that mean if you subscribe using an @action
you can provide the request id. Then the observer method will be called with a list of all the subscribed requests. here you can do what you need to do (loop over those requests and send a response for each one or something else).
see #108
I still need to add some more unit tests to ensure if you have multiple overlapping subscriptions it all works correctly.