Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message key to the Kafka messages for adding hosts #126

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions yuptoo/lib/produce.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def init_producer():
return producer


def send_message(kafka_topic, msg, request_obj=None):
def send_message(kafka_topic, msg, kafka_message_key, request_obj=None):

def delivery_report(err, msg=None, is_msg_for_hbi=False):
nonlocal request_obj
Expand All @@ -37,9 +37,10 @@ def delivery_report(err, msg=None, is_msg_for_hbi=False):

try:
bytes = json.dumps(msg, ensure_ascii=False).encode("utf-8")
key = kafka_message_key.encode("utf-8")
if kafka_topic == UPLOAD_TOPIC:
org_id = request_obj.get('org_id') if request_obj else None
key = org_id.encode("utf-8") if org_id else None
if not key:
raise KafkaException ("Org_id as a key in Kafka messages destined for hbi")
producer.produce(kafka_topic, bytes, key, callback=partial(delivery_report, is_msg_for_hbi=True))
else:
producer.produce(kafka_topic, bytes, callback=delivery_report)
Expand Down
2 changes: 1 addition & 1 deletion yuptoo/processor/report_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def upload_to_host_inventory_via_kafka(host, request_obj):
'platform_metadata': {'request_id': host['system_unique_id'],
'b64_identity': request_obj['b64_identity']}
}
send_message(UPLOAD_TOPIC, upload_msg, request_obj)
send_message(UPLOAD_TOPIC, upload_msg, host.org_id, request_obj)
except Exception as err:
LOG.error(f"The following error occurred: {err}")

Expand Down
Loading