dgs-framework
dgs-framework copied to clipboard
Provide access to events in DgsWebSocketHandler
I would like to be notified when a client subscriber has cancelled/terminated the subscription. Is that possible ?
My goal is to keep track of the active subscriptions which I am emitting events to and in order for my to do that, I somehow need to know when a subscription has been cancelled/terminated etc.
When I have the dgs-examples-java running and I create a subscription from a client which I then kill, I can see that the DgsWebSocketHandler.kt in graphql-dgs-subscriptions-websockets handles it and does "Cleaning up for session".
I would think that in the DefaultReviewsService in the dgs-examples-java in the createReviews method, that I could do something in the lines of this - which does not seem to work:
reviewsPublisher = publisher.publish();
// HOOKS START
reviewsPublisher.doOnCancel(() -> {
// Subscription cancelled
});
reviewsPublisher.doOnTerminate(() -> {
// Subscription terminated
});
// HOOKS END
reviewsPublisher.connect();
Is there a way to achieve what I am requesting and is the above a correct approach?
Thank you in advance.
Not sure actually, but looking at the code, it seems like this should trigger. Will look into this more.