def _shedual_task(self): channel = RabbitMqFactory( is_use_rabbitpy=0).get_rabbit_cleint().creat_a_channel() channel.queue_declare(queue=self._queue_name, durable=True) channel.basic_qos(prefetch_count=self._concurrent_num) def callback(ch, method, properties, body): body = body.decode() self.logger.debug( f'从rabbitmq的 [{self._queue_name}] 队列中 取出的消息是: {body}') body = json.loads(body) kw = { 'ch': ch, 'method': method, 'properties': properties, 'body': body } self._submit_task(kw) channel.basic_consume( callback, queue=self._queue_name, # no_ack=True ) channel.start_consuming()
def _shedual_task(self): # noinspection PyTypeChecker channel = RabbitMqFactory(is_use_rabbitpy=1).get_rabbit_cleint( ).creat_a_channel() # type: rabbitpy.AMQP # channel.queue_declare(queue=self._queue_name, durable=True) channel.basic_qos(prefetch_count=self._concurrent_num) for message in channel.basic_consume(self._queue_name, no_ack=False): body = message.body.decode() # self.logger.debug(f'从rabbitmq {self._queue_name} 队列中 取出的消息是: {body}') self._print_message_get_from_broker('rabbitmq', body) kw = { 'message': message, 'body': json.loads(message.body.decode()) } self._submit_task(kw)