def callback(self, ch, method, properties, body): # convert body (in bytes) to string message_dict = decode_message(body, self.config.ENCRYPT_KEY) logging.info("callback() invoked: {}".format(json.dumps(message_dict))) helper.middle_logic(helper.get_listeners( business.process_incoming_form(), message_dict['event_type']), message=message_dict, config=self.config, writer=self.writer) # Regardless of whether the process above follows the happy path or not, # we need to acknowledge receipt of the message to RabbitMQ below. This # acknowledgement deletes it from the queue. The logic above # must have saved / handled the message before we get here. ch.basic_ack(delivery_tag=method.delivery_tag)
def callback(self, ch, method, properties, body): logging.info('message received; callback invoked') # convert body (in bytes) to string message_dict = decode_message(body, self.config.ENCRYPT_KEY) helper.middle_logic(helper.get_listeners(business.process_ekt_events(), message_dict['event_type']), message=message_dict, config=self.config, writer=self.writer) # Regardless of whether the write above is successful we need to # acknowledge receipt of the message to RabbitMQ. This acknowledgement # deletes it from the queue so the logic above must have saved or # handled the message before we get here. ch.basic_ack(delivery_tag=method.delivery_tag)
def callback(self, ch, method, properties, body): logging.info('message received; callback invoked') message_dict = decode_message(body, self.config.ENCRYPT_KEY) result = self.validator.validate(message_dict) logging.info("write to: " + result['queue']) if result['isSuccess']: # Validation SUCCESSFUL if self.writer.publish( result['queue'], encode_message(message_dict, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag) else: # Validation FAILED message_with_errors = add_error_to_message(message_dict, result) if self.writer.publish( result['queue'], encode_message(message_with_errors, self.config.ENCRYPT_KEY)): ch.basic_ack(delivery_tag=method.delivery_tag)
def test_decode_plain_text_message(sample_data): message_bytes = message.encode_message(sample_data, '') message_dict = message.decode_message(message_bytes, '') pprint(message_bytes) assert sample_data == message_dict