Exemple #1
0
class NewsPublisher(object):
    '''
    published news to rabbitmq
    '''
    def __init__(self, message_key,message_auth  = None):
        self.handlerRepository = HandlerRepository()
        if message_auth != None:
            self.handlerRepository.init_Message(message_key, message_auth)
        self.message_key = message_key

    def process(self, msg):
        now = int(time.time())
        msg["id"] = time.time()

        if self.handlerRepository.process(self.message_key, msg):
            LOGGER.info('[Publish %d] received message: %s %s'   % (os.getpid(), self.message_key,msg))
class Producer():
    def __init__(self, message_key,message_auth  = None):
        self.handlerRepository = HandlerRepository()
        if message_auth != None:
            self.handlerRepository.init_Message(message_key, message_auth)
        self.message_key = message_key
    def start(self,log_config):
        while True:
            self.process()
    def process(self):
        now = int(time.time())
        msg = {
            'id': now,
            'name': 'producer %s' % (now % 10),
            'phone': now,
            '__priority': (now % 3),
        }
        if self.handlerRepository.process(self.message_key, msg):
            print '[Publish %d] received message: %s %s'   % (os.getpid(), self.message_key,msg)
Exemple #3
0
class Producer():
    def __init__(self, message_key, message_auth=None):
        self.handlerRepository = HandlerRepository()
        if message_auth != None:
            self.handlerRepository.init_Message(message_key, message_auth)
        self.message_key = message_key

    def start(self, log_config):
        while True:
            self.process()

    def process(self):
        now = int(time.time())
        msg = {
            'id': now,
            'name': 'producer %s' % (now % 10),
            'phone': now,
            '__priority': (now % 3),
        }
        if self.handlerRepository.process(self.message_key, msg):
            print '[Publish %d] received message: %s %s' % (
                os.getpid(), self.message_key, msg)