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

wang.moshu.message.MessageTrunk Maven / Gradle / Ivy

Go to download

message-trunk is a lightweight high performance message bus (queue) based on redis.

The newest version!
package wang.moshu.message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

/**
 * 消息总线,用于向消息总线存入消息
 * 
 * @author dingxiangyong 2016年7月28日 下午1:42:42
 */
@Service
public class MessageTrunk
{
	@Autowired
	private RedisUtil redisUtil;

	@Autowired
	@Qualifier(value = "messageTrunktaskExecutor")
	private ThreadPoolTaskExecutor threadPool;

	/**
	 * 失败重试次数,超过此值则不再重试,默认3次
	 */
	private int failRetryTimes = 3;

	/**
	 * 如果线程池满了,生产者暂停的时间,单位:S
	 */
	private int threadPoolFullSleepSeconds = 1;

	public ThreadPoolTaskExecutor getThreadPool()
	{
		return threadPool;
	}

	public void setThreadPool(ThreadPoolTaskExecutor threadPool)
	{
		this.threadPool = threadPool;
	}

	public int getFailRetryTimes()
	{
		return failRetryTimes;
	}

	public void setFailRetryTimes(int failRetryTimes)
	{
		this.failRetryTimes = failRetryTimes;
	}

	public int getThreadPoolFullSleepSeconds()
	{
		return threadPoolFullSleepSeconds;
	}

	public void setThreadPoolFullSleepSeconds(int threadPoolFullSleepSeconds)
	{
		this.threadPoolFullSleepSeconds = threadPoolFullSleepSeconds;
	}

	/**
	 * 推送消息
	 * 
	 * @param message
	 */
	public void put(Message message)
	{
		redisUtil.rpush(message.getKey().toString(), message, 0);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy