惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
GbyAI
GbyAI
Y
Y Combinator Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
博客园_首页
B
Blog RSS Feed
Recorded Future
Recorded Future
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
D
DataBreaches.Net
IT之家
IT之家
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
B
Blog
The Cloudflare Blog
MyScale Blog
MyScale Blog
雷峰网
雷峰网
U
Unit 42
C
Check Point Blog
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
D
Docker
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
L
LangChain Blog
F
Fortinet All Blogs
腾讯CDC
Martin Fowler
Martin Fowler
I
InfoQ
J
Java Code Geeks
博客园 - Franky
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志

博客园 - ®Geovin Du Dream Park™

go: Functional Options Pattern go:Timing Functions Pattern python: Timing Functions Pattern go: Steady-State Pattern python: Steady-State Pattern go: Handshaking Pattern python: Handshaking Pattern go: Fail-Fast Pattern python: Fail-Fast Pattern I go: Deadline Pattern python: Deadline Pattern go: Circuit-Breaker Pattern python: Circuit-Breaker Pattern go: Bulkheads Pattern python: Bulkheads Pattern go: Push & Pull Pattern python: Push & Pull Pattern python: Publish/Subscribe Pattern II go: Publish/Subscribe Pattern python: Publish/Subscribe Pattern go: Futures & Promises Pattern python: Futures & Promises Pattern go: Worker Pool Pattern go:Pipeline Pattern python: Worker Pool Pattern python: Pipeline Pattern go: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In go: Producer Consumer  Pattern python: Producer Consumer Pattern go: Parallelism Pattern python: Parallelism Pattern go: Reactor Pattern python: Reactor Pattern go: Generators Pattern python: speech to text offline python: Generators Pattern go: Coroutines Pattern python:Coroutines Pattern go: Broadcast Pattern python: Broadcast Pattern python: Bounded Parallelism Pattern go: Bounded Parallelism Pattern python: N-Barrier Pattern go: N-Barrier Pattern python: Semaphore Pattern go: Semaphore Pattern python: Read-Write Lock Pattern go: Read-Write Lock Pattern python: Monitor Pattern go: Monitor Pattern python: Mutex Pattern go: Lock/Mutex Pattern Python: Condition Variable Pattern go:Condition Variable Pattern python: Registry Pattern python: Interpreter Pattern go: Interpreter Pattern go: Registry Pattern go: Memento Pattern go: Command Pattern go: State Pattern go:Template Method Pattern go: Strategy Pattern go: Visitor Pattern go: Observer Pattern go: Mediator Pattern go: Iterator Pattern go: Chain of Responsibility Pattern go: Proxy Pattern go:Decorator Pattern go: Facade Pattern go: Flyweight Pattern go: Composite Pattern go: Singleton Pattern go: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java go: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory Pattern go: Factory Method Pattern go: goLang 在Windows环境搭建Go语言开发环境 CSharp: Parallel Extensions cpp: class python: 蝴蝶跟随鼠标 javascript: 中国历史人物热力分布图using echart javascript: 中国历史人物热力图 python: 初养龙虾微信纯文字自动回复using workBuddy python: object 入门 python: Factory Method Pattern python: Simple Factory Pattern python: Abstract Factory Pattern 区域化 代码 python: Null Object Pattern python: Builder Pattern python: Adapter Pattern
python: Fan-Out Pattern
®Geovin Du Dream Park™ · 2026-06-20 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

业务流程天然适配:1 个订单生成任务,会同时触发「原料采购核验、设计制图、加工生产、质检、包装、物流」6 个并行工序,完美体现扇出模式。
珠宝全业务流程:
生产者:客户下单系统(生成珠宝订单任务)
扇出分发:将订单同步分发给 6 个独立工作器
工作器(Worker):
原料核验:检查金 / 钻石 / 宝石库存与资质
设计制图:生成 3D 设计图
加工生产:金工铸造、宝石镶嵌
品质质检:成色、纯度、工艺检测
礼盒包装:定制包装、证书装订
物流发货:生成快递单、安排配送

# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述: Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:52 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : settings.py
"""
配置层
全局配置文件
企业级:所有硬编码统一管理
"""
import queue

# 任务队列配置
TASK_QUEUE_MAX_SIZE = 100
TASK_QUEUE = queue.Queue(maxsize=TASK_QUEUE_MAX_SIZE)

# 业务配置
ORDER_SLEEP_TIME = 1  # 下单间隔



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述: Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:53 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : order.py
"""
模型层:类型安全
订单数据模型
使用 dataclass 保证类型约束,企业级规范
"""
from dataclasses import dataclass

@dataclass
class JewelryOrder:
    """
    实体
    """
    order_id: str
    product: str
    material: str
    style: str




# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述: Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:54 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : business_exc.py
"""
异常层
业务异常定义
"""
class JewelryBusinessException(Exception):
    """
    珠宝业务基础异常
    """
    pass

class WorkerExecuteException(JewelryBusinessException):
    """
    工作器执行异常
    """
    pass
# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述: Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:56 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : material.py

import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
    原料核验工作器
    :param order:
    :return:
    """
    print(f"[原料核验] 订单{order.order_id}:检查{order.material}库存、GIA证书")
    time.sleep(1)
    print(f"[原料核验] 订单{order.order_id}:核验完成 ✅")



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:56 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : design.py
import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
     珠宝设计工作器
    :param order:
    :return:
    """
    print(f"[设计制图] 订单{order.order_id}:生成{order.style}3D图")
    time.sleep(1.5)
    print(f"[设计制图] 订单{order.order_id}:设计定稿 ✅")



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:58 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : production.py
import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
     QC工作器
    :param order:
    :return:
    """
    print(f"[加工生产] 订单{order.order_id}:{order.product}铸造镶嵌")
    time.sleep(2)
    print(f"[加工生产] 订单{order.order_id}:生产完成 ✅")



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 8:59 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : quality.py
import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
    QC工作器
    :param order:
    :return:
    """
    print(f"[品质质检] 订单{order.order_id}:纯度/净度/工艺检测")
    time.sleep(1)
    print(f"[品质质检] 订单{order.order_id}:质检合格 ✅")



# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 9:00 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : packaging.py
import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
    编货工作器
    :param order:
    :return:
    """
    print(f"[礼盒包装] 订单{order.order_id}:定制礼盒+证书装订")
    time.sleep(0.8)
    print(f"[礼盒包装] 订单{order.order_id}:包装完成 ✅")


# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 9:00 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : logistics.py
import time
from FanOutPattern.models.order import JewelryOrder

def execute(order: JewelryOrder):
    """
    物流工作器
    :param order:
    :return:
    """
    print(f"[物流发货] 订单{order.order_id}:生成顺丰保价快递")
    time.sleep(0.5)
    print(f"[物流发货] 订单{order.order_id}:已发货 ✅")
# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 9:05 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : producer.py
"""
任务生产者:只负责生成订单
"""
import time
from FanOutPattern.config.settings import TASK_QUEUE, ORDER_SLEEP_TIME
from FanOutPattern.models.order import JewelryOrder

class OrderProducer:
    """
    生产者:单一职责
    """

    def __init__(self):
        self.orders = [
            JewelryOrder("J2025001", "18K金钻石戒指", "18K金+50分钻石", "经典六爪"),
            JewelryOrder("J2025002", "翡翠玉镯", "A货翡翠", "复古圆条"),
            JewelryOrder("J2025003", "铂金项链", "PT950铂金", "简约锁骨链")
        ]

    def produce(self):
        """
        生产订单并推入队列
        :return:
        """
        print("\n===== 客户订单开始生成 =====")
        for order in self.orders:
            print(f"📝 新订单:{order.product} | {order.order_id}")
            TASK_QUEUE.put(order)
            time.sleep(ORDER_SLEEP_TIME)

        # 结束信号
        TASK_QUEUE.put(None)
        print("===== 所有订单生成完成 =====")




# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Fan-Out Pattern Fan-Out 模式 扇出模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 9:06 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : dispatcher.py
"""
Fan-Out 分发核心
Fan-Out 分发器:只负责任务分发
企业级:解耦、可复用、可测试
"""
import threading
from FanOutPattern.config.settings import TASK_QUEUE
from FanOutPattern.models.order import JewelryOrder
from FanOutPattern.workers import WORKER_LIST

class FanOutDispatcher:
    """
    Fan-Out 分发核心
    """
    def __init__(self):
        self.workers = WORKER_LIST

    def _execute_worker_parallel(self, order: JewelryOrder):
        """
        扇出:并行执行所有工作器
        :param order:
        :return:
        """
        threads = []
        for worker in self.workers:
            t = threading.Thread(target=worker, args=(order,))
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

    def start(self):
        """
        启动分发器监听队列
        :return:
        """
        while True:
            order = TASK_QUEUE.get()
            if order is None:
                break

            print(f"\n===== 订单{order.order_id} 扇出分发启动 =====")
            self._execute_worker_parallel(order)
            print(f"===== 订单{order.order_id} 全流程完成 =====\n")
            TASK_QUEUE.task_done()

调用:

# encoding: utf-8 
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2024.3.6 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/20 9:08 
# User      :  geovindu
# Product   : PyCharm
# Project   : pydesginpattern
# File      : FanOutBll.py

"""
项目启动
企业级:简洁、清晰、唯一入口
"""
import threading
from FanOutPattern.core.producer import OrderProducer
from FanOutPattern.core.dispatcher import FanOutDispatcher

class FanOutBll(object):
    """
    业务处理
    """
    def demo(self):
        """

        :return:
        """
        print("=" * 60)
        print("   珠宝行业企业级 Fan-Out 分布式任务系统 启动成功")
        print("=" * 60)

        # 初始化核心组件
        producer = OrderProducer()
        dispatcher = FanOutDispatcher()

        # 启动分发器(后台线程)
        dispatcher_thread = threading.Thread(target=dispatcher.start)
        dispatcher_thread.start()

        # 启动生产者
        producer.produce()

        # 等待结束
        dispatcher_thread.join()

        print("\n" + "=" * 60)
        print("   所有订单处理完成,系统安全退出")
        print("=" * 60)

输出:

c8b152f8363ae9b643e4c875e8b1d35f

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)