Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMQP - rabbitmq #97

Open
magicdawn opened this issue Jan 21, 2017 · 2 comments
Open

AMQP - rabbitmq #97

magicdawn opened this issue Jan 21, 2017 · 2 comments

Comments

@magicdawn
Copy link
Owner

magicdawn commented Jan 21, 2017

Links

@magicdawn
Copy link
Owner Author

magicdawn commented Jan 21, 2017

rabbitmq concepts

prefetch

默认情况下, MQ 会将 nth message dispatch 给 nth consumer, 但是不是所有任务的权重耗时是一样的, 可能导致某些 consumer 比较空闲. 使用 ch.prefetch(n) 可以让 consumer 确保最多有 n 个未 ack 的 message, 在 ack 之前, broker 不会发送新的 message.

Exchange

producer 不直接与 queue 打交道, producer 向 exchange 中 publish 消息. 默认的 sendToQueue 使用了默认的 fanout exchange

类型

  • fanout 将消息 broadcast 给所有 bind 的 queue
  • direct 支持简单的 routing key
  • routing 支持通配符进行匹配
    • * (star) can substitute for exactly one word.
    • # (hash) can substitute for zero or more words.

@magicdawn
Copy link
Owner Author

magicdawn commented Jan 21, 2017

amqplib readme notes

flow control

Channels act like stream.Writable when you call publish or sendToQueue: they return either true, meaning "keep sending", or false, meaning "please wait for a 'drain' event".

Those methods, along with ackackAllnacknackAll, and reject, do not have responses from the server. This means they do not return a promise in the promises API. The ConfirmChannel does accept a callback in both APIs, called when the server confirms the message; as well as returning a boolean.

  • publish & sendToQueuestream.Writable 一样, 返回 true 表示下游处理的过来, 继续发送, 返回 false 则需要等待 drain 事件
  • ack / ackAll / nack / nackAll / rehect 服务器不会有返回
  • 这些方法不反回 promise

Channels

Channels are multiplexed over connections, and represent something like a session, in that most operations (and thereby most errors) are scoped to channels.

Queues

options

name default explaination
exclusive false scopes the queue to the connection
durable true Message Broker 重启之后能自动恢复, 覆盖了 exclusive & autoDelete 的效果
autoDelete false 当 consumer 数量减少到 0 时, 自动删除 queue

Message

options

name default explaination
rabbitmq & consumer 使用的选项
expiration 提供了超时的话, 消息在 MQ 中超时后会被丢弃
userId 如果提供, MQ会对 connection 的 UserId 对比, reject 掉不匹配的
CC 额外的 routingjey
persistent 持久化, 该选项会覆盖 delivery
deliveryMode 1 or falsy: none persistent; 2 or truthy: persistent

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

No branches or pull requests

1 participant