sycommon-python-lib 0.1.0__py3-none-any.whl → 0.1.2__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/config/EmbeddingConfig.py +0 -1
- sycommon/config/MQConfig.py +15 -0
- sycommon/database/base_db_service.py +30 -0
- sycommon/logging/kafka_log.py +14 -38
- sycommon/middleware/middleware.py +4 -0
- sycommon/middleware/mq.py +9 -0
- sycommon/models/mqlistener_config.py +38 -0
- sycommon/models/mqmsg_model.py +11 -0
- sycommon/models/mqsend_config.py +8 -0
- sycommon/models/sso_user.py +60 -0
- sycommon/rabbitmq/rabbitmq_client.py +721 -0
- sycommon/rabbitmq/rabbitmq_service.py +476 -0
- sycommon/services.py +164 -20
- sycommon/synacos/feign.py +14 -10
- sycommon/synacos/nacos_service.py +252 -188
- {sycommon_python_lib-0.1.0.dist-info → sycommon_python_lib-0.1.2.dist-info}/METADATA +2 -2
- {sycommon_python_lib-0.1.0.dist-info → sycommon_python_lib-0.1.2.dist-info}/RECORD +19 -10
- {sycommon_python_lib-0.1.0.dist-info → sycommon_python_lib-0.1.2.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.1.0.dist-info → sycommon_python_lib-0.1.2.dist-info}/top_level.txt +0 -0
sycommon/synacos/feign.py
CHANGED
|
@@ -46,7 +46,7 @@ from sycommon.synacos.nacos_service import NacosService
|
|
|
46
46
|
# return None
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def feign_client(service_name: str, path_prefix: str = ""):
|
|
49
|
+
def feign_client(service_name: str, path_prefix: str = "", default_timeout: float | None = None):
|
|
50
50
|
# Feign风格客户端装饰器
|
|
51
51
|
"""声明式HTTP客户端装饰器"""
|
|
52
52
|
def decorator(cls):
|
|
@@ -56,6 +56,7 @@ def feign_client(service_name: str, path_prefix: str = ""):
|
|
|
56
56
|
self.nacos_manager = NacosService(None)
|
|
57
57
|
self.path_prefix = path_prefix
|
|
58
58
|
self.session = aiohttp.ClientSession()
|
|
59
|
+
self.default_timeout = default_timeout
|
|
59
60
|
|
|
60
61
|
def __getattr__(self, name):
|
|
61
62
|
func = getattr(cls, name)
|
|
@@ -67,6 +68,8 @@ def feign_client(service_name: str, path_prefix: str = ""):
|
|
|
67
68
|
path = request_meta.get("path", "")
|
|
68
69
|
headers = request_meta.get("headers", {})
|
|
69
70
|
|
|
71
|
+
timeout = kwargs.pop('timeout', self.default_timeout)
|
|
72
|
+
|
|
70
73
|
# 获取版本信息
|
|
71
74
|
version = headers.get('s-y-version')
|
|
72
75
|
|
|
@@ -120,7 +123,7 @@ def feign_client(service_name: str, path_prefix: str = ""):
|
|
|
120
123
|
headers=headers,
|
|
121
124
|
params=params,
|
|
122
125
|
data=data,
|
|
123
|
-
timeout=
|
|
126
|
+
timeout=timeout
|
|
124
127
|
) as response:
|
|
125
128
|
return await self._handle_response(response)
|
|
126
129
|
else:
|
|
@@ -131,7 +134,7 @@ def feign_client(service_name: str, path_prefix: str = ""):
|
|
|
131
134
|
headers=headers,
|
|
132
135
|
params=params,
|
|
133
136
|
json=body,
|
|
134
|
-
timeout=
|
|
137
|
+
timeout=timeout
|
|
135
138
|
) as response:
|
|
136
139
|
return await self._handle_response(response)
|
|
137
140
|
except Exception as e:
|
|
@@ -188,15 +191,15 @@ def feign_upload(field_name: str = "file"):
|
|
|
188
191
|
|
|
189
192
|
|
|
190
193
|
async def feign(service_name, api_path, method='GET', params=None, headers=None, file_path=None,
|
|
191
|
-
path_params=None,
|
|
194
|
+
path_params=None, body=None, files=None, form_data=None, timeout=None):
|
|
192
195
|
"""
|
|
193
|
-
feign 函数,支持 form-data
|
|
196
|
+
feign 函数,支持 form-data 表单上传文件和其他字段,支持自定义超时时间
|
|
194
197
|
|
|
195
198
|
参数:
|
|
196
199
|
files: 字典,用于上传文件,格式: {'field_name': (filename, file_content)}
|
|
197
200
|
form_data: 字典,用于上传表单字段
|
|
201
|
+
timeout: 超时时间(秒),None 表示不设置超时
|
|
198
202
|
"""
|
|
199
|
-
file_stream = None
|
|
200
203
|
session = aiohttp.ClientSession()
|
|
201
204
|
try:
|
|
202
205
|
# 获取健康的服务实例
|
|
@@ -259,7 +262,7 @@ async def feign(service_name, api_path, method='GET', params=None, headers=None,
|
|
|
259
262
|
headers=headers,
|
|
260
263
|
params=params,
|
|
261
264
|
data=data,
|
|
262
|
-
timeout=
|
|
265
|
+
timeout=timeout
|
|
263
266
|
) as response:
|
|
264
267
|
return await _handle_feign_response(response)
|
|
265
268
|
else:
|
|
@@ -272,7 +275,7 @@ async def feign(service_name, api_path, method='GET', params=None, headers=None,
|
|
|
272
275
|
headers=headers,
|
|
273
276
|
params=params,
|
|
274
277
|
json=body,
|
|
275
|
-
timeout=
|
|
278
|
+
timeout=timeout
|
|
276
279
|
) as response:
|
|
277
280
|
return await _handle_feign_response(response)
|
|
278
281
|
except aiohttp.ClientError as e:
|
|
@@ -281,8 +284,9 @@ async def feign(service_name, api_path, method='GET', params=None, headers=None,
|
|
|
281
284
|
print(f"请求服务接口时出错: {e}")
|
|
282
285
|
return None
|
|
283
286
|
except Exception as e:
|
|
284
|
-
|
|
285
|
-
|
|
287
|
+
import traceback
|
|
288
|
+
SYLogger.error(f"nacos:请求服务接口时出错: {traceback.format_exc()}")
|
|
289
|
+
print(f"nacos:请求服务接口时出错: {traceback.format_exc()}")
|
|
286
290
|
return None
|
|
287
291
|
finally:
|
|
288
292
|
SYLogger.info(f"nacos:结束调用服务: {service_name}, {api_path}")
|