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

推荐订阅源

D
DataBreaches.Net
IT之家
IT之家
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
L
LangChain Blog
博客园 - Franky
美团技术团队
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
小众软件
小众软件
Y
Y Combinator Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News

博客园 - ®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 python: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In
go: Broadcast Pattern
®Geovin Du Dream Park™ · 2026-06-08 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

6d4a3cce-b010-4d58-a91f-fc65fb5a9d7e

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:25
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : model.go
*/
package message

// JewelryMessage 珠宝行业标准广播消息
type JewelryMessage struct {
	Title             string // 消息标题
	Content           string // 消息内容
	Product           string // 产品名称
	Material          string // 原料
	Batch             string // 批次
	Standard          string // 质检标准
	WarehouseLocation string // 仓位
	MarketingContent  string // 营销内容
}




/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:26
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : errors.go
*/
package core

import "errors"

// 广播相关错误
var (
	ErrSubscriberNil = errors.New("订阅者不能为空")
	ErrSubscriberDup = errors.New("订阅者已存在")
)



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:26
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : subscriber.go
*/
package iface

import "godesginpattern/broadcast/message"

// Subscriber 订阅者接口(所有业务系统必须实现)
type Subscriber interface {
	Name() string                         // 系统名称
	OnReceive(msg message.JewelryMessage) // 接收广播消息
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:27
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : broadcast.go
*/
package core

import (
	"fmt"
	"godesginpattern/broadcast/iface"
	"godesginpattern/broadcast/message"
	"sync"
)

// BroadcastEngine 广播引擎(单例)
type BroadcastEngine struct {
	subscribers []iface.Subscriber
	lock        sync.RWMutex // 线程安全
}

var instance *BroadcastEngine
var once sync.Once

// NewBroadcastEngine 单例模式获取全局广播引擎
func NewBroadcastEngine() *BroadcastEngine {
	once.Do(func() {
		instance = &BroadcastEngine{
			subscribers: make([]iface.Subscriber, 0),
		}
	})
	return instance
}

// Subscribe 订阅广播
func (e *BroadcastEngine) Subscribe(sub iface.Subscriber) error {
	if sub == nil {
		return ErrSubscriberNil
	}

	e.lock.Lock()
	defer e.lock.Unlock()

	// 去重
	for _, s := range e.subscribers {
		if s.Name() == sub.Name() {
			return ErrSubscriberDup
		}
	}

	e.subscribers = append(e.subscribers, sub)
	return nil
}

// Broadcast 向所有订阅者广播消息
func (e *BroadcastEngine) Broadcast(msg message.JewelryMessage) {
	e.lock.RLock()
	defer e.lock.RUnlock()

	fmt.Println("\n=============================================")
	fmt.Println("📢 广播引擎开始全局广播:", msg.Title)
	fmt.Println("📄 消息内容:", msg.Content)
	fmt.Println("=============================================\n")

	// 同步发送给所有订阅者
	for _, sub := range e.subscribers {
		sub.OnReceive(msg)
	}
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:27
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : procurement.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// ProcurementSystem 原料采购系统
type ProcurementSystem struct{}

func (p *ProcurementSystem) Name() string {
	return "原料采购系统"
}

func (p *ProcurementSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("📦【", p.Name(), "】已同步原料溯源:", msg.Material)
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:28
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : production.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// ProductionSystem 生产加工系统
type ProductionSystem struct{}

func (p *ProductionSystem) Name() string {
	return "生产加工系统"
}

func (p *ProductionSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("⚙️【", p.Name(), "】已排产:", msg.Product, " 批次 ", msg.Batch)
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:28
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : quality.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// QCSystem 质量检测系统
type QCSystem struct{}

func (q *QCSystem) Name() string {
	return "质量检测系统"
}

func (q *QCSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("🔍【", q.Name(), "】已加载质检标准:", msg.Standard)
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:29
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : warehouse.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// WarehouseSystem 仓储管理系统
type WarehouseSystem struct{}

func (w *WarehouseSystem) Name() string {
	return "仓储管理系统"
}

func (w *WarehouseSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("📦【", w.Name(), "】已预留仓位:", msg.WarehouseLocation)
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:29
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : sales.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// StoreSalesSystem 全国门店销售系统
type StoreSalesSystem struct{}

func (s *StoreSalesSystem) Name() string {
	return "全国门店销售系统"
}

func (s *StoreSalesSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("🏬【", s.Name(), "】已上架新品:", msg.Product)
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:29
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : marketing.go
*/
package business

import (
	"fmt"
	"godesginpattern/broadcast/message"
)

// MemberMarketingSystem 会员营销系统
type MemberMarketingSystem struct{}

func (m *MemberMarketingSystem) Name() string {
	return "会员营销系统"
}

func (m *MemberMarketingSystem) OnReceive(msg message.JewelryMessage) {
	fmt.Println("🎯【", m.Name(), "】已推送:", msg.MarketingContent)
}

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Broadcast Pattern  广播模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/8 22:30
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : broadcastbll.go
*/
package bll

import (
	"fmt"
	"godesginpattern/broadcast/business"
	"godesginpattern/broadcast/core"
	"godesginpattern/broadcast/iface"
	"godesginpattern/broadcast/message"
)

func BroadcastMain() {
	// 1. 获取全局单例广播引擎
	engine := core.NewBroadcastEngine()

	// 2. 初始化所有珠宝业务系统
	systems := []iface.Subscriber{
		&business.ProcurementSystem{},
		&business.ProductionSystem{},
		&business.QCSystem{},
		&business.WarehouseSystem{},
		&business.StoreSalesSystem{},
		&business.MemberMarketingSystem{},
	}

	// 3. 订阅广播
	for _, sys := range systems {
		if err := engine.Subscribe(sys); err != nil {
			fmt.Println("❌ 订阅失败:", sys.Name(), " 错误:", err.Error())
			continue
		}
		fmt.Println("✅ 已订阅:", sys.Name())
	}

	// 4. 构造标准广播消息
	msg := message.JewelryMessage{
		Title:             "2025春季冰种翡翠手镯全国上市",
		Content:           "天然A货翡翠,统一标准、统一定价、同步发售",
		Product:           "冰种翡翠手镯",
		Material:          "缅甸天然翡翠",
		Batch:             "JC20250415-001",
		Standard:          "GB/T 16552-2017 珠宝玉石鉴定",
		WarehouseLocation: "广州总部仓-A03-07",
		MarketingContent:  "VIP会员专享9折+免费刻字",
	}

	// 5. 执行全局广播
	engine.Broadcast(msg)

	fmt.Println("\n🎉 企业级广播完成:全业务链同步成功")
}

输出:

226e99a5-b2db-40bf-b2b4-d38f2aa9368b

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