ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription.SubscriptionPostReconnectJob.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-redis-client-heimdall Show documentation
Show all versions of vertx-redis-client-heimdall Show documentation
Redis client based on the official one https://vertx.io/docs/vertx-redis-client/java/. This client will provide some additional features like reconnect capabilities, Event bus events on reconnecting related activities.
The newest version!
package ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription
import ch.sourcemotion.vertx.redis.client.heimdall.impl.PostReconnectJob
import ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription.connection.RedisHeimdallSubscriptionConnection
import io.vertx.core.AsyncResult
import io.vertx.core.Future
import io.vertx.core.Handler
import io.vertx.core.Promise
import io.vertx.core.logging.LoggerFactory
import io.vertx.redis.client.Redis
object SubscriptionPostReconnectJob : PostReconnectJob {
private val logger = LoggerFactory.getLogger(SubscriptionPostReconnectJob::class.java)
override fun execute(redis: Redis) : Future {
logger.debug("Execute subscription post reconnect job")
val promise = Promise.promise()
redis.connect()
.onSuccess { connection ->
if (connection is RedisHeimdallSubscriptionConnection) {
// Subscribe to channels after reconnect
connection.subscribeAfterReconnect()
.onSuccess { promise.complete() }
.onFailure { promise.fail(it) }
} else {
logger.logWrongConnectionType(connection)
// We flag here the job as successful, as we can nothing except logging
promise.complete()
}
}
.onFailure { promise.tryFail(it) }
return promise.future()
}
}