-
Notifications
You must be signed in to change notification settings - Fork 354
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
RSocketFacrory.start() returns Mono<Rsocket> which is reconnect on each usage #730
Comments
Personally, I would recommend caching the created
However, such usage has its own downside. For example, if your connection gets closed for any reason, then you will not be able to reconnect using the given Right now I'm working on a version of |
Thank you for your response! With this info I've manage to make a hacky but sustainable Spring configuration which is reconnected only when previous connection is lost. Maybe someone finds it useful until official solution released: @Configuration
class RSocketClientConfiguration {
private val connectedRSocketMonoReference = AtomicReference<Mono<RSocket>>()
@Bean
@Qualifier("factory")
fun rSocketMonoFactory(): Mono<RSocket> {
return RSocketFactory
.connect()
.dataMimeType(APPLICATION_JSON_VALUE)
.metadataMimeType(MESSAGE_RSOCKET_COMPOSITE_METADATA.toString())
.resume()
.resumeSessionDuration(Duration.ofHours(2))
.resumeStreamTimeout(Duration.ofHours(2))
.frameDecoder(PayloadDecoder.ZERO_COPY)
.transport(WebsocketClientTransport.create(7000))
.start()
}
@Bean
@Primary
fun rSocketMono(@Qualifier("factory") rSocketMono: Mono<RSocket>): Mono<RSocket> {
return Mono.just(1)
.flatMap {
var resultMono: Mono<RSocket>
val connectedRSocketMono = connectedRSocketMonoReference.get()
if (connectedRSocketMono == null) {
resultMono = rSocketMono.cache()
connectedRSocketMonoReference.set(resultMono)
} else {
resultMono = connectedRSocketMono.flatMap { connectedRSocket ->
var result: Mono<RSocket> = connectedRSocketMono
if (connectedRSocket.isDisposed) {
result = rSocketMono.cache()
connectedRSocketMonoReference.set(result)
}
result
}
}
resultMono
}
}
} |
RSocketFacrory.start() returns Mono which returns new RSocket instance with new connection on each usage.
Shouldn't it keep established connection and return it whenever possible until connection closed?
E.g. I have simple spring client with rSocket and controller:
With this approach rSocket creates new connection for each request and doesn't uses multiple streams inside single connection.
The text was updated successfully, but these errors were encountered: