扇入(Fan-In):该模块直接调用上级模块的个数,像漏斗型一样去工作;
扇出(Fan-Out):该模块直接调用的下级模块的个数;
高扇入,合理扇出
Fan-In Messaging Patterns
Fan-In is a messaging pattern used to create a funnel for work amongst workers (clients: source, server: destination).
扇入 是一种消息传递模式,使用创建一种工作人员之间像漏斗一样的去工作 客户端:源,服务端:目标
We can model fan-in using the Go channels.
用channels来模拟fan-in
1 | // Merge different channels in one channel |
The Merge function converts a list of channels to a single channel by starting a goroutine for each inbound channel that copies the values to the sole outbound channel.
合并功能转换的频道列表的开始为每个入站通道副本的值的唯一出境通道goroutine里单通道。
Once all the output goroutines have been started, Merge a goroutine is started to close the main channel.
一旦所有的输出概念已经启动,合并一个goroutine里开始关闭主通道。
Fan-Out Messaging Pattern
Fan-Out is a messaging pattern used for distributing work amongst workers (producer: source, consumers: destination).
扇出是一种用于在工作人员之间分配工作的消息传递模式(生产者:源,消费者,目的地)
We can model fan-out using the Go channels.
用channels来模拟fan-out
1 | // Split a channel into n channels that receive messages in a round-robin fashion. |
The Split function converts a single channel into a list of channels by using a goroutine to copy received values to channels in the list in a round-robin fashion.
split函数转换成一个单一的通道进入的频道列表用一个goroutine里抄收到价值频道列表中以循环的方式。