<filename>rabbitmq/RBConsumerImp.py<gh_stars>1-10
import logging
import threading
from rabbitmq.RBAsynConsumer import *

LOG_FORMAT = '%(levelname) -10s %(asctime)s %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s'
logger = logging.getLogger(__name__)


class RBConsumerImp(RBAsynConsumer):

    def process_message(self, basic_deliver, properties, body):
        """Child Class extends Class RBAsynConsumer and Override this method processMessage"""
        logger.info('============ RBConsumerImp process message ============')
        # do something...
        logging.info("body: " + str(body))

    def start_consumer(self):
        ct = self.ConsumerThread(self)
        ct.start()

    class ConsumerThread (threading.Thread):
        def __init__(self, consumer=None):
            threading.Thread.__init__(self)
            self.consumer = consumer

        def run(self):
            try:
                logging.info("Instance ConsumerThread[%s] starting...", self.consumer.ROUTING_KEY)
                self.consumer.run()
            except Exception as e:
                logging.info("Instance ConsumerThread[%s] run fail...", self.consumer.ROUTING_KEY)
                self.consumer.stop()

<filename>rabbitmq/RBConsumerImp.py<gh_stars>1-10
import logging
import threading
from rabbitmq.RBAsynConsumer import *

LOG_FORMAT = '%(levelname) -10s %(asctime)s %(name) -30s %(funcName) -35s %(lineno) -5d: %(message)s'
logger = logging.getLogger(__name__)


class RBConsumerImp(RBAsynConsumer):

    def process_message(self, basic_deliver, properties, body):
        """Child Class extends Class RBAsynConsumer and Override this method processMessage"""
        logger.info('============ RBConsumerImp process message ============')
        # do something...
        logging.info("body: " + str(body))

    def start_consumer(self):
        ct = self.ConsumerThread(self)
        ct.start()

    class ConsumerThread (threading.Thread):
        def __init__(self, consumer=None):
            threading.Thread.__init__(self)
            self.consumer = consumer

        def run(self):
            try:
                logging.info("Instance ConsumerThread[%s] starting...", self.consumer.ROUTING_KEY)
                self.consumer.run()
            except Exception as e:
                logging.info("Instance ConsumerThread[%s] run fail...", self.consumer.ROUTING_KEY)
                self.consumer.stop()

Child Class extends Class RBAsynConsumer and Override this method processMessage # do something...