| | |
| | | def stop(self): |
| | | """stop the thread""" |
| | | self.is_stop = True |
| | | self.connection.close() |
| | | # self.connection.close() |
| | | |
| | | def run(self): |
| | | |
| | |
| | | |
| | | while True: |
| | | try: |
| | | if not self.message_queue.empty(): |
| | | if not self.message_queue.empty() and not self.is_stop: |
| | | |
| | | # decode the routing key and message body from tuple list |
| | | message = self.message_queue.get() |
| | |
| | | def stop(self): |
| | | """stop the thread""" |
| | | self.is_stop = True |
| | | self.connection.close() |
| | | # self.connection.close() |
| | | |
| | | |
| | | def run(self): |
| | |
| | | channel.queue_declare(queue=self.MQqueue_name, durable=True) |
| | | for binding_key in self.binding_keys: |
| | | channel.queue_bind(exchange=self.exchange_name, queue=self.MQqueue_name, routing_key=binding_key) |
| | | print(f"[*] Using [{binding_key}] bind [{self.MQqueue_name}] on [{self.exchange_name}]") |
| | | |
| | | # consume the message |
| | | channel.basic_qos(prefetch_count=1) |
| | |
| | | channel.start_consuming() |
| | | |
| | | def callback(self,ch, method, properties, body): |
| | | |
| | | if self.is_stop: |
| | | ch.close() |
| | | self.message_queue.put(body) |
| | | ch.basic_ack(delivery_tag = method.delivery_tag) |
| | | |
| | |
| | | queue = self.queue_list[i_tag] |
| | | |
| | | # make sure the queue is not empty |
| | | while not queue.empty(): |
| | | while not queue.empty() and not self.is_stop: |
| | | # decode the msg using cooresponding method |
| | | queue_tag = self.queue_tags[i_tag] |
| | | decode_method = self.decode_select(queue_tag) |
| | |
| | | while not queue.empty() and count < nums_limit: |
| | | |
| | | # extracting the msg from queue |
| | | msg = queue.pop() |
| | | msg = queue.get() |
| | | msg_pb = pb.LogsMessage() |
| | | msg_pb.ParseFromString(msg) |
| | | |
| | |
| | | while not queue.empty(): |
| | | |
| | | # extracting the msg from queue |
| | | msg = queue.pop() |
| | | msg = queue.get() |
| | | msg_pb = pb.ImagesMessage() |
| | | msg_pb.ParseFromString(msg) |
| | | |
| | |
| | | filename = f"{msg_source}_{msg_timestamp}_image{id}.jpg" |
| | | filepath = os.path.join(self.imagesmsg_folder,filename) |
| | | with open(filepath, 'wb') as f: |
| | | f.write(image) |
| | | f.write(image_byte) |
| | | |
| | | # display the info to the console |
| | | curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') |
| | |
| | | while not queue.empty(): |
| | | |
| | | # extracting the msg from queue |
| | | msg = queue.pop() |
| | | msg = queue.get() |
| | | msg_pb = pb.PlyMessage() |
| | | msg_pb.ParseFromString(msg) |
| | | |