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

org.swisspush.redisques.action.GetQueueItemsCountAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
package org.swisspush.redisques.action;

import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.swisspush.redisques.exception.RedisQuesExceptionFactory;
import org.swisspush.redisques.handler.GetQueueItemsCountHandler;
import org.swisspush.redisques.util.QueueConfiguration;
import org.swisspush.redisques.util.QueueStatisticsCollector;
import org.swisspush.redisques.util.RedisProvider;

import java.util.List;

import static org.swisspush.redisques.util.RedisquesAPI.PAYLOAD;
import static org.swisspush.redisques.util.RedisquesAPI.QUEUENAME;

/**
 * Retrieve the number of items of the requested queue
 */
public class GetQueueItemsCountAction extends AbstractQueueAction {

    public GetQueueItemsCountAction(
            Vertx vertx, RedisProvider redisProvider, String address, String queuesKey,
            String queuesPrefix, String consumersPrefix, String locksKey,
            List queueConfigurations, RedisQuesExceptionFactory exceptionFactory,
            QueueStatisticsCollector queueStatisticsCollector, Logger log
    ) {
        super(vertx, redisProvider, address, queuesKey, queuesPrefix, consumersPrefix, locksKey,
                queueConfigurations, exceptionFactory, queueStatisticsCollector, log);
    }

    @Override
    public void execute(Message event) {
        String queue = event.body().getJsonObject(PAYLOAD).getString(QUEUENAME);
        var p = redisProvider.redis();
        p.onSuccess(redisAPI -> redisAPI.llen(queuesPrefix + queue, new GetQueueItemsCountHandler(event)));
        p.onFailure(ex -> replyErrorMessageHandler(event).handle(ex));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy