aury-boot 0.0.36__py3-none-any.whl → 0.0.37__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aury/boot/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.36'
32
- __version_tuple__ = version_tuple = (0, 0, 36)
31
+ __version__ = version = '0.0.37'
32
+ __version_tuple__ = version_tuple = (0, 0, 37)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -147,13 +147,13 @@ class MQInstanceConfig(MultiInstanceSettings):
147
147
 
148
148
  环境变量格式: MQ__{INSTANCE}__{FIELD}
149
149
  示例:
150
- MQ__DEFAULT__BACKEND=redis
150
+ MQ__DEFAULT__BACKEND=redis_stream
151
151
  MQ__DEFAULT__URL=redis://localhost:6379/4
152
152
  """
153
153
 
154
154
  backend: str = Field(
155
- default="redis",
156
- description="消息队列后端 (redis/rabbitmq)"
155
+ default="redis_stream",
156
+ description="消息队列后端 (redis/redis_stream/rabbitmq)"
157
157
  )
158
158
  url: str | None = Field(
159
159
  default=None,
@@ -715,7 +715,7 @@ class AlertSettings(BaseModel):
715
715
 
716
716
  # 抑制配置
717
717
  suppress_seconds: int = Field(
718
- default=10,
718
+ default=300,
719
719
  description="告警抑制时间(秒),相同告警在此时间内不重复发送"
720
720
  )
721
721
 
@@ -707,8 +707,8 @@ def init(
707
707
  console.print(f" [cyan]uv add \"{deps[0]}\"[/cyan]")
708
708
  console.print()
709
709
  else:
710
- # 非交互模式:默认启用 Admin Console
711
- with_admin_console = True
710
+ # 非交互模式:默认禁用 Admin Console
711
+ with_admin_console = False
712
712
  if package_name == ".":
713
713
  package_name_snake = None
714
714
  elif package_name:
@@ -169,7 +169,7 @@ class BaseConfig(BaseSettings):
169
169
  )
170
170
  ```
171
171
 
172
- **环境变量命名规则**:`{SECTION}__{FIELD}`
172
+ **环境变量命名规则**:`{{SECTION}}__{{FIELD}}`
173
173
 
174
174
  ```bash
175
175
  # 示例
@@ -1,6 +1,6 @@
1
1
  # 消息队列(MQ)
2
2
 
3
- 支持 `redis` 和 `rabbitmq` 后端的消息队列,用于异步任务解耦。
3
+ 支持 `redis`、`redis_stream` 和 `rabbitmq` 后端的消息队列,用于异步任务解耦。
4
4
 
5
5
  ## 14.1 基本用法
6
6
 
@@ -10,93 +10,143 @@ from aury.boot.infrastructure.mq import MQManager
10
10
  # 获取实例
11
11
  mq = MQManager.get_instance()
12
12
 
13
- # Redis 后端
13
+ # Redis List 后端(简单队列)
14
14
  await mq.initialize(backend="redis", url="redis://localhost:6379/0")
15
15
 
16
+ # Redis Stream 后端(推荐,支持消费者组)
17
+ await mq.initialize(backend="redis_stream", url="redis://localhost:6379/0")
18
+
16
19
  # RabbitMQ 后端
17
20
  await mq.initialize(backend="rabbitmq", url="amqp://guest:guest@localhost:5672/")
18
21
  ```
19
22
 
20
- ## 14.2 生产者
23
+ ## 14.2 后端对比
24
+
25
+ **Redis List (redis)**:
26
+ - 简单的 FIFO 队列(LPUSH/BRPOP)
27
+ - 适合单消费者场景
28
+ - 消息不持久化(除非开启 AOF)
29
+
30
+ **Redis Stream (redis_stream)** ⭐ 推荐:
31
+ - 支持消费者组,多实例可并行消费
32
+ - 消息持久化(配合 AOF)
33
+ - 支持消息确认(ACK)和重试
34
+ - 支持消息回放和历史查询
35
+
36
+ **RabbitMQ (rabbitmq)**:
37
+ - 功能最完整的消息队列
38
+ - 支持多种交换机类型
39
+ - 适合复杂的消息路由场景
40
+
41
+ ## 14.3 生产者
21
42
 
22
43
  ```python
44
+ from aury.boot.infrastructure.mq import MQMessage
45
+
23
46
  # 发送消息
24
- await mq.publish(
47
+ await mq.send(
25
48
  queue="orders",
26
49
  message={{"order_id": "123", "action": "created"}}
27
50
  )
28
51
 
29
- # 批量发送
30
- await mq.publish_batch(
31
- queue="orders",
32
- messages=[
33
- {{"order_id": "1", "action": "created"}},
34
- {{"order_id": "2", "action": "updated"}},
35
- ]
52
+ # 使用 MQMessage 对象(可设置 headers)
53
+ msg = MQMessage(
54
+ body={{"order_id": "123"}},
55
+ headers={{"priority": "high"}}
36
56
  )
57
+ await mq.send("orders", msg)
37
58
  ```
38
59
 
39
- ## 14.3 消费者
60
+ ## 14.4 消费者
40
61
 
41
62
  **文件**: `{package_name}/workers/order_worker.py`
42
63
 
43
64
  ```python
44
- from aury.boot.infrastructure.mq import MQManager
65
+ from aury.boot.infrastructure.mq import MQManager, MQMessage
45
66
  from aury.boot.common.logging import logger
46
67
 
47
68
  mq = MQManager.get_instance()
48
69
 
49
70
 
50
- async def process_order(message: dict):
71
+ async def process_order(message: MQMessage):
51
72
  \"\"\"处理订单消息。\"\"\"
52
- logger.info(f"处理订单: {{message['order_id']}}")
73
+ logger.info(f"处理订单: {{message.body}}")
53
74
  # 业务逻辑...
54
75
 
55
76
 
56
77
  async def start_consumer():
57
78
  \"\"\"启动消费者。\"\"\"
79
+ # consume 会自动处理 ACK/NACK
58
80
  await mq.consume("orders", process_order)
81
+ ```
82
+
83
+ ## 14.5 Redis Stream 特性
59
84
 
85
+ ```python
86
+ from aury.boot.infrastructure.mq.backends.redis_stream import RedisStreamMQ
87
+
88
+ # 初始化时指定消费者组
89
+ mq = MQManager.get_instance()
90
+ await mq.initialize(
91
+ backend="redis_stream",
92
+ url="redis://localhost:6379/0"
93
+ )
94
+
95
+ # 获取底层 RedisStreamMQ 实例使用高级特性
96
+ stream_mq: RedisStreamMQ = mq.backend
60
97
 
61
- # 带确认的消费
62
- async def process_with_ack(message: dict, ack, nack):
63
- try:
64
- await process_order(message)
65
- await ack()
66
- except Exception:
67
- await nack(requeue=True)
98
+ # 读取所有历史消息(用于重放)
99
+ messages = await stream_mq.read_all("orders", count=100)
68
100
 
69
- await mq.consume("orders", process_with_ack, auto_ack=False)
101
+ # 阻塞读取新消息(用于 SSE/实时推送)
102
+ messages = await stream_mq.read_blocking(
103
+ "orders",
104
+ last_id="$", # 从最新消息开始
105
+ count=10,
106
+ block_ms=5000 # 阻塞 5 秒
107
+ )
108
+
109
+ # 裁剪 Stream(保留最新 1000 条)
110
+ await stream_mq.trim("orders", maxlen=1000)
111
+
112
+ # 获取 Stream 信息
113
+ info = await stream_mq.stream_info("orders")
70
114
  ```
71
115
 
72
- ## 14.4 多实例
116
+ ## 14.6 多实例配置
117
+
118
+ 框架支持命名多实例,适合不同业务场景使用不同的 MQ:
73
119
 
74
120
  ```python
75
- # 不同用途的 MQ 实例
121
+ # 代码中使用命名实例
76
122
  orders_mq = MQManager.get_instance("orders")
77
123
  notifications_mq = MQManager.get_instance("notifications")
78
124
 
79
125
  # 分别初始化
80
- await orders_mq.initialize(backend="rabbitmq", url="amqp://localhost:5672/orders")
81
- await notifications_mq.initialize(backend="redis", url="redis://localhost:6379/5")
126
+ await orders_mq.initialize(backend="redis_stream", url="redis://localhost:6379/1")
127
+ await notifications_mq.initialize(backend="redis", url="redis://localhost:6379/2")
82
128
  ```
83
129
 
84
- ## 14.5 环境变量
130
+ **环境变量配置**(自动初始化):
85
131
 
86
132
  ```bash
87
- # 默认实例
88
- MQ__BACKEND=redis
133
+ # 单实例配置
134
+ MQ__BACKEND=redis_stream
89
135
  MQ__URL=redis://localhost:6379/0
90
136
 
91
- # 多实例(格式:MQ__{{INSTANCE}}__{{FIELD}})
92
- MQ__DEFAULT__BACKEND=redis
137
+ # 多实例配置(格式:MQ__{{INSTANCE}}__{{FIELD}})
138
+ MQ__DEFAULT__BACKEND=redis_stream
93
139
  MQ__DEFAULT__URL=redis://localhost:6379/4
94
140
  MQ__ORDERS__BACKEND=rabbitmq
95
141
  MQ__ORDERS__URL=amqp://guest:guest@localhost:5672/
96
- MQ__ORDERS__PREFETCH_COUNT=10
97
142
  ```
98
143
 
99
- ## 14.6 与异步任务(Dramatiq)的区别
144
+ ## 14.7 与异步任务(Dramatiq)的区别
145
+
146
+ - **MQ**:轻量级消息传递,适合简单的生产者-消费者模式、实时通知、多实例消费
147
+ - **Dramatiq(TaskManager)**:功能更丰富,支持重试、延迟、优先级、Actor 模式
100
148
 
101
- - **MQ**:轻量级消息传递,适合简单的生产者-消费者模式
102
- - **Dramatiq(TaskManager)**:功能更丰富,支持重试、延迟、优先级等
149
+ 选择建议:
150
+ - 简单的异步解耦 → MQ (redis_stream)
151
+ - 需要重试/延迟/优先级 → Dramatiq
152
+ - 多服务实例并行消费 → MQ (redis_stream) 或 RabbitMQ
@@ -19,19 +19,27 @@
19
19
  # =============================================================================
20
20
  # 消息队列配置 (MQ__)
21
21
  # =============================================================================
22
+ # 支持后端: redis | redis_stream (推荐) | rabbitmq
23
+ #
22
24
  # 单实例配置:
23
- # MQ__ENABLED=false
24
- # MQ__BROKER_URL=redis://localhost:6379/4
25
-
25
+ # MQ__BACKEND=redis_stream
26
+ # MQ__URL=redis://localhost:6379/4
27
+ #
26
28
  # 多实例配置 (格式: MQ__{{INSTANCE}}__{{FIELD}}):
27
- # MQ__DEFAULT__BACKEND=redis
29
+ # MQ__DEFAULT__BACKEND=redis_stream
28
30
  # MQ__DEFAULT__URL=redis://localhost:6379/4
29
- # MQ__DEFAULT__MAX_CONNECTIONS=10
30
31
  #
31
- # RabbitMQ 后端:
32
+ # Redis List 后端 (简单 FIFO 队列):
33
+ # MQ__SIMPLE__BACKEND=redis
34
+ # MQ__SIMPLE__URL=redis://localhost:6379/4
35
+ #
36
+ # Redis Stream 后端 (推荐,支持消费者组/多实例消费):
37
+ # MQ__TASKS__BACKEND=redis_stream
38
+ # MQ__TASKS__URL=redis://localhost:6379/4
39
+ #
40
+ # RabbitMQ 后端 (复杂消息路由):
32
41
  # MQ__ORDERS__BACKEND=rabbitmq
33
42
  # MQ__ORDERS__URL=amqp://guest:guest@localhost:5672/orders
34
- # MQ__ORDERS__PREFETCH_COUNT=10
35
43
 
36
44
  # =============================================================================
37
45
  # 事件总线配置 (EVENT__)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aury-boot
3
- Version: 0.0.36
3
+ Version: 0.0.37
4
4
  Summary: Aury Boot - 基于 FastAPI 生态的企业级 API 开发框架
5
5
  Requires-Python: >=3.13
6
6
  Requires-Dist: alembic>=1.17.2
@@ -1,5 +1,5 @@
1
1
  aury/boot/__init__.py,sha256=pCno-EInnpIBa1OtxNYF-JWf9j95Cd2h6vmu0xqa_-4,1791
2
- aury/boot/_version.py,sha256=0ktbVh2xRI7xnrojV_sDPVhrN753EK8vWN68JQalwWk,706
2
+ aury/boot/_version.py,sha256=BV1Ma7idHU0hCvzfaqU-vGA4N-4x9mQtKafasKpzadA,706
3
3
  aury/boot/application/__init__.py,sha256=I2KqNVdYg2q5nlOXr0TtFGyHmhj4oWdaR6ZB73Mwg7Y,3041
4
4
  aury/boot/application/adapter/__init__.py,sha256=e1bcSb1bxUMfofTwiCuHBZJk5-STkMCWPF2EJXHQ7UU,3976
5
5
  aury/boot/application/adapter/base.py,sha256=Ar_66fiHPDEmV-1DKnqXKwc53p3pozG31bgTJTEUriY,15763
@@ -14,7 +14,7 @@ aury/boot/application/app/middlewares.py,sha256=BXe2H14FHzJUVpQM6DZUm-zfZRXSXIi1
14
14
  aury/boot/application/app/startup.py,sha256=DHKt3C2G7V5XfFr1SQMl14tNzcuDd9MqUVAxi274HDQ,7873
15
15
  aury/boot/application/config/__init__.py,sha256=Dd-myRSBCM18DXXsi863h0cJG5VFrI10xMRtjnvelGo,1894
16
16
  aury/boot/application/config/multi_instance.py,sha256=RXSp-xP8-bKMDEhq3SeL7T3lS8-vpRlvBEVBuZVjVK4,6475
17
- aury/boot/application/config/settings.py,sha256=YxcR75SxdjJznJ1813sK4dhUPJ5ac5ATvGuT6IbNst0,37998
17
+ aury/boot/application/config/settings.py,sha256=JZuLVKH13cuBdlHdtrt7ZZ4d7KD8as5DWBv0d9enHDk,38026
18
18
  aury/boot/application/constants/__init__.py,sha256=DCXs13_VVaQWHqO-qpJoZwRd7HIexiirtw_nu8msTXE,340
19
19
  aury/boot/application/constants/components.py,sha256=I4SlsF2DpSzMiLsi1wVrEmdHn4yV5J2h3ikMQqufPmM,1120
20
20
  aury/boot/application/constants/scheduler.py,sha256=S77FBIvHlyruvlabRWZJ2J1YAs2xWXPQI2yuGdGUDNA,471
@@ -47,7 +47,7 @@ aury/boot/commands/config.py,sha256=gPkG_jSWrXidjpyVdzABH7uRhoCgX5yrOcdKabtX5wY,
47
47
  aury/boot/commands/docker.py,sha256=7mKorZCPZgxH1XFslzo6W-uzpe61hGXz86JKOhOeBlo,9006
48
48
  aury/boot/commands/docs.py,sha256=Hz1W-2TW8DzaPxARqEF4UncPhGMI9h97jJ962dlox3U,14327
49
49
  aury/boot/commands/generate.py,sha256=WZieSXuofxJOC7NBiVGpBigB9NZ4GMcF2F1ReTNun1I,44420
50
- aury/boot/commands/init.py,sha256=W_eCL3wydWaMSLqTpadREDnzC0w-LGgNnj3IBjuQAfA,32348
50
+ aury/boot/commands/init.py,sha256=6reBpZ5jS4O9QTfXHKt4MCXPn3WcubjUfOtB5tKdy0s,32349
51
51
  aury/boot/commands/pkg.py,sha256=bw0QPptKscNgQ4I1SfSehTio9Q5KrvxgvkYx4tbZ7Vs,14495
52
52
  aury/boot/commands/scheduler.py,sha256=XO3Gq7PqNxXNz5Gw0xNUHa_bEnAKZ9AkzLc062QJ3j8,3669
53
53
  aury/boot/commands/worker.py,sha256=OEvfDiiM_pV3Mj73HKhSm1RNqFPuS125iNM0qNCTHFY,4316
@@ -61,7 +61,7 @@ aury/boot/commands/templates/generate/model.py.tpl,sha256=knFwMyGZ7wMpzH4_bQD_V1
61
61
  aury/boot/commands/templates/generate/repository.py.tpl,sha256=Uj9jNEI9Zn8W061FGFlRaIfAy9IhdassYH6noEjG0z0,662
62
62
  aury/boot/commands/templates/generate/schema.py.tpl,sha256=HIaY5B0UG_S188nQLrZDEJ0q73WPdb7BmCdc0tseZA4,545
63
63
  aury/boot/commands/templates/generate/service.py.tpl,sha256=2hwQ8e4a5d_bIMx_jGDobdmKPMFLBlfQrQVQH4Ym5k4,1842
64
- aury/boot/commands/templates/project/AGENTS.md.tpl,sha256=sp5qyzU-SGhgQCobpMW4EXRzpGsEsVdmJvspnKAP4AQ,10059
64
+ aury/boot/commands/templates/project/AGENTS.md.tpl,sha256=KdCqZJeI6cRwjTxX0B2u9fcGQKUi2fJrIjTJBkm3c4U,10063
65
65
  aury/boot/commands/templates/project/README.md.tpl,sha256=oCeBiukk6Pa3hrCKybkfM2sIRHsPZ15nlwuFTUSFDwY,2459
66
66
  aury/boot/commands/templates/project/admin_console_init.py.tpl,sha256=K81L14thyEhRA8lFCQJVZL_NU22-sBz0xS68MJPeoCo,1541
67
67
  aury/boot/commands/templates/project/alert_rules.example.yaml.tpl,sha256=QZH6SC5TcUhgX_2JRXk0k0g26wJf9xNwsdquiEIgg-I,2492
@@ -83,7 +83,7 @@ aury/boot/commands/templates/project/aury_docs/10-storage.md.tpl,sha256=mhe0j0S5
83
83
  aury/boot/commands/templates/project/aury_docs/11-logging.md.tpl,sha256=bwxFCGQsO9cTEbwqJF1xcjsZKP82HRWhIMRUS0c9_ZI,2435
84
84
  aury/boot/commands/templates/project/aury_docs/12-admin.md.tpl,sha256=6z3mN54qP2jtpTFOJBLVexvEv0ZHXYKjncvpZG4yOdw,1883
85
85
  aury/boot/commands/templates/project/aury_docs/13-channel.md.tpl,sha256=aGpf2phQBMRs6Uh1DfjNl06pC_niea91Sm8sTq_NFec,4443
86
- aury/boot/commands/templates/project/aury_docs/14-mq.md.tpl,sha256=4bxLQBbCi0Fue0VQWOPt6acZ5P00BoLkCoLPQe_8k4U,2396
86
+ aury/boot/commands/templates/project/aury_docs/14-mq.md.tpl,sha256=irrKal6y8pPAjifntnOLfRzzllvBQinKMjIjKd-_ANc,4016
87
87
  aury/boot/commands/templates/project/aury_docs/15-events.md.tpl,sha256=a4wQRgVPuYUGTGmw_lX1HJH_yFTbD30mBz7Arc4zgfs,3361
88
88
  aury/boot/commands/templates/project/aury_docs/16-adapter.md.tpl,sha256=pkmJkZw2Ca6_uYk2jZvAb8DozjBa2tWq_t3gtq1lFSk,11456
89
89
  aury/boot/commands/templates/project/aury_docs/17-alerting.md.tpl,sha256=2MosApSAuGerBw7SOO-ihk4NTp2qEkgOUyu6pS2m0UY,5709
@@ -93,7 +93,7 @@ aury/boot/commands/templates/project/env_templates/admin.tpl,sha256=wWt3iybOpBHt
93
93
  aury/boot/commands/templates/project/env_templates/cache.tpl,sha256=_sK-p_FECj4mVvggNvgb4Wu0yGii0Ocz560syG7DU2c,498
94
94
  aury/boot/commands/templates/project/env_templates/database.tpl,sha256=2lWzTKt4X0SpeBBCkrDV90Di4EfoAuqYzhVsh74vTUI,907
95
95
  aury/boot/commands/templates/project/env_templates/log.tpl,sha256=x5rkrEFJISH0gaCcr-wTCbDYtyFnlLNJpY789fqjZgc,754
96
- aury/boot/commands/templates/project/env_templates/messaging.tpl,sha256=SzPRKwN0wO5e1kpjkSwpPJfVmiUDzZkK4Qm-qNsCvVE,2178
96
+ aury/boot/commands/templates/project/env_templates/messaging.tpl,sha256=AgfsXTRnvDySFERoCVop89jsC_h8hzj1sPeq5MczSXM,2462
97
97
  aury/boot/commands/templates/project/env_templates/monitoring.tpl,sha256=Zq0xQzDrCRtbeLCQB3pkEE2p8FFED6IjQo4TqMyd_P8,2584
98
98
  aury/boot/commands/templates/project/env_templates/rpc.tpl,sha256=FhweCFakawGLSs01a_BkmZo11UhWax2-VCBudHj68WA,1163
99
99
  aury/boot/commands/templates/project/env_templates/scheduler.tpl,sha256=c8Grcs1rgBB58RHlxqmDMPHQl8BnbcqNW473ctmsojU,752
@@ -210,7 +210,7 @@ aury/boot/testing/client.py,sha256=KOg1EemuIVsBG68G5y0DjSxZGcIQVdWQ4ASaHE3o1R0,4
210
210
  aury/boot/testing/factory.py,sha256=8GvwX9qIDu0L65gzJMlrWB0xbmJ-7zPHuwk3eECULcg,5185
211
211
  aury/boot/toolkit/__init__.py,sha256=AcyVb9fDf3CaEmJPNkWC4iGv32qCPyk4BuFKSuNiJRQ,334
212
212
  aury/boot/toolkit/http/__init__.py,sha256=zIPmpIZ9Qbqe25VmEr7jixoY2fkRbLm7NkCB9vKpg6I,11039
213
- aury_boot-0.0.36.dist-info/METADATA,sha256=dyV3mpOq5ZzkAUCbQdLt4Bmxw_vyLSyNcuUaJOtF6B8,8694
214
- aury_boot-0.0.36.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
215
- aury_boot-0.0.36.dist-info/entry_points.txt,sha256=f9KXEkDIGc0BGkgBvsNx_HMz9VhDjNxu26q00jUpDwQ,49
216
- aury_boot-0.0.36.dist-info/RECORD,,
213
+ aury_boot-0.0.37.dist-info/METADATA,sha256=8Kgz7a5fhou-Ki53QzjfwAfv68cE8iu83UWQ8aR6BOI,8694
214
+ aury_boot-0.0.37.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
215
+ aury_boot-0.0.37.dist-info/entry_points.txt,sha256=f9KXEkDIGc0BGkgBvsNx_HMz9VhDjNxu26q00jUpDwQ,49
216
+ aury_boot-0.0.37.dist-info/RECORD,,