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

com.power4j.fist.redisson.queue.BlockQueueWriter Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
package com.power4j.fist.redisson.queue;

import com.power4j.fist.message.queue.QueueWriter;
import com.power4j.fist.redisson.common.NameGenerator;
import com.power4j.fist.redisson.common.RedisNamespace;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.Codec;
import org.springframework.lang.Nullable;

/**
 * @author CJ ([email protected])
 * @since 1.0
 */
@RequiredArgsConstructor
public class BlockQueueWriter implements QueueWriter {

	private final NameGenerator nameGenerator;

	private final RedissonClient redisson;

	@Nullable
	private final Codec codec;

	@Override
	public  boolean write(String channel, T data) {
		RBlockingQueue queue = createQueue(makeChannelName(channel));
		return queue.offer(data);
	}

	protected String makeChannelName(String origin) {
		return nameGenerator.generate(RedisNamespace.QUEUE, origin);
	}

	protected  RBlockingQueue createQueue(String channel) {
		if (null == codec) {
			return redisson.getBlockingQueue(channel);
		}
		else {
			return redisson.getBlockingQueue(channel, codec);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy