
redis 的list类型实现消息队列:

list结构实现的优缺点:



2、pubsub模式(消息发布订阅)实现消息队列

pubsub的优缺点:

命令行实现:
pub:第一次发送有两个接收,第二个只有一个接收

sub接收:
第一个sub接收的信息通道(order.p1)使得pub发送第二次消息没有接受到

第二个sub接收的频道(order.*)接收order.后面所有的频道,使得两次pub发送的消息都接收到了

stream实现消息队列:


具体的实现:

往里面存数据:

$:则实时取数据,在消息存放的时候才会获取

0:取第一个数据,始终取第一个数据
优缺点:
4、消息费者组(consumer Group):

创建一个消费者组: XGROUP CREATE s1 g1 $ (s1队列名称,g1消费者组的名称)

消息消费者命令:

确认消息命令:XACK key group ID [ID ...] (如果消息只是拿到,没有确认的话,消息会存放在expending-list里面)
查看pending-list的命令:XPENDING key group [[IDLE min-idle-time] start end count [consumer]]
stream group的优点:

三种实现消息队列的比较:

5、通过streamGroup消费者组,就可以实现消息队列(通过java和lua脚本)