Skip to content

Instantly share code, notes, and snippets.

@danthelion
Created October 20, 2022 10:55
Show Gist options
  • Save danthelion/b71f42fdc701b0003916712be5d36f1a to your computer and use it in GitHub Desktop.
Save danthelion/b71f42fdc701b0003916712be5d36f1a to your computer and use it in GitHub Desktop.
fake user producer
TOPIC = "USERS"
def push_messages():
producer = KafkaProducer(
bootstrap_servers=BOOTSTRAP_SERVERS,
)
fake = Faker()
for i in range(100):
data = {
"ts": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"),
"name": fake.name(),
"country": fake.country(),
"age": str(fake.random_int(0, 100)),
}
producer.send(topic=TOPIC, key=str(i).encode("utf-8"), value=json.dumps(data).encode("utf-8"))
print(f"Sent message {i} -> {data}")
sleep(2)
if __name__ == "__main__":
push_messages()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment