Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC309 Lecture 22

CSC309 Lecture 22

Software Engineering II
MQTT
(202406)

Javier Gonzalez-Sanchez

March 12, 2023
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs CSC 309 Software Engineering II Lecture 21: Publish-Subscribe Service

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227
  2. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    3 What is MQTT? • MQTT (Message Queuing Telemetry Transport) is a lightweight, publish- subscribe network protocol. • Designed for constrained devices and low-bandwidth, high-latency, or unreliable networks. Key Features • Simple and easy to implement. • Low bandwidth consumption. • Reliable message delivery. • Scalable to millions of devices. MQTT
  3. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    7 Pong https://github.com/CSC3100/Pong-Game
  4. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    8 Broker • The central server that handles message distribution. • Examples: Mosquitto, HiveMQ, EMQX, AWS MQ. Clients • Devices or applications that publish (send) and subscribe (receive) messages. • Examples: Sensors, mobile apps, IoT devices. Topics • Hierarchical namespace for organizing messages. • Example: home/livingroom/temperature. MQTT Architecture
  5. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    9 Connect • Clients connect to the broker. Subscribe • Clients subscribe to topics of interest. Publish • Clients publish messages to topics. Receive • Clients receive messages from topics they are subscribed to. Disconnect • Clients disconnect from the broker. MQTT Workflow
  6. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    10 What is Eclipse Paho? • A set of MQTT client libraries developed by the Eclipse Foundation. • It supports multiple languages, such as Java, Python, JavaScript, etc. Java Dependency (Maven) <dependency> <groupId>org.eclipse.paho</groupId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId> <version>1.2.5</version> </dependency> Eclipse Paho for Java
  7. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    12 § 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. Quality-of-service options
  8. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    14 § MQTT: Lightweight, efficient 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 Summary
  9. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    16 Pong https://github.com/CSC3100/Pong-Game
  10. jgs Javier Gonzalez-Sanchez | CSC 309 | Winter 2023 |

    17 Let’s Work * Could you create an MQTT version for Pong? (yes, it is basically joining the 2 source codes) * Could you draw the UML class diagram? * Could it be possible to have 4 players (2 on each side)?
  11. jgs

  12. jgs CSC 309 Software Engineering II Lab 20: MQTT Pong

    Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.com Building 14 -227 Office Hours: By appointment
  13. jgs CSC 309 Software Engineering II Javier Gonzalez-Sanchez, Ph.D. [email protected]

    Winter 2023 Copyright. These slides can only be used as study material for the class CSC308 at Cal Poly. They cannot be distributed or used for another purpose.