com.github.lontime.extredisson.rpc.consumer.AbstractIdempotencyRemoteService Maven / Gradle / Ivy
package com.github.lontime.extredisson.rpc.consumer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.github.lontime.base.commonj.constants.Consts;
import com.github.lontime.base.commonj.utils.LoggerHelper;
import com.github.lontime.base.serial.mq.Message;
import com.github.lontime.extredisson.rpc.common.RemoteContext;
import org.redisson.api.RScoredSortedSet;
import org.redisson.api.RScript;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.ByteArrayCodec;
import static com.github.lontime.extredisson.common.Constants.IDEMPOTENCY_SUFFIX;
/**
* AbstractIdempotencyRemoteService.
* @author lontime
* @since 1.0
* @param res
* @param req
*/
public abstract class AbstractIdempotencyRemoteService extends AbstractRemoteService {
@Override
public boolean before(RemoteContext context, Message message) {
final RedissonClient client = getProvider().client(context.getConnectionName());
final RScoredSortedSet set = client.getScoredSortedSet(buildIdempotencyName(context.getStreamName()));
return set.addIfAbsent(System.currentTimeMillis(), createId(context));
}
@Override
public void error(Throwable throwable, RemoteContext context, Message message) {
final RedissonClient client = getProvider().client(context.getConnectionName());
final List