Created
June 23, 2016 19:48
-
-
Save ryaminal/a6fa8aff2a7e58070738c525197c938a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kafka import KafkaProducer | |
from functools import partial | |
from vivint_generated.constants import Fields | |
utf8_encode = partial(str.encode, encoding="UTF-8") | |
config = { | |
'bootstrap_servers': 'localhost', | |
'key_serializer': utf8_encode, | |
'value_serializer': utf8_encode, | |
'acks': 0, | |
} | |
k = KafkaProducer(**config) | |
sample_ap_msg = { | |
"_id": "234149061247496|1", | |
"da": {"stuff": "here"}, | |
"t": "account_partition", | |
"op": "u", | |
"panid": 234149061247496, | |
"parid": 1 | |
} | |
sample_as_msg = { | |
"da": {"stuff": "here"}, | |
"_id": 234149060930506, | |
"t": "account_system", | |
"op": "u" | |
} | |
def get_id(msg): | |
msg.get(Fields.PanelId, msg.get(Fields.Id, "No panel id found... strange")) | |
def send_msg(msg): | |
k.send(msg[Fields.Type], get_id(msg), msg) | |
# for i in [sample_ap_msg, sample_as_msg]: | |
# send_msg(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment