df5ec93dc3
- Trino catalogs, Grafana, Spark jobs, LDAP LDIF, NPM compose - Airflow DAG scripts, Proxmox VM inventory, network docs - Ansible playbook, Gitea CI validate workflow - Backup and health-check scripts, cron documentation - Homepage DOCS tab with links to all documentation - Extended collect-fleet-config.sh and populate-repo.py
39 lines
1013 B
Python
39 lines
1013 B
Python
from kafka import KafkaConsumer
|
|
import boto3
|
|
import json
|
|
from datetime import datetime
|
|
|
|
KAFKA_BROKER = "10.0.21.36:9092"
|
|
KAFKA_TOPIC = "test-lakehouse"
|
|
S3_ENDPOINT = "http://10.0.20.111:9020"
|
|
S3_BUCKET = "data"
|
|
S3_ACCESS_KEY = "REDACTED"
|
|
S3_SECRET_KEY = "REDACTED"
|
|
|
|
print("Starting consumer...")
|
|
print(f"Kafka: {KAFKA_BROKER}, Topic: {KAFKA_TOPIC}")
|
|
print(f"S3: {S3_ENDPOINT}, Bucket: {S3_BUCKET}")
|
|
|
|
s3 = boto3.client(
|
|
's3',
|
|
endpoint_url=S3_ENDPOINT,
|
|
aws_access_key_id=S3_ACCESS_KEY,
|
|
aws_secret_access_key=S3_SECRET_KEY,
|
|
use_ssl=False,
|
|
verify=False
|
|
)
|
|
|
|
consumer = KafkaConsumer(
|
|
KAFKA_TOPIC,
|
|
bootstrap_servers=[KAFKA_BROKER],
|
|
auto_offset_reset='earliest',
|
|
value_deserializer=lambda x: json.loads(x.decode('utf-8'))
|
|
)
|
|
|
|
print("Waiting for messages...")
|
|
for msg in consumer:
|
|
ts = datetime.now().strftime('%Y%m%d_%H%M%S_%f')
|
|
key = f"kafka/{KAFKA_TOPIC}/msg_{ts}.json"
|
|
s3.put_object(Bucket=S3_BUCKET, Key=key, Body=json.dumps(msg.value))
|
|
print(f"Written: {key}")
|