Search code examples
push-diffusion

When my process dies can I voluntarily close my Diffusion session?


I’m developing a control client that wires up a back-end system to a tree of topics. The back-end has a few thousand end points and the topic tree has a corresponding number of topics.

During development & testing I stop & restart my client a lot but prior sessions placed to the server live on for another 60s, meaning that my session-will (that my topics be removed) is not executed and the subsequent execution of my control client cannot add topics nor register as a topic updater (because the prior session hasn’t expired).

So I kill & restart the Diffusion server, which is inelegant and easily forgotten.

Granted sessions live longer than individual connection for robustness, but in this scenario I want the session to close. How can this be achieved?


Solution

  • 60 seconds is the default reconnect timeout. The server waits for this period for the first session to reconnect before executing the session will.

    The client can reduce that time, or disable reconnection altogether, by configuring the session factory used to establish the connection.

    Session session = Diffusion.sessions()
      .reconnectionTimeout(1000 /* ms */)
      .open("wss://myserver");
    

    or

    Session session = Diffusion.sessions()
      .noReconnection()
      .open("wss://myserver");