🤖Building a Telegram bot with Apache Kafka and ksqlDB

A presentation at DataEngBytes in August 2020 in by Robin Moffatt

Slide 1

Slide 1

🤖Building a Telegram bot with Apache Kafka and ksqlDB @rmoff

Slide 2

Slide 2

Slide 3

Slide 3

How many spaces are available in this car park?

Slide 4

Slide 4

Where’s my nearest carpark with available spaces?

Slide 5

Slide 5

💡Tell me when a car park with spaces is available

Slide 6

Slide 6

📈How does occupancy vary over time?

Slide 7

Slide 7

@rmoff | @confluentinc

Slide 8

Slide 8

$ whoami > Robin Moffatt (@rmoff) > Senior Developer Advocate at Confluent (Apache Kafka, not Wikis 😉) > Working in data & analytics since 2001 > Oracle ACE Director (Alumnus) http://rmoff.dev/talks · http://rmoff.dev/blog · http://rmoff.dev/youtube @rmoff | @confluentinc

Slide 9

Slide 9

Telegram @rmoff | @confluentinc

Slide 10

Slide 10

Telegram Bot @rmoff | @confluentinc

Slide 11

Slide 11

Don’t just tell me… show me! Demo code: https://rmoff.dev/carparks

Slide 12

Slide 12

API all the things! ➜ http https:!//datahub.bradford.gov.uk/ebase/api/getData/v2/Council/CarParkCurrent HTTP/1.1 200 OK Access-Control-Allow-Origin: * Access-Control-Allow-Origin: * Cache-Control: private Content-Disposition: attachment; filename=”carParkCurrent.csv” Content-Encoding: gzip Content-Length: 381 Content-Type: “text/csv” Date: Tue, 28 Jul 2020 10:59:52 GMT Server: Microsoft-IIS/8.5 Set-Cookie: JSESSIONID=5433FDC610177C14204184E7218C8370; Path=/ebase/; Secure; HttpOnly ntCoent-Length: 1021 date,time,name,capacity,empty_places,status,latitude,longitude,directionsURL 2020-07-28,11:52,Westgate,116,74,Spaces,53.796291,-1.759143,”https:”//maps.google.com/?daddr=53.796291,-1.759143” 2020-07-28,11:52,Burnett St,122,110,Spaces,53.795739,-1.744756,”https:”//maps.google.com/?daddr=53.795739,-1.…” 2020-07-28,11:52,Crown Court,142,90,Spaces,53.792179,-1.748466,”https:”//maps.google.com/?daddr=53.792179,-…” 2020-07-28,11:52,Leisure Exchange,996,944,Spaces,53.79222,-1.746683,”https:”//maps.google.com/?daddr=53.79222,-…” 2020-07-28,11:52,NCP Hall Ings,526,490,Spaces,53.791838,-1.752201,”https:”//maps.google.com/?daddr=53.791838,-…” @rmoff | @confluentinc

Slide 13

Slide 13

Streaming Data Ingest carparks HTTP curl | kafkacat Kafka Unix pipes FTW 🙌 @rmoff | @confluentinc

Slide 14

Slide 14

Streaming Data Transformation carparks ksqlDB Kafka CARPARK_EVENTS CREATE STREAM CARPARK_EVENTS WITH (VALUE_FORMAT=’PROTOBUF’) AS SELECT *, STRUCT(“lat” := LATITUDE, “lon”:= LONGITUDE), ‘v2/CarParkCurrent’ AS SRC FROM CARPARK_SRC EMIT CHANGES; @rmoff | @confluentinc

Slide 15

Slide 15

K/V Lookups (materialised views) ksqlDB Kafka CARPARK_EVENTS CREATE TABLE CARPARK AS SELECT … @rmoff | @confluentinc

Slide 16

Slide 16

K/V Lookups (materialised views) How many spaces are free at “ Westgate carpark right now? ksqlDB ” Kafka CARPARK_EVENTS CREATE TABLE CARPARK AS SELECT … @rmoff | @confluentinc

Slide 17

Slide 17

K/V Lookups (materialised views) SELECT SPACES_AVAILABLE How many spaces are free at “ FROM CARPARK WHERE NAME=’WESTGATE’; Westgate carpark right now? ksqlDB ” Kafka CARPARK_EVENTS CREATE TABLE CARPARK AS SELECT … @rmoff | @confluentinc

Slide 18

Slide 18

K/V Lookups (materialised views) SELECT SPACES_AVAILABLE How many spaces are free at “ FROM CARPARK WHERE NAME=’WESTGATE’; Westgate carpark right now? ksqlDB ” Kafka CARPARK_EVENTS 42 CREATE TABLE CARPARK AS SELECT … @rmoff | @confluentinc

Slide 19

Slide 19

K/V Lookups (materialised views) SELECT SPACES_AVAILABLE How many spaces are free at “ FROM CARPARK WHERE NAME=’WESTGATE’; Westgate carpark right now? ksqlDB ” Kafka CARPARK_EVENTS 42 CREATE TABLE CARPARK AS SELECT … “ There are 42 spaces free @rmoff | ” @confluentinc

Slide 20

Slide 20

Stream Processing with ksqlDB Source stream @rmoff | #ConfluentVUG | @confluentinc

Slide 21

Slide 21

Stream Processing with ksqlDB Source stream @rmoff | #ConfluentVUG | @confluentinc

Slide 22

Slide 22

Stream Processing with ksqlDB Source stream @rmoff | #ConfluentVUG | @confluentinc

Slide 23

Slide 23

Stream Processing with ksqlDB Source stream Analytics @rmoff | #ConfluentVUG | @confluentinc

Slide 24

Slide 24

Stream Processing with ksqlDB Source stream Applications / Microservices @rmoff | #ConfluentVUG | @confluentinc

Slide 25

Slide 25

Stream Processing with ksqlDB …SUM(TXN_AMT) GROUP BY AC_ID Source stream Applications / Microservices @rmoff | #ConfluentVUG | @confluentinc

Slide 26

Slide 26

Stream Processing with ksqlDB …SUM(TXN_AMT) GROUP BY AC_ID AC _I D= 42 Source stream Applications / Microservices @rmoff | #ConfluentVUG | @confluentinc

Slide 27

Slide 27

Stream Processing with ksqlDB …SUM(TXN_AMT) GROUP BY AC_ID AC _I D= 42 BA LA NC AC E= _I 94 D= .0 42 0 Source stream Applications / Microservices @rmoff | #ConfluentVUG | @confluentinc

Slide 28

Slide 28

Streaming Analytics Kafka Connect Kafka @rmoff | @confluentinc

Slide 29

Slide 29

Streaming Integration with Kafka Connect Amazon S3 syslog Google BigQuery Kafka Connect @rmoff | Kafka Brokers #ConfluentVUG | @confluentinc

Slide 30

Slide 30

Streaming Analytics @rmoff | @confluentinc

Slide 31

Slide 31

on Photo by Want to learn more? CTAs, not CATs (sorry, not sorry) @rmoff | @confluentinc

Slide 32

Slide 32

60 DE VA DV $50 USD off your bill each calendar month for the first three months when you sign up https://rmoff.dev/ccloud Free money! (additional $60 towards your bill 😄 ) Fully Managed Kafka as a Service * Limited availability. Activate by 11th September 2020. Expires after 90 days of activation. Any unused promo value on the expiration date will be forfeited.

Slide 33

Slide 33

Learn Kafka. Start building with Apache Kafka at Confluent Developer. developer.confluent.io

Slide 34

Slide 34

Confluent Community Slack group cnfl.io/slack @rmoff | @confluentinc

Slide 35

Slide 35

Further reading / watching • Kafka as a Platform: the Ecosystem from the Ground Up • https://rmoff.dev/kafka101 • Apache Kafka and ksqlDB in Action: Let’s Build a Streaming Data Pipeline! • https://rmoff.dev/ljc-kafka-01 • From Zero to Hero with Kafka Connect • https://rmoff.dev/ljc-kafka-02 • Introduction to ksqlDB • https://rmoff.dev/ljc-kafka-03 • Integrating Oracle and Kafka • https://rmoff.dev/oracle-and-kafka • The Changing Face of ETL: Event-Driven Architectures for Data Engineers • https://rmoff.dev/oredev19-changing-face-of-etl • 🚂On Track with Apache Kafka: Building a Streaming Platform solution with Rail Data • https://rmoff.dev/oredev19-on-track-with-kafka @rmoff | @confluentinc

Slide 36

Slide 36

#EOF https://talks.rmoff.net @rmoff