Last active
November 22, 2022 10:52
-
-
Save rkpattnaik780/13473d69a387317fc332603f18d8f32c to your computer and use it in GitHub Desktop.
Sample producer, consumer and configuration code
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
KAFKA_HOST= | |
RHOAS_SERVICE_ACCOUNT_CLIENT_ID= | |
RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET= |
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 KafkaConsumer | |
consumer = KafkaConsumer(bootstrap_servers=KAFKA_HOST, | |
security_protocol='SASL_PLAINTEXT', | |
sasl_mechanism='PLAIN', | |
sasl_plain_username=RHOAS_SERVICE_ACCOUNT_CLIENT_ID, | |
sasl_plain_password=RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET) | |
consumer.subscribe([TOPIC]) | |
for message in consumer: | |
print message | |
consumer.close() |
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 | |
producer = KafkaProducer(bootstrap_servers=KAFKA_HOST, | |
security_protocol='SASL_PLAINTEXT', | |
sasl_mechanism='PLAIN', | |
sasl_plain_username=RHOAS_SERVICE_ACCOUNT_CLIENT_ID, | |
sasl_plain_password=RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET) | |
producer.send(TOPIC, value=<message-to-send-in-bytes>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I could be wrong but I am not sure where TOPIC is defined in these snippets.
https://gist.github.com/rkpattnaik780/13473d69a387317fc332603f18d8f32c#file-consumer-py-L8