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
What's the best practice for monitoring a filtered stream? #11
Comments
After some research, and looking at the source code in persisted-model, while it looks like it should support an |
major +1 to including this as a built in feature and to you @njcaruso for your great example. really helpful |
@njcaruso - the solution was awesome. I also copied from your code and used loopback-filters to apply all the filters in the change stream object. Created a gist here. https://gist.github.com/allupaku/4139d4a366983568206a May be this will be useful for some one.. |
@allupaku - I tested your gist and it worked very well for me. This issue is definitely worthy of a PR to loopback's main repository. The documentation on their PersistentModel's createChangeStream is clearly misleading since Strongloop never implemented the where filter. |
@allupaku, @zihehuang glad I could help you. I ran into an issue using EventSource (nothing to do with Loopback I think), where if the client disconnects manually or on browser close, the server never receives a "close" or "end" event hook. So a connection persists forever. Additionally, it seems that with no activity on the stream within 60 seconds, that the client requests a NEW request. So if you have 5 minutes of no activity, you'll get 5 total connections on the server. I ended up having to write an interval after 60 seconds to destroy the stream, with a changes.on('data') event hook to reset the interval if data was sent. So test your close/end assumptions. If you are able to get it to work, please let me know? |
@njcaruso - i have updated the gist with another file which is a middle ware i use to remove the default timeout of node/express web server. I am just looking at a test whether i am able to reproduce that issue of multiple connections.. |
@njcaruso - with 60 seconds of no activity i am not getting that behavior of client issuing another connection.. i just double checked .. Can this be a browser specific behavior ? which browser are you trying with ? |
@zihehuang - i have added another lb services gist as well which may help in creating the change-stream , could you please test that out if possible ? and let me know the results.. for me it is working perfectly.. |
@allupaku @njcaruso - I am not using the lb-services so I cannot confirm the use case for that. However, I can confirm that setting the
Before the addition of |
+1 i can duplicate what @zihehuang is seeing, setting the timeout in server.js does not prevent the change streams from timing out after 2 minutes
|
I'm using this code and it works - but only on main model, not on nested in filter:
So the change events are coming when "cards" changed, not when "image" or "media" objects (they are both related as hasOne). Don't know what to do for now. |
@dancingshell 's middleware works well when connecting loopback directly. However it won't work in nginx proxy and get 'net::ERR_INCOMPLETE_CHUNKED_ENCODING' every 60 seconds. Finally, Add In case someone have the same problem, posted this comment here. |
I'm having troubles getting the result from one browser window to another using technique described in the gist. Maybe someone experienced something like that? Thanks! |
Ok, it was my mistake misunderstanding the work of cluster. Having update fire up on one worker and user had stream on other one. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
I need to stream changes to a specified user, not to all users.
In my below code I can successfully initially query messages for a specific user, but any updates to the stream is not filtered. So it gives me updates to any change to the
Message
model regardless of the filter.belongsTo
relation between myMessage
model and myuser
model (which hasUser
as the base model). Can I monitor a stream specific touser.Message
, i.e. to just the relation?Here's my current code:
I can see here that you can set a
where
clause in creating a change-stream: https://apidocs.strongloop.com/loopback/#persistedmodel-createchangestream, but I'm struggling on how to do this with the LiveSet approach. I suspect somehow from the Angular client I can create a change stream, pass in an option 'where clause'.I'm also struggling to understand how the lbServices createChangeStream factors into all of this, like
Message.createChangeStream()
, versus the newly released factorycreateChangeStream()
that's inangular-live-set
.The text was updated successfully, but these errors were encountered: