springboot 基于 redis redisson的消息队列
springboot 基于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
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)