All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription.SubscriptionPostReconnectJob.kt Maven / Gradle / Ivy

Go to download

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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy