Pipeline opérationnel Kafka 3.8 · Spark 3.5 · Open-Meteo

Kafka Weather Streaming

Exercices 1 à 5 du TP KAFKA. Pipeline de données météo en temps réel : Open-Meteo, Kafka, Spark Structured Streaming, puis agrégats par fenêtre glissante.

0
Messages weather_stream
0
Messages transformés
0
Villes suivies
0
Fenêtres agrégées
0
Alertes L1/L2

Architecture du pipeline

🌍
Open-Meteo API
données météo live
lat / lon en argument
→
📤
Producer current_weather.py
Ex 1 & 3, envoie JSON
toutes les N secondes
→
⚡
Kafka topic
weather_stream
→
🔄
Spark spark_transform.py
Ex 4, alertes vent / chaleur
wind_alert_level · heat_alert_level
→
⚡
Kafka topic
weather_transformed
→
📊
Spark spark_aggregates.py
Ex 5, fenêtre glissante 5 min
moyenne · min · max · alertes
→
👁️
Consumer / Dashboard
Ex 2, affichage temps réel
ExerciceFichierCe que ça faitStatut
Ex 1create_topics.py · produce_hello.pyCrée weather_stream et envoie {"msg":"Hello Kafka"}✔ fait
Ex 2consumer.pyLit un topic passé en argument, affiche en temps réel✔ fait
Ex 3current_weather.pyInterroge Open-Meteo (lat/lon) → weather_stream✔ fait
Ex 4spark_transform.pyStreaming Spark → alertes vent & chaleur → weather_transformed✔ fait
Ex 5spark_aggregates.pyFenêtre glissante 5 min : moy/min/max température, alertes par type et par ville✔ fait

Exercice 1 : topic et message statique

Topic créés

Message Hello Kafka


      

Exercice 2 : consommateur Kafka

Le script consumer.py --topic <topic> lit les messages du topic passé en argument et les affiche en temps réel (JSON).


  

Exercice 3 : données météo en direct (Open-Meteo)

Messages capturés dans weather_stream : température, vent (m/s), coordonnées et horodatage pour chaque ville.

OffsetVillePaysTemp °CVent m/sEvent timeSource

Exercice 4 : transformation et détection d'alertes (Spark)

Alertes de vent
level_0 < 10 m/s, vent faible
level_1 10-20 m/s, vent modéré
level_2 > 20 m/s, vent fort
Alertes de chaleur
level_0 < 25 °C, température normale
level_1 25-35 °C, chaleur modérée
level_2 > 35 °C, canicule

Sortie de spark_transform.py dans weather_transformed. Colonnes ajoutées : event_time, wind_alert_level, heat_alert_level.

VillePaysTemp °CVent m/sVent alertChaleur alertEvent time

Exercice 5 : agrégats temps réel (fenêtre glissante 5 min, slide 1 min)

Alertes L1/L2 par type + stats température

Fenêtre débutFenêtre finAlertes ventAlertes chaleurTotalMoy °CMinMaxÉvts

Alertes par ville / pays

Fenêtre débutVillePaysAlertesMoy °CÉvts