def dispatch_mock_sqs_message(message: Message) -> None: from hedwig import consumer sqs_message = mock.Mock() sqs_message.body = json.dumps(message.as_dict()) sqs_message.receipt_handle = 'test-receipt' settings.HEDWIG_PRE_PROCESS_HOOK(sqs_queue_message=sqs_message) consumer.message_handler_sqs(sqs_message)
def publish(message: Message) -> None: """ Publishes a message on Hedwig topic """ if settings.HEDWIG_SYNC: dispatch_mock_sqs_message(message) return message_body = message.as_dict() headers = { **settings.HEDWIG_DEFAULT_HEADERS(message=message), **message_body['metadata']['headers'] } # make a copy to prevent changing "headers" variable contents in # pre serialize hook message_body['metadata']['headers'] = copy.deepcopy(headers) settings.HEDWIG_PRE_SERIALIZE_HOOK(message_data=message_body) payload = _convert_to_json(message_body) topic = _get_sns_topic(message) response = _publish_over_sns(topic, payload, headers) _log_published_message(message_body, response['MessageId'])