Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 305 Individual Software Design and Development Lecture 23. Architecture (Distributed Systems) II

Slide 2

Slide 2 text

Collaboration 2 Stu C St F M Pe St C S F M Pe

Slide 3

Slide 3 text

Architecture 3

Slide 4

Slide 4 text

Communication Protocols Sockets • - Wh a t: Low-level communic a tion mech a nism for exch a nging d a t a between two systems. • - How: Utilizes TCP/UDP protocols for reli a ble/unreli a ble d a t a tr a nsfer. • - Use C a se: Direct communic a tion between client-server a pplic a tions (e.g., f ile tr a nsfer a nd ch a t). WebSockets • - Wh a t: Full-duplex communic a tion protocol over a single TCP connection. • - How: En a bles persistent, bidirection a l communic a tion between client a nd server in re a l- time. • - Use C a se: Re a l-time a pplic a tions like live ch a ts, g a ming, a nd stock tr a ding pl a tforms. MQTT (Mess a ge Queuing Telemetry Tr a nsport) • Wh a t: Lightweight mess a ging protocol designed for low-b a ndwidth, high-l a tency networks. • How: Uses a publish-subscribe p a ttern for e ff icient communic a tion between devices. • Use C a se: Ide a l for IoT a pplic a tions, sm a rt home devices, a nd sensor networks. 4

Slide 5

Slide 5 text

Publisher-Subscriber MQTT

Slide 6

Slide 6 text

Message Queuing 6

Slide 7

Slide 7 text

Message Queuing (Topics) 7

Slide 8

Slide 8 text

MQTT Wh a t is MQTT? • MQTT (Mess a ge Queuing Telemetry Tr a nsport) is a lightweight, publish-subscribe network protocol. • Designed for constr a ined devices a nd low-b a ndwidth, high-l a tency, or unreli a ble networks. Key Fe a tures • Simple a nd e a sy to implement. • Low b a ndwidth consumption. • Reli a ble mess a ge delivery. • Sc a l a ble to millions of devices. 8

Slide 9

Slide 9 text

MQTT Architecture Broker • The centr a l server th a t h a ndles mess a ge distribution. • Ex a mples: Mosquitto, HiveMQ, EMQX, AWS MQ. Clients • Devices or a pplic a tions th a t publish (send) a nd subscribe (receive) mess a ges. • Ex a mples: Sensors, mobile a pps, a nd IoT devices. Topics • Hier a rchic a l n a mesp a ces for org a nizing mess a ges. • Ex a mple: home/livingRoom/temper a ture. 9

Slide 10

Slide 10 text

MQTT Work f low Connect • Clients connect to the broker. Subscribe • Clients subscribe to topics of interest. Publish • Clients publish mess a ges to topics. Receive • Clients receive mess a ges from topics they a re subscribed to. Disconnect • Clients disconnect from the broker. 10

Slide 11

Slide 11 text

Eclipse Paho for Java Wh a t is Eclipse P a ho? • A set of MQTT client libr a ries developed by the Eclipse Found a tion. • It supports multiple l a ngu a ges, such a s J a v a , Python, J a v a Script, etc. J a v a Dependency (M a ven) org.eclipse.paho org.eclipse.paho.client.mqttv3 1.2.5 11

Slide 12

Slide 12 text

https://github.com/CSC3100/MQTT

Slide 13

Slide 13 text

Quality-of-service options • 0 – "at most once": A.K.A. "fire-and-forget." This option is suitable when message loss is acceptable, as it doesn't require acknowledgment or persistence. • 1 – "at least once": This option should be chosen when message loss is unacceptable, and your subscribers can handle duplicate messages. • 2 – "Exactly once": This option is ideal when message loss is unacceptable, and your subscribers cannot handle duplicate messages. 13

Slide 14

Slide 14 text

https://github.com/CSC3100/MQTT

Slide 15

Slide 15 text

Summary • MQTT: Lightweight, e ff i cient protocol for IoT and other use cases. • Mosquitto: A popular open-source MQTT broker. • Eclipse Paho: A versatile MQTT client library. • Java Example: https://github.com/CSC3100/MQTT 15

Slide 16

Slide 16 text

Questions 16

Slide 17

Slide 17 text

Lab

Slide 18

Slide 18 text

Challenge 18 * Could you create an MQTT version for the CLICK AND DRAW A DOT app? (yes, it is basically joining the two source codes) * Could it be possible to have it BI-DIRECTIONAL?

Slide 19

Slide 19 text

CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.