Skip to content

Instantly share code, notes, and snippets.

@firefirer1983
Last active April 28, 2020 10:34
Show Gist options
  • Save firefirer1983/85aeff9db4227fdc91a0d9055601be3c to your computer and use it in GitHub Desktop.
Save firefirer1983/85aeff9db4227fdc91a0d9055601be3c to your computer and use it in GitHub Desktop.
RabbitMQ

RabbitMQ

Message Queue - a message buffer that RabbitMQ keeps on behalf of the consumer.

Message Queue是RabbitMQ维护在host上的一个缓存队列

无论是发送还是接收前,都需要先queue_declare,不然会发送丢失或接收失败.

Work Queues (aka: Task Queues)

Avoid doing a resource-intensive task immediately and having to wait for it to complete.

Consumer

Consumer对Queue不是独占的,如果有多个Consumer同时消费一个Queue,会以round-robin的方式消费掉所有的消息

Fair Dispatch

默认情况下,当一个消息进入queue后,broker是直接将消息按照round-robin的方式分配到每个consumer. 如果任务之间是不均衡的,有可能出现饥饿的消费者. 解决方法: 在一个consumer发送ack前,不要将消息再发送给此consumer(prefetch=1)

Fan-out Exchange

Fan-out的Exchange会出现一个风险,就是当没有队列的时候,如果有消息发送到Exchange,消息会被丢弃掉.

The messages will be lost if no queue is bound to the exchange yet, but that's okay for us; if no consumer is listening yet we can safely discard the message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment