2

Rabbitmq | 01 - Hello World

 2 years ago
source link: https://ijayer.github.io/post/tech/mq/20190328-rabbitmq-hello-world/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using the Go RabbitMQ client

Design 

> 客户端协议实现说明

Most other broker clients publish to queues, but in AMQP, clients publish
Exchanges(交易中心) instead.  AMQP is programmable, meaning that both the producers and
consumers agree on(达成一致) the configuration of the broker, instead requiring an
operator or system configuration that declares the logical topology in the
broker.  The routing between producers and consumer queues is via Bindings.
These bindings form the logical topology(拓扑) of the broker.

> Hello World Example Routing

                       +---------------------------------+
           Publishing  +                                 + Delivery
Publisher ------------>+--Exchange --> Routes --> Queue--+----------> Consumer
                       +                                 +
                       +---------------------------------+

In this library, a message sent from publisher is called a "Publishing" and a
message received to a consumer is called a "Delivery".  The fields of
Publishings and Deliveries are close(接近) but not exact mappings to the underlying
wire format to maintain stronger types.  Many other libraries will combine
message properties with message headers.  In this library, the message well
known properties are strongly typed fields on the Publishings and Deliveries,
whereas the user defined headers are in the Headers field.

> Publishings 和 Deliveries 类型定义相关说明

The method naming closely matches the protocol's method name with positional
parameters mapping(映射) to named protocol message fields.  The motivation here is to
present a comprehensive(全面的) view over all possible interactions with the server.

Generally, methods that map to protocol methods of the "basic" class will be
elided(消隐) in this interface, and "select" methods of various channel mode selectors
will be elided(隐藏) for example Channel.Confirm and Channel.Tx.

> 接口命名尽量和 AMQP 协议保持了一致 

The library is intentionally(有意的) designed to be synchronous, where responses for
each protocol message are required to be received in an RPC manner.  Some
methods have a noWait parameter like Channel.QueueDeclare, and some methods are
asynchronous like Channel.Publish.  The error values should still be checked for
these methods as they will indicate IO failures like when the underlying
connection closes.

> 同步通信;但也有例外,如 Channel.Publish 属于异步,也需要检查 err 是否是 IO 错误(在底层连接关闭时就会抛出) 

Asynchronous Events

> 异步事件机制相关说明

Clients of this library may be interested in receiving some of the protocol
messages other than Deliveries like basic.ack methods while a channel is in
confirm mode(确认模式).

The Notify* methods with Connection and Channel receivers model(模拟) the pattern of
asynchronous events like closes due to exceptions, or messages that are sent out
of band from an RPC call like basic.ack or basic.flow.

Any asynchronous events, including Deliveries and Publishings must always have
a receiver until the corresponding chans are closed.  Without asynchronous
receivers, the sychronous methods will block.

> 异步事件必须有接收者,等待 chan 被关闭;同步方法会阻塞

Use Case

It's important as a client to an AMQP topology to ensure the state of the
broker matches your expectations.  For both publish and consume use cases,
make sure you declare the queues, exchanges and bindings you expect to exist
prior to calling Channel.Publish or Channel.Consume.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK