Skip to content

Instantly share code, notes, and snippets.

@rkpattnaik780
Last active November 22, 2022 10:52
Show Gist options
  • Save rkpattnaik780/13473d69a387317fc332603f18d8f32c to your computer and use it in GitHub Desktop.
Save rkpattnaik780/13473d69a387317fc332603f18d8f32c to your computer and use it in GitHub Desktop.
Sample producer, consumer and configuration code
KAFKA_HOST=
RHOAS_SERVICE_ACCOUNT_CLIENT_ID=
RHOAS_SERVICE_ACCOUNT_CLIENT_SECRET=
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()
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>)
@jackdelahunt
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment