ventas-kafka-spark · sequence diagram

Scenario C · Spark analytics

Once the simulation finishes, Spark Structured Streaming reads payment.processed from the beginning, processes what is available exactly once (AvailableNow) and prints the per-product summary.

start.shdocker compose run AnaliticaSparkmain() SparkSessionlocal[*] Kafkapayment.processed Consoleformat("console") Start Spark run --rm --no-deps analitica KAFKA_BOOTSTRAP = kafka:9092 builder().master(local[*]).getOrCreate() SparkSession · logLevel WARN Read the payments readStream kafka · subscribe payment.processed startingOffsets = earliest 1 PagoProcesado (JSON) from_json(value, schema) → p.* Transform explode(lineas) → one row per line groupBy(producto) · sum(cantidad, subtotal, iva, total) Write the summary writeStream · complete · Trigger.AvailableNow() Batch 0 Playera azul · 2 · 100.0 · 16.0 · 116.0 Levi's 502 azul · 1 · 600.0 · 96.0 · 696.0 awaitTermination() returns spark.stop() exit 0 · container removed (--rm) Result: 3 units · subtotal 700.0 · VAT 112.0 · total 812.0, in two rows by product
Solid arrows: calls or published messages. Dashed: replies or returns. Green: success. Red: rejections and errors. Dashed amber boxes: alternative branches; dashed blue boxes: optional steps or loops.

What to notice