funboost 44.1__py3-none-any.whl → 44.3__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.
Potentially problematic release.
This version of funboost might be problematic. Click here for more details.
- funboost/__init__.py +1 -1
- funboost/consumers/base_consumer.py +25 -15
- funboost/consumers/http_consumer.py +10 -10
- funboost/consumers/http_consumer000.py +1 -2
- funboost/consumers/httpsqs_consumer.py +1 -1
- funboost/consumers/kafka_consumer.py +13 -15
- funboost/consumers/kafka_consumer_manually_commit.py +12 -15
- funboost/consumers/kombu_consumer.py +0 -1
- funboost/consumers/local_python_queue_consumer.py +2 -3
- funboost/consumers/memory_deque_consumer.py +0 -3
- funboost/consumers/mongomq_consumer.py +0 -1
- funboost/consumers/mqtt_consumer.py +4 -3
- funboost/consumers/nats_consumer.py +6 -5
- funboost/consumers/nsq_consumer.py +7 -6
- funboost/consumers/peewee_conusmer.py +1 -2
- funboost/consumers/persist_queue_consumer.py +1 -2
- funboost/consumers/pulsar_consumer.py +1 -2
- funboost/consumers/rabbitmq_amqpstorm_consumer.py +0 -2
- funboost/consumers/rabbitmq_pika_consumer.py +0 -2
- funboost/consumers/rabbitmq_pika_consumerv0.py +0 -1
- funboost/consumers/rabbitmq_rabbitpy_consumer.py +1 -2
- funboost/consumers/redis_brpoplpush_consumer.py +1 -3
- funboost/consumers/redis_consumer.py +4 -8
- funboost/consumers/redis_consumer_ack_able.py +5 -10
- funboost/consumers/redis_consumer_priority.py +3 -7
- funboost/consumers/redis_consumer_simple.py +2 -3
- funboost/consumers/redis_pubsub_consumer.py +3 -3
- funboost/consumers/redis_stream_consumer.py +3 -3
- funboost/consumers/rocketmq_consumer.py +2 -2
- funboost/consumers/sqlachemy_consumer.py +1 -1
- funboost/consumers/tcp_consumer.py +2 -2
- funboost/consumers/txt_file_consumer.py +2 -2
- funboost/consumers/udp_consumer.py +2 -2
- funboost/consumers/zeromq_consumer.py +13 -13
- funboost/core/cli/discovery_boosters.py +2 -2
- funboost/core/funboost_config_getter.py +7 -0
- funboost/core/funboost_time.py +28 -0
- funboost/core/helper_funs.py +21 -9
- funboost/core/lazy_impoter.py +108 -33
- funboost/core/loggers.py +1 -1
- funboost/core/muliti_process_enhance.py +3 -3
- funboost/function_result_web/app.py +3 -0
- funboost/function_result_web/functions.py +0 -1
- funboost/publishers/base_publisher.py +4 -7
- funboost/publishers/confluent_kafka_publisher.py +9 -12
- funboost/publishers/kafka_publisher.py +5 -11
- funboost/publishers/mqtt_publisher.py +3 -2
- funboost/publishers/nats_publisher.py +2 -2
- funboost/publishers/nsq_publisher.py +4 -6
- funboost/publishers/zeromq_publisher.py +3 -3
- funboost/set_frame_config.py +1 -1
- funboost/utils/bulk_operation.py +3 -2
- funboost/utils/decorators.py +14 -2
- funboost/utils/paramiko_util.py +1 -1
- funboost/utils/resource_monitoring.py +10 -9
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/METADATA +34 -17
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/RECORD +61 -60
- funboost/core/try_get_user_funboost_common_config.py +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/LICENSE +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/WHEEL +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/entry_points.txt +0 -0
- {funboost-44.1.dist-info → funboost-44.3.dist-info}/top_level.txt +0 -0
funboost/__init__.py
CHANGED
|
@@ -49,7 +49,7 @@ from funboost.concurrent_pool.single_thread_executor import SoloExecutor
|
|
|
49
49
|
|
|
50
50
|
from funboost.core.function_result_status_saver import ResultPersistenceHelper, FunctionResultStatus, RunStatus
|
|
51
51
|
|
|
52
|
-
from funboost.core.helper_funs import delete_keys_and_return_new_dict, get_publish_time,
|
|
52
|
+
from funboost.core.helper_funs import delete_keys_and_return_new_dict, get_publish_time, MsgGenerater
|
|
53
53
|
|
|
54
54
|
from funboost.concurrent_pool.async_helper import simple_run_in_executor
|
|
55
55
|
from funboost.concurrent_pool.async_pool_executor import AsyncPoolExecutor
|
|
@@ -71,7 +71,7 @@ from funboost.core import kill_remote_task
|
|
|
71
71
|
from funboost.core.exceptions import ExceptionForRequeue, ExceptionForPushToDlxqueue
|
|
72
72
|
|
|
73
73
|
# from funboost.core.booster import BoostersManager 互相导入
|
|
74
|
-
from funboost.core.lazy_impoter import
|
|
74
|
+
from funboost.core.lazy_impoter import funboost_lazy_impoter
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
# patch_apscheduler_run_job()
|
|
@@ -174,6 +174,7 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
174
174
|
broker_exclusive_config_merge = dict()
|
|
175
175
|
broker_exclusive_config_merge.update(self.BROKER_EXCLUSIVE_CONFIG_DEFAULT)
|
|
176
176
|
broker_exclusive_config_merge.update(self.consumer_params.broker_exclusive_config)
|
|
177
|
+
# print(broker_exclusive_config_merge)
|
|
177
178
|
self.consumer_params.broker_exclusive_config = broker_exclusive_config_merge
|
|
178
179
|
|
|
179
180
|
self._stop_flag = None
|
|
@@ -222,7 +223,7 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
222
223
|
# log_filename=consumer_params.log_filename,
|
|
223
224
|
# logger_name=consumer_params.logger_name,
|
|
224
225
|
# broker_exclusive_config=self.consumer_params.broker_exclusive_config)
|
|
225
|
-
self.publisher_params = BaseJsonAbleModel.init_by_another_model(PublisherParams, consumer_params)
|
|
226
|
+
self.publisher_params = BaseJsonAbleModel.init_by_another_model(PublisherParams, self.consumer_params)
|
|
226
227
|
# print(self.publisher_params)
|
|
227
228
|
if is_main_process:
|
|
228
229
|
self.logger.info(f'{self.queue_name} consumer 的消费者配置:\n {self.consumer_params.json_str_value()}')
|
|
@@ -322,11 +323,11 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
322
323
|
# ConsumersManager.show_all_consumer_info()
|
|
323
324
|
# noinspection PyBroadException
|
|
324
325
|
pid_queue_name_tuple = (os.getpid(), self.queue_name)
|
|
325
|
-
if pid_queue_name_tuple in
|
|
326
|
+
if pid_queue_name_tuple in funboost_lazy_impoter.BoostersManager.pid_queue_name__has_start_consume_set:
|
|
326
327
|
self.logger.warning(f'{pid_queue_name_tuple} 已启动消费,不要一直去启动消费,funboost框架自动阻止.') # 有的人乱写代码,无数次在函数内部或for循环里面执行 f.consume(),一个队列只需要启动一次消费,不然每启动一次性能消耗很大,直到程序崩溃
|
|
327
328
|
return
|
|
328
329
|
else:
|
|
329
|
-
|
|
330
|
+
funboost_lazy_impoter.BoostersManager.pid_queue_name__has_start_consume_set.add(pid_queue_name_tuple)
|
|
330
331
|
GlobalVars.has_start_a_consumer_flag = True
|
|
331
332
|
try:
|
|
332
333
|
self._concurrent_mode_dispatcher.check_all_concurrent_mode()
|
|
@@ -373,7 +374,7 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
373
374
|
key = 'apscheduler.redisjobstore_runonce'
|
|
374
375
|
if RedisMixin().redis_db_frame.sadd(key, runonce_uuid): # 这样可以阻止多次启动同队列名消费者 redis jobstore多次运行函数.
|
|
375
376
|
cls.logger_apscheduler.debug(f'延时任务用普通消息重新发布到普通队列 {msg}')
|
|
376
|
-
|
|
377
|
+
funboost_lazy_impoter.BoostersManager.get_or_create_booster_by_queue_name(queue_name).publish(msg)
|
|
377
378
|
|
|
378
379
|
@abc.abstractmethod
|
|
379
380
|
def _shedual_task(self):
|
|
@@ -383,8 +384,11 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
383
384
|
"""
|
|
384
385
|
raise NotImplementedError
|
|
385
386
|
|
|
386
|
-
def
|
|
387
|
-
"""
|
|
387
|
+
def convert_msg_before_run(self, msg: typing.Union[str,dict]):
|
|
388
|
+
"""
|
|
389
|
+
转换消息,消息没有使用funboost来发送,并且没有extra相关字段时候
|
|
390
|
+
用户也可以按照4.21文档,继承任意Consumer类,并实现这个方法 convert_msg_before_run,先转换消息.
|
|
391
|
+
"""
|
|
388
392
|
""" 一般消息至少包含这样
|
|
389
393
|
{
|
|
390
394
|
"a": 42,
|
|
@@ -401,15 +405,19 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
401
405
|
extra_params = {'task_id': task_id, 'publish_time': round(time.time(), 4),
|
|
402
406
|
'publish_time_format': time.strftime('%Y-%m-%d %H:%M:%S')}
|
|
403
407
|
"""
|
|
408
|
+
if isinstance(msg,str):
|
|
409
|
+
msg = json.loads(msg)
|
|
410
|
+
# 以下是清洗补全字段.
|
|
404
411
|
if 'extra' not in msg:
|
|
405
412
|
msg['extra'] = {'is_auto_fill_extra': True}
|
|
406
413
|
extra = msg['extra']
|
|
407
414
|
if 'task_id' not in extra:
|
|
408
|
-
extra['task_id'] = generate_task_id(self._queue_name)
|
|
415
|
+
extra['task_id'] = MsgGenerater.generate_task_id(self._queue_name)
|
|
409
416
|
if 'publish_time' not in extra:
|
|
410
|
-
extra['publish_time'] =
|
|
417
|
+
extra['publish_time'] = MsgGenerater.generate_publish_time()
|
|
411
418
|
if 'publish_time_format':
|
|
412
|
-
extra['publish_time_format'] =
|
|
419
|
+
extra['publish_time_format'] = MsgGenerater.generate_publish_time_format()
|
|
420
|
+
return msg
|
|
413
421
|
|
|
414
422
|
def _submit_task(self, kw):
|
|
415
423
|
while 1: # 这一块的代码为支持暂停消费。
|
|
@@ -421,12 +429,13 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
421
429
|
self._last_show_pause_log_time = time.time()
|
|
422
430
|
else:
|
|
423
431
|
break
|
|
424
|
-
|
|
432
|
+
msg = kw['body']
|
|
433
|
+
self._print_message_get_from_broker(msg)
|
|
434
|
+
kw['body'] = self.convert_msg_before_run(msg)
|
|
425
435
|
if self._judge_is_daylight():
|
|
426
436
|
self._requeue(kw)
|
|
427
437
|
time.sleep(self.time_interval_for_check_do_not_run_time)
|
|
428
438
|
return
|
|
429
|
-
self._auto_fill_msg(kw['body'])
|
|
430
439
|
function_only_params = delete_keys_and_return_new_dict(kw['body'], )
|
|
431
440
|
if self._get_priority_conf(kw, 'do_task_filtering') and self._redis_filter.check_value_exists(
|
|
432
441
|
function_only_params): # 对函数的参数进行检查,过滤已经执行过并且成功的任务。
|
|
@@ -521,12 +530,13 @@ class AbstractConsumer(LoggerLevelSetterMixin, metaclass=abc.ABCMeta, ):
|
|
|
521
530
|
if self._has_execute_times_in_recent_second >= qpsx:
|
|
522
531
|
time.sleep((1 - (time.time() - self._last_start_count_qps_timestamp)) * 1)
|
|
523
532
|
|
|
524
|
-
def _print_message_get_from_broker(self, broker_name
|
|
533
|
+
def _print_message_get_from_broker(self, msg,broker_name=None):
|
|
525
534
|
# print(999)
|
|
526
535
|
if self.consumer_params.is_show_message_get_from_broker:
|
|
527
536
|
if isinstance(msg, (dict, list)):
|
|
528
537
|
msg = json.dumps(msg, ensure_ascii=False)
|
|
529
|
-
self.logger.debug(f'从 {broker_name} 中间件 的 {self._queue_name} 中取出的消息是 {msg}')
|
|
538
|
+
# self.logger.debug(f'从 {broker_name} 中间件 的 {self._queue_name} 中取出的消息是 {msg}')
|
|
539
|
+
self.logger.debug(f'从 {broker_name or self.consumer_params.broker_kind} 中间件 的 {self._queue_name} 中取出的消息是 {msg}')
|
|
530
540
|
|
|
531
541
|
def _get_priority_conf(self, kw: dict, broker_task_config_key: str):
|
|
532
542
|
broker_task_config = kw['body'].get('extra', {}).get(broker_task_config_key, None)
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import asyncio
|
|
5
5
|
import json
|
|
6
6
|
|
|
7
|
-
from aiohttp import web
|
|
8
|
-
from aiohttp.web_request import Request
|
|
7
|
+
# from aiohttp import web
|
|
8
|
+
# from aiohttp.web_request import Request
|
|
9
9
|
|
|
10
10
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
11
|
-
|
|
11
|
+
from funboost.core.lazy_impoter import AioHttpImporter
|
|
12
12
|
|
|
13
13
|
class HTTPConsumer(AbstractConsumer, ):
|
|
14
14
|
"""
|
|
@@ -38,26 +38,26 @@ class HTTPConsumer(AbstractConsumer, ):
|
|
|
38
38
|
#
|
|
39
39
|
# flask_app.run('0.0.0.0', port=self._port,debug=False)
|
|
40
40
|
|
|
41
|
-
routes = web.RouteTableDef()
|
|
41
|
+
routes = AioHttpImporter().web.RouteTableDef()
|
|
42
42
|
|
|
43
43
|
# noinspection PyUnusedLocal
|
|
44
44
|
@routes.get('/')
|
|
45
45
|
async def hello(request):
|
|
46
|
-
return web.Response(text="Hello, from funboost")
|
|
46
|
+
return AioHttpImporter().web.Response(text="Hello, from funboost")
|
|
47
47
|
|
|
48
48
|
@routes.post('/queue')
|
|
49
|
-
async def recv_msg(request: Request):
|
|
49
|
+
async def recv_msg(request: AioHttpImporter().Request):
|
|
50
50
|
data = await request.post()
|
|
51
51
|
msg = data['msg']
|
|
52
|
-
kw = {'body':
|
|
52
|
+
kw = {'body': msg}
|
|
53
53
|
self._submit_task(kw)
|
|
54
|
-
return web.Response(text="finish")
|
|
54
|
+
return AioHttpImporter().web.Response(text="finish")
|
|
55
55
|
|
|
56
|
-
app = web.Application()
|
|
56
|
+
app = AioHttpImporter().web.Application()
|
|
57
57
|
app.add_routes(routes)
|
|
58
58
|
loop = asyncio.new_event_loop()
|
|
59
59
|
asyncio.set_event_loop(loop)
|
|
60
|
-
web.run_app(app, host='0.0.0.0', port=self._port, )
|
|
60
|
+
AioHttpImporter().web.run_app(app, host='0.0.0.0', port=self._port, )
|
|
61
61
|
|
|
62
62
|
def _confirm_consume(self, kw):
|
|
63
63
|
pass # 没有确认消费的功能。
|
|
@@ -60,8 +60,7 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|
|
60
60
|
if self.path == '/queue':
|
|
61
61
|
msg = form['msg'].value
|
|
62
62
|
# print(msg)
|
|
63
|
-
|
|
64
|
-
kw = {'body': json.loads(msg)}
|
|
63
|
+
kw = {'body': msg}
|
|
65
64
|
self.consumer._submit_task(kw)
|
|
66
65
|
|
|
67
66
|
# 开始回复
|
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
# @Time : 2022/8/8 0008 13:32
|
|
4
4
|
import json
|
|
5
5
|
# noinspection PyPackageRequirements
|
|
6
|
-
|
|
7
|
-
# noinspection PyPackageRequirements
|
|
8
|
-
from kafka.admin import NewTopic
|
|
9
|
-
# noinspection PyPackageRequirements
|
|
10
|
-
from kafka.errors import TopicAlreadyExistsError
|
|
6
|
+
|
|
11
7
|
from funboost.constant import BrokerEnum
|
|
12
8
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
9
|
+
from funboost.core.lazy_impoter import KafkaPythonImporter
|
|
13
10
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
14
11
|
# from nb_log import get_logger
|
|
15
12
|
from funboost.core.loggers import get_funboost_file_logger
|
|
13
|
+
|
|
16
14
|
# LogManager('kafka').get_logger_and_add_handlers(30)
|
|
17
15
|
get_funboost_file_logger('kafka', log_level_int=30)
|
|
18
16
|
|
|
@@ -36,18 +34,18 @@ class KafkaConsumer(AbstractConsumer):
|
|
|
36
34
|
|
|
37
35
|
def _shedual_task(self):
|
|
38
36
|
try:
|
|
39
|
-
admin_client = KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
40
|
-
admin_client.create_topics([NewTopic(self._queue_name, 10, 1)])
|
|
37
|
+
admin_client = KafkaPythonImporter().KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
38
|
+
admin_client.create_topics([KafkaPythonImporter().NewTopic(self._queue_name, 10, 1)])
|
|
41
39
|
# admin_client.create_partitions({self._queue_name: NewPartitions(total_count=16)})
|
|
42
|
-
except TopicAlreadyExistsError:
|
|
40
|
+
except KafkaPythonImporter().TopicAlreadyExistsError:
|
|
43
41
|
pass
|
|
44
42
|
|
|
45
|
-
self._producer = KafkaProducer(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
46
|
-
consumer = OfficialKafkaConsumer(self._queue_name, bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
self._producer = KafkaPythonImporter().KafkaProducer(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
44
|
+
consumer = KafkaPythonImporter().OfficialKafkaConsumer(self._queue_name, bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS,
|
|
45
|
+
group_id=self.consumer_params.broker_exclusive_config["group_id"],
|
|
46
|
+
enable_auto_commit=True,
|
|
47
|
+
auto_offset_reset=self.consumer_params.broker_exclusive_config["auto_offset_reset"],
|
|
48
|
+
)
|
|
51
49
|
# auto_offset_reset (str): A policy for resetting offsets on
|
|
52
50
|
# OffsetOutOfRange errors: 'earliest' will move to the oldest
|
|
53
51
|
# available message, 'latest' will move to the most recent. Any
|
|
@@ -63,7 +61,7 @@ class KafkaConsumer(AbstractConsumer):
|
|
|
63
61
|
if self.consumer_params.is_show_message_get_from_broker:
|
|
64
62
|
self.logger.debug(
|
|
65
63
|
f'从kafka的 [{message.topic}] 主题,分区 {message.partition} 中 取出的消息是: {message.value.decode()}')
|
|
66
|
-
kw = {'consumer': consumer, 'message': message, 'body':
|
|
64
|
+
kw = {'consumer': consumer, 'message': message, 'body': message.value}
|
|
67
65
|
self._submit_task(kw)
|
|
68
66
|
|
|
69
67
|
def _confirm_consume(self, kw):
|
|
@@ -10,13 +10,10 @@ from collections import defaultdict, OrderedDict
|
|
|
10
10
|
import time
|
|
11
11
|
|
|
12
12
|
# noinspection PyPackageRequirements
|
|
13
|
-
|
|
13
|
+
# pip install kafka-python==2.0.2
|
|
14
14
|
|
|
15
|
-
# noinspection PyPackageRequirements
|
|
16
|
-
from kafka.admin import NewTopic
|
|
17
|
-
# noinspection PyPackageRequirements
|
|
18
|
-
from kafka.errors import TopicAlreadyExistsError
|
|
19
15
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
16
|
+
from funboost.core.lazy_impoter import KafkaPythonImporter
|
|
20
17
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
21
18
|
from confluent_kafka.cimpl import TopicPartition
|
|
22
19
|
from confluent_kafka import Consumer as ConfluentConsumer # 这个包在win下不好安装,用户用这个中间件的时候自己再想办法安装。win用户需要安装c++ 14.0以上环境。
|
|
@@ -39,13 +36,13 @@ class KafkaConsumerManuallyCommit(AbstractConsumer):
|
|
|
39
36
|
def _shedual_task(self):
|
|
40
37
|
|
|
41
38
|
try:
|
|
42
|
-
admin_client = KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
43
|
-
admin_client.create_topics([NewTopic(self._queue_name, 10, 1)])
|
|
39
|
+
admin_client = KafkaPythonImporter().KafkaAdminClient(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
40
|
+
admin_client.create_topics([KafkaPythonImporter().NewTopic(self._queue_name, 10, 1)])
|
|
44
41
|
# admin_client.create_partitions({self._queue_name: NewPartitions(total_count=16)})
|
|
45
|
-
except TopicAlreadyExistsError:
|
|
42
|
+
except KafkaPythonImporter().TopicAlreadyExistsError:
|
|
46
43
|
pass
|
|
47
44
|
|
|
48
|
-
self._producer = KafkaProducer(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
45
|
+
self._producer = KafkaPythonImporter().KafkaProducer(bootstrap_servers=BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS)
|
|
49
46
|
# consumer 配置 https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
|
|
50
47
|
self._confluent_consumer = ConfluentConsumer({
|
|
51
48
|
'bootstrap.servers': ','.join(BrokerConnConfig.KAFKA_BOOTSTRAP_SERVERS),
|
|
@@ -69,7 +66,7 @@ class KafkaConsumerManuallyCommit(AbstractConsumer):
|
|
|
69
66
|
# value() offset() partition()
|
|
70
67
|
# print('Received message: {}'.format(msg.value().decode('utf-8'))) # noqa
|
|
71
68
|
self._partion__offset_consume_status_map[msg.partition()][msg.offset()] = 0
|
|
72
|
-
kw = {'partition': msg.partition(), 'offset': msg.offset(), 'body':
|
|
69
|
+
kw = {'partition': msg.partition(), 'offset': msg.offset(), 'body': msg.value()} # noqa
|
|
73
70
|
if self.consumer_params.is_show_message_get_from_broker:
|
|
74
71
|
self.logger.debug(
|
|
75
72
|
f'从kafka的 [{self._queue_name}] 主题,分区 {msg.partition()} 中 的 offset {msg.offset()} 取出的消息是: {msg.value()}') # noqa
|
|
@@ -130,14 +127,14 @@ class SaslPlainKafkaConsumer(KafkaConsumerManuallyCommit):
|
|
|
130
127
|
def _shedual_task(self):
|
|
131
128
|
|
|
132
129
|
try:
|
|
133
|
-
admin_client = KafkaAdminClient(
|
|
130
|
+
admin_client = KafkaPythonImporter().KafkaAdminClient(
|
|
134
131
|
**BrokerConnConfig.KFFKA_SASL_CONFIG)
|
|
135
|
-
admin_client.create_topics([NewTopic(self._queue_name, 10, 1)])
|
|
132
|
+
admin_client.create_topics([KafkaPythonImporter().NewTopic(self._queue_name, 10, 1)])
|
|
136
133
|
# admin_client.create_partitions({self._queue_name: NewPartitions(total_count=16)})
|
|
137
|
-
except TopicAlreadyExistsError:
|
|
134
|
+
except KafkaPythonImporter().TopicAlreadyExistsError:
|
|
138
135
|
pass
|
|
139
136
|
|
|
140
|
-
self._producer = KafkaProducer(
|
|
137
|
+
self._producer = KafkaPythonImporter().KafkaProducer(
|
|
141
138
|
**BrokerConnConfig.KFFKA_SASL_CONFIG)
|
|
142
139
|
# consumer 配置 https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
|
|
143
140
|
self._confluent_consumer = ConfluentConsumer({
|
|
@@ -168,7 +165,7 @@ class SaslPlainKafkaConsumer(KafkaConsumerManuallyCommit):
|
|
|
168
165
|
# print('Received message: {}'.format(msg.value().decode('utf-8'))) # noqa
|
|
169
166
|
self._partion__offset_consume_status_map[msg.partition(
|
|
170
167
|
)][msg.offset()] = 0
|
|
171
|
-
kw = {'partition': msg.partition(), 'offset': msg.offset(), 'body':
|
|
168
|
+
kw = {'partition': msg.partition(), 'offset': msg.offset(), 'body': msg.value()} # noqa
|
|
172
169
|
if self.consumer_params.is_show_message_get_from_broker:
|
|
173
170
|
self.logger.debug(
|
|
174
171
|
f'从kafka的 [{self._queue_name}] 主题,分区 {msg.partition()} 中 的 offset {msg.offset()} 取出的消息是: {msg.value()}') # noqa
|
|
@@ -194,7 +194,6 @@ Transport Options
|
|
|
194
194
|
|
|
195
195
|
def callback(body: dict, message: Message):
|
|
196
196
|
# print(type(body),body,type(message),message)
|
|
197
|
-
self._print_message_get_from_broker('kombu', body)
|
|
198
197
|
# self.logger.debug(f""" 从 kombu {self._middware_name} 中取出的消息是 {body}""")
|
|
199
198
|
kw = {'body': body, 'message': message, }
|
|
200
199
|
self._submit_task(kw)
|
|
@@ -20,9 +20,8 @@ class LocalPythonQueueConsumer(AbstractConsumer):
|
|
|
20
20
|
def _shedual_task(self):
|
|
21
21
|
while True:
|
|
22
22
|
task = self.local_python_queue.get()
|
|
23
|
-
if isinstance(task,
|
|
24
|
-
task = json.
|
|
25
|
-
self._print_message_get_from_broker('当前python解释器内部', task)
|
|
23
|
+
if isinstance(task, dict):
|
|
24
|
+
task = json.dumps(task)
|
|
26
25
|
# self.logger.debug(f'从当前python解释器内部的 [{self._queue_name}] 队列中 取出的消息是: {json.dumps(task)} ')
|
|
27
26
|
kw = {'body': task}
|
|
28
27
|
self._submit_task(kw)
|
|
@@ -21,9 +21,6 @@ class LocalPythonQueueConsumer(AbstractConsumer):
|
|
|
21
21
|
def _shedual_task(self):
|
|
22
22
|
while True:
|
|
23
23
|
task = self.local_python_queue.popleft()
|
|
24
|
-
if isinstance(task, str):
|
|
25
|
-
task = json.loads(task)
|
|
26
|
-
self._print_message_get_from_broker('当前python解释器内部', task)
|
|
27
24
|
# self.logger.debug(f'从当前python解释器内部的 [{self._queue_name}] 队列中 取出的消息是: {json.dumps(task)} ')
|
|
28
25
|
kw = {'body': task}
|
|
29
26
|
self._submit_task(kw)
|
|
@@ -19,7 +19,6 @@ class MongoMqConsumer(AbstractConsumer, MongoMixin):
|
|
|
19
19
|
job = mp.queue.next()
|
|
20
20
|
if job is not None:
|
|
21
21
|
# self.logger.debug(f'从mongo的 [{self._queue_name}] 队列中 取出的消息是: 消息是: {job.payload} ')
|
|
22
|
-
self._print_message_get_from_broker('mongo', job.payload)
|
|
23
22
|
kw = {'body': job.payload, 'job': job}
|
|
24
23
|
self._submit_task(kw)
|
|
25
24
|
else:
|
|
@@ -5,8 +5,9 @@ import json
|
|
|
5
5
|
# import time
|
|
6
6
|
from funboost.constant import BrokerEnum
|
|
7
7
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
8
|
+
from funboost.core.lazy_impoter import PahoMqttImporter
|
|
8
9
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
9
|
-
import paho.mqtt.client as mqtt
|
|
10
|
+
# import paho.mqtt.client as mqtt
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class MqttConsumer(AbstractConsumer):
|
|
@@ -23,7 +24,7 @@ class MqttConsumer(AbstractConsumer):
|
|
|
23
24
|
|
|
24
25
|
# noinspection DuplicatedCode
|
|
25
26
|
def _shedual_task(self):
|
|
26
|
-
client = mqtt.Client()
|
|
27
|
+
client = PahoMqttImporter().mqtt.Client()
|
|
27
28
|
# client.username_pw_set('admin', password='public')
|
|
28
29
|
client.on_connect = self._on_connect
|
|
29
30
|
client.on_message = self._on_message
|
|
@@ -47,7 +48,7 @@ class MqttConsumer(AbstractConsumer):
|
|
|
47
48
|
# noinspection PyUnusedLocal
|
|
48
49
|
def _on_message(self, client, userdata, msg):
|
|
49
50
|
# print(msg.topic + " " + str(msg.payload))
|
|
50
|
-
kw = {'body':
|
|
51
|
+
kw = {'body': msg.payload}
|
|
51
52
|
self._submit_task(kw)
|
|
52
53
|
|
|
53
54
|
def _confirm_consume(self, kw):
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from pynats import NATSClient, NATSMessage # noqa
|
|
3
|
-
|
|
2
|
+
# from pynats import NATSClient, NATSMessage # noqa
|
|
3
|
+
|
|
4
4
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
5
|
+
from funboost.core.lazy_impoter import NatsImporter
|
|
5
6
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
6
7
|
|
|
7
8
|
|
|
@@ -13,14 +14,14 @@ class NatsConsumer(AbstractConsumer):
|
|
|
13
14
|
|
|
14
15
|
def _shedual_task(self):
|
|
15
16
|
# print(88888888888888)
|
|
16
|
-
nats_client = NATSClient(BrokerConnConfig.NATS_URL, socket_timeout=600, socket_keepalive=True)
|
|
17
|
+
nats_client = NatsImporter().NATSClient(BrokerConnConfig.NATS_URL, socket_timeout=600, socket_keepalive=True)
|
|
17
18
|
nats_client.connect()
|
|
18
19
|
|
|
19
|
-
def callback(msg: NATSMessage):
|
|
20
|
+
def callback(msg: NatsImporter().NATSMessage):
|
|
20
21
|
# print(type(msg))
|
|
21
22
|
# print(msg.reply)
|
|
22
23
|
# print(f"Received a message with subject {msg.subject}: {msg.payload}")
|
|
23
|
-
kw = {'body':
|
|
24
|
+
kw = {'body': msg.payload}
|
|
24
25
|
self._submit_task(kw)
|
|
25
26
|
|
|
26
27
|
nats_client.subscribe(subject=self.queue_name, callback=callback)
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
# @Author : ydf
|
|
3
3
|
# @Time : 2022/8/8 0008 13:32
|
|
4
4
|
import json
|
|
5
|
-
|
|
6
|
-
from funboost.
|
|
5
|
+
|
|
6
|
+
from funboost.core.lazy_impoter import GnsqImporter
|
|
7
|
+
# from gnsq import Consumer, Message
|
|
8
|
+
|
|
7
9
|
from funboost.funboost_config_deafult import BrokerConnConfig
|
|
8
10
|
from funboost.consumers.base_consumer import AbstractConsumer
|
|
9
11
|
# from nb_log import LogManager
|
|
@@ -19,16 +21,15 @@ class NsqConsumer(AbstractConsumer):
|
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
def _shedual_task(self):
|
|
22
|
-
consumer = Consumer(self._queue_name, 'frame_channel', BrokerConnConfig.NSQD_TCP_ADDRESSES,
|
|
24
|
+
consumer = GnsqImporter().Consumer(self._queue_name, 'frame_channel', BrokerConnConfig.NSQD_TCP_ADDRESSES,
|
|
23
25
|
max_in_flight=self.consumer_params.concurrent_num, heartbeat_interval=60, timeout=600, ) # heartbeat_interval 不能设置为600
|
|
24
26
|
|
|
25
27
|
@consumer.on_message.connect
|
|
26
|
-
def handler(consumerx: Consumer, message: Message):
|
|
28
|
+
def handler(consumerx: GnsqImporter().Consumer, message: GnsqImporter().Message):
|
|
27
29
|
# 第一条消息不能并发,第一条消息之后可以并发。
|
|
28
|
-
self._print_message_get_from_broker('nsq', message.body.decode())
|
|
29
30
|
# self.logger.debug(f'从nsq的 [{self._queue_name}] 主题中 取出的消息是: {message.body.decode()}')
|
|
30
31
|
message.enable_async()
|
|
31
|
-
kw = {'consumer': consumerx, 'message': message, 'body':
|
|
32
|
+
kw = {'consumer': consumerx, 'message': message, 'body': message.body}
|
|
32
33
|
self._submit_task(kw)
|
|
33
34
|
|
|
34
35
|
consumer.start()
|
|
@@ -20,8 +20,7 @@ class PeeweeConsumer(AbstractConsumer):
|
|
|
20
20
|
task_dict = self.queue.get()
|
|
21
21
|
# print(task_dict)
|
|
22
22
|
# self.logger.debug(f'从数据库 {frame_config.SQLACHEMY_ENGINE_URL[:25]}。。 的 [{self._queue_name}] 队列中 取出的消息是: 消息是: {sqla_task_dict}')
|
|
23
|
-
|
|
24
|
-
kw = {'body':json.loads(task_dict['body']), 'job_id': task_dict['job_id']}
|
|
23
|
+
kw = {'body':task_dict['body'], 'job_id': task_dict['job_id']}
|
|
25
24
|
self._submit_task(kw)
|
|
26
25
|
|
|
27
26
|
def _confirm_consume(self, kw):
|
|
@@ -17,8 +17,7 @@ class PersistQueueConsumer(AbstractConsumer):
|
|
|
17
17
|
while True:
|
|
18
18
|
item = pub.queue.get()
|
|
19
19
|
# self.logger.debug(f'从本地持久化sqlite的 [{self._queue_name}] 队列中 取出的消息是: {item} ')
|
|
20
|
-
|
|
21
|
-
kw = {'body': json.loads(item), 'q': pub.queue, 'item': item}
|
|
20
|
+
kw = {'body': item, 'q': pub.queue, 'item': item}
|
|
22
21
|
self._submit_task(kw)
|
|
23
22
|
|
|
24
23
|
def _confirm_consume(self, kw):
|
|
@@ -53,8 +53,7 @@ class PulsarConsumer(AbstractConsumer, ):
|
|
|
53
53
|
while True:
|
|
54
54
|
msg = self._consumer.receive()
|
|
55
55
|
if msg:
|
|
56
|
-
|
|
57
|
-
kw = {'body': json.loads(msg.data()), 'msg': msg}
|
|
56
|
+
kw = {'body': msg.data(), 'msg': msg}
|
|
58
57
|
self._submit_task(kw)
|
|
59
58
|
|
|
60
59
|
def _confirm_consume(self, kw):
|
|
@@ -21,8 +21,6 @@ class RabbitmqConsumerAmqpStorm(AbstractConsumer):
|
|
|
21
21
|
def callback(amqpstorm_message: amqpstorm.Message):
|
|
22
22
|
body = amqpstorm_message.body
|
|
23
23
|
# self.logger.debug(f'从rabbitmq的 [{self._queue_name}] 队列中 取出的消息是: {body}')
|
|
24
|
-
self._print_message_get_from_broker('rabbitmq', body)
|
|
25
|
-
body = json.loads(body)
|
|
26
24
|
kw = {'amqpstorm_message': amqpstorm_message, 'body': body}
|
|
27
25
|
self._submit_task(kw)
|
|
28
26
|
|
|
@@ -37,8 +37,6 @@ class RabbitmqConsumer(AbstractConsumer):
|
|
|
37
37
|
def callback(ch, method, properties, body):
|
|
38
38
|
body = body.decode()
|
|
39
39
|
# self.logger.debug(f'从rabbitmq的 [{self._queue_name}] 队列中 取出的消息是: {body}')
|
|
40
|
-
self._print_message_get_from_broker('rabbitmq', body)
|
|
41
|
-
body = json.loads(body)
|
|
42
40
|
kw = {'ch': ch, 'method': method, 'properties': properties, 'body': body}
|
|
43
41
|
self._submit_task(kw)
|
|
44
42
|
|
|
@@ -34,7 +34,6 @@ class RabbitmqConsumer(AbstractConsumer):
|
|
|
34
34
|
def callback(ch, method, properties, body):
|
|
35
35
|
body = body.decode()
|
|
36
36
|
self.logger.debug(f'从rabbitmq的 [{self._queue_name}] 队列中 取出的消息是: {body}')
|
|
37
|
-
body = json.loads(body)
|
|
38
37
|
kw = {'ch': ch, 'method': method, 'properties': properties, 'body': body}
|
|
39
38
|
self._submit_task(kw)
|
|
40
39
|
|
|
@@ -23,8 +23,7 @@ class RabbitmqConsumerRabbitpy(AbstractConsumer):
|
|
|
23
23
|
for message in channel.basic_consume(self._queue_name, no_ack=False):
|
|
24
24
|
body = message.body.decode()
|
|
25
25
|
# self.logger.debug(f'从rabbitmq {self._queue_name} 队列中 取出的消息是: {body}')
|
|
26
|
-
|
|
27
|
-
kw = {'message': message, 'body': json.loads(message.body.decode())}
|
|
26
|
+
kw = {'message': message, 'body': body}
|
|
28
27
|
self._submit_task(kw)
|
|
29
28
|
|
|
30
29
|
def _confirm_consume(self, kw):
|
|
@@ -27,9 +27,7 @@ class RedisBrpopLpushConsumer(AbstractConsumer, RedisMixin):
|
|
|
27
27
|
while True:
|
|
28
28
|
msg = self.redis_db_frame.brpoplpush(self._queue_name, unack_list_name, timeout=60)
|
|
29
29
|
if msg:
|
|
30
|
-
|
|
31
|
-
task_dict = json.loads(msg)
|
|
32
|
-
kw = {'body': task_dict, 'raw_msg': msg}
|
|
30
|
+
kw = {'body': msg, 'raw_msg': msg}
|
|
33
31
|
self._submit_task(kw)
|
|
34
32
|
|
|
35
33
|
def _confirm_consume(self, kw):
|
|
@@ -34,17 +34,15 @@ class RedisConsumer(AbstractConsumer, RedisMixin):
|
|
|
34
34
|
task_str_list = p.execute()[0]
|
|
35
35
|
if task_str_list:
|
|
36
36
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str_list} ')
|
|
37
|
-
self._print_message_get_from_broker(
|
|
37
|
+
self._print_message_get_from_broker( task_str_list)
|
|
38
38
|
for task_str in task_str_list:
|
|
39
|
-
kw = {'body':
|
|
39
|
+
kw = {'body': task_str}
|
|
40
40
|
self._submit_task(kw)
|
|
41
41
|
else:
|
|
42
42
|
result = self.redis_db_frame.brpop(self._queue_name, timeout=60)
|
|
43
43
|
if result:
|
|
44
44
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {result[1].decode()} ')
|
|
45
|
-
|
|
46
|
-
task_dict = json.loads(result[1])
|
|
47
|
-
kw = {'body': task_dict}
|
|
45
|
+
kw = {'body': result[1]}
|
|
48
46
|
self._submit_task(kw)
|
|
49
47
|
|
|
50
48
|
def _shedual_task00(self):
|
|
@@ -52,9 +50,7 @@ class RedisConsumer(AbstractConsumer, RedisMixin):
|
|
|
52
50
|
result = self.redis_db_frame.blpop(self._queue_name, timeout=60)
|
|
53
51
|
if result:
|
|
54
52
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {result[1].decode()} ')
|
|
55
|
-
|
|
56
|
-
task_dict = json.loads(result[1])
|
|
57
|
-
kw = {'body': task_dict}
|
|
53
|
+
kw = {'body': result[1]}
|
|
58
54
|
self._submit_task(kw)
|
|
59
55
|
|
|
60
56
|
def _confirm_consume(self, kw):
|
|
@@ -32,9 +32,7 @@ class RedisConsumerAckAble000(ConsumerConfirmMixinWithTheHelpOfRedis, AbstractCo
|
|
|
32
32
|
# 如果运行了第20行,但没运行下面这一行,仍然有极小概率会丢失1个任务。但比不做控制随意关停,丢失几百个线程你的redis任务强多了。
|
|
33
33
|
self._add_task_str_to_unack_zset(task_str, )
|
|
34
34
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str} ')
|
|
35
|
-
|
|
36
|
-
task_dict = json.loads(task_str)
|
|
37
|
-
kw = {'body': task_dict, 'task_str': task_str}
|
|
35
|
+
kw = {'body': task_str, 'task_str': task_str}
|
|
38
36
|
self._submit_task(kw)
|
|
39
37
|
|
|
40
38
|
def _requeue(self, kw):
|
|
@@ -74,8 +72,7 @@ class RedisConsumerAckAble111(ConsumerConfirmMixinWithTheHelpOfRedis, AbstractCo
|
|
|
74
72
|
if return_v:
|
|
75
73
|
task_str = return_v
|
|
76
74
|
self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str} ')
|
|
77
|
-
|
|
78
|
-
kw = {'body': task_dict, 'task_str': task_str}
|
|
75
|
+
kw = {'body': task_str, 'task_str': task_str}
|
|
79
76
|
self._submit_task(kw)
|
|
80
77
|
else:
|
|
81
78
|
# print('xiuxi')
|
|
@@ -118,8 +115,7 @@ class RedisConsumerAckAble(ConsumerConfirmMixinWithTheHelpOfRedisByHearbeat, Abs
|
|
|
118
115
|
if return_v:
|
|
119
116
|
task_str = return_v
|
|
120
117
|
self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str} ')
|
|
121
|
-
|
|
122
|
-
kw = {'body': task_dict, 'task_str': task_str}
|
|
118
|
+
kw = {'body': task_str, 'task_str': task_str}
|
|
123
119
|
self._submit_task(kw)
|
|
124
120
|
else:
|
|
125
121
|
# print('xiuxi')
|
|
@@ -149,11 +145,10 @@ class RedisConsumerAckAble(ConsumerConfirmMixinWithTheHelpOfRedisByHearbeat, Abs
|
|
|
149
145
|
while True:
|
|
150
146
|
task_str_list = script(keys=[self._queue_name, self._unack_zset_name], args=[time.time()])
|
|
151
147
|
if task_str_list:
|
|
152
|
-
self._print_message_get_from_broker(
|
|
148
|
+
self._print_message_get_from_broker( task_str_list)
|
|
153
149
|
# self.logger.debug(f'从redis的 [{self._queue_name}] 队列中 取出的消息是: {task_str_list} ')
|
|
154
150
|
for task_str in task_str_list:
|
|
155
|
-
|
|
156
|
-
kw = {'body': task_dict, 'task_str': task_str}
|
|
151
|
+
kw = {'body': task_str, 'task_str': task_str}
|
|
157
152
|
self._submit_task(kw)
|
|
158
153
|
else:
|
|
159
154
|
time.sleep(0.2)
|