com.redis.spring.batch.writer.operation.XAddAll Maven / Gradle / Ivy
package com.redis.spring.batch.writer.operation;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import com.redis.spring.batch.writer.Operation;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.StreamMessage;
import io.lettuce.core.XAddArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisStreamAsyncCommands;
public class XAddAll implements Operation {
private Function>> messages;
private Function, XAddArgs> args = m -> new XAddArgs().id(m.getId());
public void setMessages(Function>> messages) {
this.messages = messages;
}
public void setArgs(Function, XAddArgs> args) {
this.args = args;
}
@SuppressWarnings("unchecked")
@Override
public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
RedisStreamAsyncCommands streamCommands = (RedisStreamAsyncCommands) commands;
for (StreamMessage message : messages(item)) {
futures.add(streamCommands.xadd(message.getStream(), args(message), message.getBody()));
}
}
private XAddArgs args(StreamMessage message) {
return args.apply(message);
}
private Collection> messages(T item) {
return messages.apply(item);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy