rsocket / rsocket-kotlin

RSocket Kotlin multi-platform implementation
http://rsocket.io
Apache License 2.0
552 stars 37 forks source link

Provide rSocket `path` or some `id` in the `reconnectable` and `interceptors` blocks #282

Open vmalykhin opened 4 days ago

vmalykhin commented 4 days ago

Is there an easy way to know the current RSocket instance by path (url or any other tag like id or hash) when processing errors in the reconnectable {...} block?

Android use case: Ktor client creates a few instances of RSockets by ktorClient.rSocket(host, path, secure = true)with different path and keeps these sockets alive during app session. Then after the disconnect/reconnect depending on business logic, the client might want to reconnect some socket instance immediately, but other sockets should be reconnected a bit later to prevent network overloading (say, 5-10 seconds later) or should not be reconnected at all.

I bit of pseudo code:

reconnectable { cause, attempt -> // no way to know on what exact rSocket instance it called?
  if (myInternalLogicHelper.isHighPriorityInstance(rSocket)) {
    true // reconnects now
  } else {
    delay(5000) // delay before next attempt
    true // or even `false` to not reconnect at all after error
  }
}

Also looks like there is no relation between initial RSocket created by ktorClient.rSocket(...) and rSocket object received in  interceptors -> forRequester. Does RSocket URL (path) have public access somewhere?

Thanks in advance!