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
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
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
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
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
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)?
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.