sycommon-python-lib 0.1.57b5__py3-none-any.whl → 0.1.57b6__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.
- sycommon/rabbitmq/rabbitmq_client.py +29 -27
- {sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/METADATA +1 -1
- {sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/RECORD +6 -6
- {sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/top_level.txt +0 -0
|
@@ -257,9 +257,9 @@ class RabbitMQClient:
|
|
|
257
257
|
|
|
258
258
|
async def _process_message_callback(self, message: AbstractIncomingMessage):
|
|
259
259
|
# 记录消息的原始追踪ID
|
|
260
|
-
original_trace_id = message.headers.get(
|
|
261
|
-
|
|
262
|
-
current_retry = 0
|
|
260
|
+
# original_trace_id = message.headers.get(
|
|
261
|
+
# "trace-id") if message.headers else None
|
|
262
|
+
# current_retry = 0
|
|
263
263
|
|
|
264
264
|
try:
|
|
265
265
|
msg_obj: MQMsgModel
|
|
@@ -278,12 +278,13 @@ class RabbitMQClient:
|
|
|
278
278
|
body=message.body.decode("utf-8"),
|
|
279
279
|
routing_key=message.routing_key,
|
|
280
280
|
delivery_tag=message.delivery_tag,
|
|
281
|
-
traceId=
|
|
281
|
+
traceId=message.headers.get(
|
|
282
|
+
"trace-id") if message.headers else SYLogger.get_trace_id(),
|
|
282
283
|
)
|
|
283
284
|
|
|
284
285
|
# 2. 设置日志上下文
|
|
285
286
|
# 注意:如果 header 中有 x-last-retry-ts,说明之前重试过
|
|
286
|
-
current_retry = int(message.headers.get("x-retry-count", 0))
|
|
287
|
+
# current_retry = int(message.headers.get("x-retry-count", 0))
|
|
287
288
|
SYLogger.set_trace_id(msg_obj.traceId)
|
|
288
289
|
|
|
289
290
|
# 3. 执行业务逻辑
|
|
@@ -294,28 +295,29 @@ class RabbitMQClient:
|
|
|
294
295
|
await message.ack()
|
|
295
296
|
|
|
296
297
|
except Exception as e:
|
|
297
|
-
logger.error(f"消息处理异常 (第 {current_retry} 次尝试): {e}", exc_info=True)
|
|
298
|
-
|
|
299
|
-
# 【核心修复】使用原生 Nack + Requeue
|
|
300
|
-
if current_retry >= 3:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
else:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
298
|
+
# logger.error(f"消息处理异常 (第 {current_retry} 次尝试): {e}", exc_info=True)
|
|
299
|
+
|
|
300
|
+
# # 【核心修复】使用原生 Nack + Requeue
|
|
301
|
+
# if current_retry >= 3:
|
|
302
|
+
# # 超过重试次数,丢弃消息(或进入死信队列)
|
|
303
|
+
# logger.warning(f"重试次数超限 (3次),丢弃消息: {message.delivery_tag}")
|
|
304
|
+
# await message.reject(requeue=False)
|
|
305
|
+
# else:
|
|
306
|
+
# # 还没到重试上限,重新入队
|
|
307
|
+
# # 为了防止立即重试导致的死循环,我们需要人为增加一点延迟
|
|
308
|
+
# # 但 Nack 本身不支持延迟,所以这里只能快速 Nack 让它尽快回来,
|
|
309
|
+
# # 并在业务层(或外层)做好限流保护。
|
|
310
|
+
|
|
311
|
+
# # 如果你有延迟队列插件,可以 publish 到延迟交换机。
|
|
312
|
+
# # 如果没有,直接 requeue 是最安全的不丢包方案。
|
|
313
|
+
# logger.info(f"消息处理失败,重新入队等待重试... (当前重试: {current_retry})")
|
|
314
|
+
|
|
315
|
+
# # 技巧:如果你不想立即重试,可以 Nack(False) 然后手动 Publish 延迟消息
|
|
316
|
+
# # 但为了解决你当前的“死循环”问题,直接 Nack(True) 是最有效的
|
|
317
|
+
# # 延迟5秒
|
|
318
|
+
# await asyncio.sleep(5)
|
|
319
|
+
# await message.nack(requeue=True)
|
|
320
|
+
await message.ack()
|
|
319
321
|
|
|
320
322
|
async def start_consuming(self) -> Optional[ConsumerTag]:
|
|
321
323
|
if self._closed:
|
|
@@ -51,7 +51,7 @@ sycommon/models/mqsend_config.py,sha256=NQX9dc8PpuquMG36GCVhJe8omAW1KVXXqr6lSRU6
|
|
|
51
51
|
sycommon/models/sso_user.py,sha256=i1WAN6k5sPcPApQEdtjpWDy7VrzWLpOrOQewGLGoGIw,2702
|
|
52
52
|
sycommon/notice/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
53
53
|
sycommon/notice/uvicorn_monitor.py,sha256=VryQYcAtjijJuGDBimbVurgwxlsLaLtkNnABPDY5Tao,7332
|
|
54
|
-
sycommon/rabbitmq/rabbitmq_client.py,sha256=
|
|
54
|
+
sycommon/rabbitmq/rabbitmq_client.py,sha256=XN_I-W2PWqjpxk_DrvsgVEHQaWQ1S7Y-N2_psNAFbg8,18833
|
|
55
55
|
sycommon/rabbitmq/rabbitmq_pool.py,sha256=BiFQgZPzSAFR-n5XhyIafoeWQXETF_31nFRDhMbe6aU,15577
|
|
56
56
|
sycommon/rabbitmq/rabbitmq_service.py,sha256=XSHo9HuIJ_lq-vizRh4xJVdZr_2zLqeLhot09qb0euA,2025
|
|
57
57
|
sycommon/rabbitmq/rabbitmq_service_client_manager.py,sha256=IP9TMFeG5LSrwFPEmOy1ce4baPxBUZnWJZR3nN_-XR4,8009
|
|
@@ -82,8 +82,8 @@ sycommon/tools/env.py,sha256=Ah-tBwG2C0_hwLGFebVQgKdWWXCjTzBuF23gCkLHYy4,2437
|
|
|
82
82
|
sycommon/tools/merge_headers.py,sha256=u9u8_1ZIuGIminWsw45YJ5qnsx9MB-Fot0VPge7itPw,4941
|
|
83
83
|
sycommon/tools/snowflake.py,sha256=xQlYXwYnI85kSJ1rZ89gMVBhzemP03xrMPVX9vVa3MY,9228
|
|
84
84
|
sycommon/tools/timing.py,sha256=OiiE7P07lRoMzX9kzb8sZU9cDb0zNnqIlY5pWqHcnkY,2064
|
|
85
|
-
sycommon_python_lib-0.1.
|
|
86
|
-
sycommon_python_lib-0.1.
|
|
87
|
-
sycommon_python_lib-0.1.
|
|
88
|
-
sycommon_python_lib-0.1.
|
|
89
|
-
sycommon_python_lib-0.1.
|
|
85
|
+
sycommon_python_lib-0.1.57b6.dist-info/METADATA,sha256=7jdIE6yCJt89yjcZoBiDUujDJijuyL3x1U8NRH-Tir4,7301
|
|
86
|
+
sycommon_python_lib-0.1.57b6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
87
|
+
sycommon_python_lib-0.1.57b6.dist-info/entry_points.txt,sha256=q_h2nbvhhmdnsOUZEIwpuoDjaNfBF9XqppDEmQn9d_A,46
|
|
88
|
+
sycommon_python_lib-0.1.57b6.dist-info/top_level.txt,sha256=98CJ-cyM2WIKxLz-Pf0AitWLhJyrfXvyY8slwjTXNuc,17
|
|
89
|
+
sycommon_python_lib-0.1.57b6.dist-info/RECORD,,
|
|
File without changes
|
{sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{sycommon_python_lib-0.1.57b5.dist-info → sycommon_python_lib-0.1.57b6.dist-info}/top_level.txt
RENAMED
|
File without changes
|