wangduanduan / wangduanduan.github.io

Wubba Lubba dub-dub
https://wdd.js.org
27 stars 7 forks source link

rabbitmq 复习 #285

Closed wangduanduan closed 5 years ago

wangduanduan commented 5 years ago

基本概念

Jietu20190506-085006

工作队列

Jietu20190506-090554

队列durable和消息persistent的区别?

// 队列durable
ch.assertQueue('hello', {durable: true});

// 消息persistent
ch.sendToQueue(q, new Buffer(msg), {persistent: true});

Marking messages as persistent doesn't fully guarantee that a message won't be lost. Although it tells RabbitMQ to save the message to disk, there is still a short time window when RabbitMQ has accepted a message and hasn't saved it yet. Also, RabbitMQ doesn't do fsync(2) for every message -- it may be just saved to cache and not really written to the disk. The persistence guarantees aren't strong, but it's more than enough for our simple task queue. If you need a stronger guarantee then you can use

prefetch

perfetch用来设置,如果一个消息还没有被消费者处理完并确认,就不要再给这个消息发送消息

ch.prefetch(1);

推送订阅

工作队列,每个消息只能被一个消费者消费。而推送订阅方式,一个消息可以被多个消费者消费。

The core idea in the messaging model in RabbitMQ is that the producer never sends any messages directly to a queue. Instead, the producer can only send messages to an exchange. There are a few exchange types available: - direct, topic, headers and fanout

// 声明exchange
ch.assertExchange('logs', 'fanout', {durable: false})

临时队列

// 队列名为空字符串,就是临时队列
channel.assertQueue('', {
  exclusive: true
});

队列

队列属性

队列声明

  1. 如果要声明的队列不存在,则创建
  2. 如果要声明的队列存在,则检查传递的队列属性和已经存在的队列的属性是否相同,如果相同,则使用已经存在的队列。如果不同,则会报错406 PRECONDITION_FAILED

exchange

其他

RabbitMQ doesn't allow you to redefine an existing queue with different parameters and will return an error to any program that tries to do that.

参考