springboot 基于 redis redisson的消息队列

springboot 基于 redis redisson的消息队列

消息接收方

@Slf4j
@Component
@Order(200)
public class ClickQueueMessageReceive implements ApplicationRunner {

    @Resource
    private RedissonClient redissonClient;

    @Async("birdsExecutor")
    @Override
    public void run(ApplicationArguments args) throws Exception {
        while (true){
        
            try {
                RBlockingQueue<NovelIdTopicDto> blockingQueue =
    redissonClient.getBlockingQueue(TopicAndQueueKeyConst.CLICK_QUEUE);
                NovelIdTopicDto novelIdTopicDto = blockingQueue.take();
               //do some 
               
            } catch (InterruptedException e) {
                log.warn(e.getMessage(),e);
            }
            try {
                TimeUnit.MILLISECONDS.sleep(500);
            } catch (InterruptedException e) {
                log.info(e.getMessage(),e);
            }
        }
    }
}

消息发送方

@Slf4j
@Service
public class TopicAndQueuePushService {

    @Resource
    private RedissonClient redissonClient;

    @Async
    public void sendRead(String novelId){
        RBlockingQueue<NovelIdTopicDto> blockingQueue =
                redissonClient.getBlockingQueue(TopicAndQueueKeyConst.CLICK_QUEUE);
        blockingQueue.putAsync(getNovelIdTopicDto(novelId));
    }
}

完整代码查看

github开源地址(飞鸟小说):https://github.com/caobinrg/birds-novel
gitee开源地址(飞鸟小说) : https://gitee.com/caobinrg/birds-novel


版权声明:本文为qq_23287943原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。