Created
October 20, 2022 12:04
-
-
Save danthelion/60c0736ac762a9f64340e09ecdd53f2e to your computer and use it in GitHub Desktop.
Updated schema to produce
This file contains 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
client = SchemaRegistryClient(url="http://127.0.0.1:8081") | |
class User(BaseModel): | |
ts: str | |
name: str | |
country: str | |
date_of_birth: str | |
for i in range(100): | |
data = User( | |
ts=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), | |
name=fake.name(), | |
country=fake.country(), | |
date_of_birth=str(fake.date_of_birth(tzinfo=None, minimum_age=0, maximum_age=100)), | |
) | |
# Get the latest schema from the registry and serialize the message with it | |
compatibility = client.test_compatibility("USERS-value", data.schema_json(), schema_type="JSON") | |
if not compatibility: | |
raise Exception("Schema is not compatible with the latest version") | |
producer.send(topic=TOPIC, key=str(i).encode("utf-8"), value=json.dumps(data.dict()).encode("utf-8")) | |
print(f"Sent message {i} -> {data}") | |
sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment