# -*- coding: utf-8 -*-
# @Author  : ydf
# @Time    : 2019/8/8 0008 14:57
import time

from function_scheduling_distributed_framework import get_publisher
from test_frame.my_patch_frame_config import do_patch_frame_config

do_patch_frame_config()
pb = get_publisher('task1_queue', broker_kind=2)

for i in range(100):
    pb.publish({'x': i, 'y': i * 2})
# -*- coding: utf-8 -*-
# @Author  : ydf
# @Time    : 2019/8/8 0008 14:57
from multiprocessing import Process
import time
from function_scheduling_distributed_framework import get_consumer, get_publisher, AbstractConsumer
from function_scheduling_distributed_framework.consumers.redis_consumer import RedisConsumer
from function_scheduling_distributed_framework.utils import LogManager

from test_frame.my_patch_frame_config import do_patch_frame_config

do_patch_frame_config()

logger = LogManager('complex_example').get_logger_and_add_handlers()

pb2 = get_publisher('task2_queue', broker_kind=2)


def task1(x, y):
    logger.info(f'消费此消息 {x} - {y} ,结果是  {x - y}')
    for i in range(10):
        pb2.publish({'n': x * 100 + i})  # 消费时候发布任务到别的队列或自己的队列。可以边消费边推送。
    time.sleep(10)  # 模拟做某事需要阻塞10秒种,必须用并发绕过此阻塞。


def task2(n):
    logger.info(n)
    time.sleep(3)


def multi_processing_consume():
예제 #3
0
# -*- coding: utf-8 -*-
# @Author  : ydf
# @Time    : 2019/8/8 0008 14:57
import time

from function_scheduling_distributed_framework import get_publisher, PriorityConsumingControlConfig

pb = get_publisher('queue_test33', broker_kind=2)

# [consumer.publisher_of_same_queue.publish({'a': i, 'b': 2 * i}) for i in range(100)]

for i in range(10000000):
    a = i
    b = i * 2
    async_result = pb.publish({'a': a, 'b': b})
    print(f'{a}  {b} 之和是 {async_result.result}')