Unit 5: Messaging Queues and Publish/Subscribe Communications - Subjective Questions
ECE128 — Introduction To Iot Networking Protocols • Practice Questions with Detailed Answers
20 questions
Define Message Queue Telemetry Transport (MQTT) and explain its main architectural components.
MQTT is a lightweight messaging protocol designed for devices operating over low-bandwidth, high-latency, or unreliable networks. It uses the publish/subscribe communication model and normally operates over TCP/IP.
Its main architectural components are:
- Publisher: Produces data and publishes messages to a named topic.
- Subscriber: Expresses interest in one or more topics and receives matching messages.
- Broker: Receives messages from publishers, filters them according to topics, and forwards them to subscribers.
- Topic: A hierarchical name used to classify messages, such as
factory/machine1/temperature. - MQTT client: Any device or application acting as a publisher, subscriber, or both.
MQTT is suitable for IoT because it has a small packet header, supports asynchronous communication, and provides configurable delivery reliability.
Describe the MQTT connection establishment and message exchange process.
An MQTT communication session generally follows these steps:
- Transport connection: The client establishes a TCP connection with the MQTT broker. A secure connection may use TLS.
- CONNECT packet: The client sends a
CONNECTcontrol packet containing its client identifier, session options, authentication information, keep-alive value, and optional Will information. - CONNACK packet: The broker accepts or rejects the request using a
CONNACKpacket. - Subscription: A subscriber sends
SUBSCRIBEwith one or more topic filters. The broker responds withSUBACK. - Publication: A publisher sends a
PUBLISHpacket containing a topic, payload, QoS level, and other flags. - Message delivery: The broker forwards the message to all matching subscribers.
- Connection maintenance:
PINGREQandPINGRESPpackets can confirm that the connection remains active. - Termination: A client normally sends
DISCONNECTbefore closing the transport connection.
Explain the three MQTT Quality of Service levels and identify a suitable application for each.
MQTT provides three Quality of Service (QoS) levels:
- QoS 0 — At most once: The message is sent once without acknowledgment. Delivery is not guaranteed. It has the lowest overhead and is suitable for frequent sensor readings where occasional loss is acceptable.
- QoS 1 — At least once: The sender retransmits the message until it receives an acknowledgment. The message is guaranteed to arrive, but duplicates may occur. It is suitable for alarms, status updates, and control information when applications can detect duplicates.
- QoS 2 — Exactly once: A multi-step acknowledgment exchange ensures that the message is processed once. It provides the highest reliability but also has the greatest delay and overhead. It is suitable for billing, financial transactions, or critical commands.
The QoS level should be selected by balancing reliability, bandwidth, latency, energy consumption, and processing cost.
Explain retained messages, persistent sessions, and the Last Will and Testament feature of MQTT.
These MQTT features improve availability and reliability:
- Retained message: A publisher marks a message as retained, causing the broker to store the most recent retained message for that topic. A new subscriber immediately receives it instead of waiting for the next publication.
- Persistent session: The broker retains session-related information after a client disconnects. Depending on the MQTT version and configuration, this can include subscriptions and queued QoS messages.
- Last Will and Testament: A client provides a Will topic and Will message during connection establishment. If the client disconnects unexpectedly, the broker publishes the Will message to inform interested subscribers.
For example, an industrial sensor can publish an online status when it connects and configure an offline status as its Will message. Monitoring systems can then detect an unexpected sensor failure.
Compare MQTT and AMQP with respect to architecture, message delivery, overhead, interoperability, and IoT suitability.
MQTT and AMQP are both messaging protocols, but they target different requirements.
| Aspect | MQTT | AMQP |
|---|---|---|
| Communication model | Topic-based publish/subscribe | Brokered messaging with exchanges, queues, bindings, and routing keys |
| Complexity | Simple and lightweight | More feature-rich and comparatively complex |
| Header and bandwidth overhead | Very low | Generally higher |
| Delivery support | QoS 0, 1, and 2 | Reliable delivery, acknowledgments, transactions, and queue controls |
| Routing | Primarily topic-based | Flexible routing through direct, topic, fanout, and header exchanges |
| Device suitability | Well suited to constrained sensors and gateways | Better suited to capable devices, servers, and enterprise back ends |
| Interoperability goal | Efficient telemetry transport | Standardized enterprise messaging and reliable broker interoperability |
| Common applications | Remote monitoring, telemetry, smart homes, and mobile IoT | Banking, business systems, data centers, and enterprise integration |
Conclusion: MQTT is usually preferred when low power, low bandwidth, and simplicity are important. AMQP is preferred when applications require sophisticated routing, durable queues, transactions, and enterprise-level messaging guarantees.
Explain the publish/subscribe communication model and distinguish it from direct request/response communication.
In the publish/subscribe model, publishers send messages to logical topics or channels rather than directly addressing receivers. Subscribers register their interest in selected topics, and a broker distributes matching messages.
Its important characteristics are:
- Space decoupling: Publishers do not need the addresses of subscribers.
- Time decoupling: Publishers and subscribers may not need to be active simultaneously if the broker supports message storage.
- Synchronization decoupling: Publishers can continue their work without waiting for subscribers to process messages.
- One-to-many delivery: One publication may be delivered to several subscribers.
In request/response communication, a client sends a request directly to a known server and normally waits for a response. It is appropriate for immediate queries and commands. Publish/subscribe is more suitable for asynchronous event distribution, telemetry, and situations in which producers and consumers change dynamically.
Discuss the major advantages of using the publish/subscribe model in IoT systems.
The publish/subscribe model provides the following IoT advantages:
- Loose coupling: Sensors and applications do not need direct knowledge of one another.
- Scalability: New publishers and subscribers can be added without changing existing devices.
- Efficient one-to-many communication: A single sensor update can be distributed to many applications.
- Asynchronous operation: Devices can publish without waiting for receivers to respond.
- Simplified integration: Multiple applications can consume the same telemetry through common topics.
- Support for intermittent devices: Brokers can retain or queue selected messages for temporarily disconnected clients.
- Flexible filtering: Subscribers receive only messages matching their topic filters.
- Reduced device complexity: The broker performs message routing and distribution.
These properties are useful in smart cities, industrial monitoring, connected vehicles, agriculture, and home automation.
Analyze the disadvantages of the publish/subscribe model and suggest suitable mitigation techniques.
The publish/subscribe model has several limitations:
- Broker dependency: A centralized broker can become a failure point. This can be mitigated through clustering, replication, and failover brokers.
- Delivery uncertainty: Messages may be lost on unreliable networks. QoS levels, acknowledgments, persistence, and retransmission can improve reliability.
- Duplicate or out-of-order messages: Applications can use message identifiers, timestamps, sequence numbers, and idempotent processing.
- Security complexity: Unauthorized clients may publish or subscribe to sensitive topics. TLS, authentication, access-control lists, and topic-level authorization should be applied.
- Debugging difficulty: Indirect communication makes message tracing harder. Distributed logging, correlation identifiers, and broker monitoring are useful.
- Potential broker overload: High publication rates can exhaust broker resources. Rate limiting, load balancing, topic partitioning, and edge aggregation can reduce load.
- Stale retained data: Retained messages may no longer be valid. Expiry intervals and clear retention policies should be used.
Thus, publish/subscribe improves flexibility but requires careful reliability, security, and broker-capacity planning.
What is session initiation in the Internet of Things? Explain the main information that must be negotiated.
Session initiation is the procedure through which two or more IoT endpoints establish the context needed for communication before application data is exchanged.
The initiation process may negotiate or establish:
- Endpoint identities and addresses
- Application or service being requested
- Media or data format, such as a sensor-data representation or audio codec
- Transport protocol and port numbers
- Security parameters, including authentication and encryption choices
- Quality requirements, such as delay, reliability, or bandwidth
- Session lifetime and refresh rules
- Device capabilities and resource limitations
The process normally includes a session request, an acceptance or rejection response, and an acknowledgment or confirmation. In IoT, session initiation must minimize message size, processing cost, delay, and radio use.
Explain the concept of lightweight sessions in IoT and state the characteristics expected from a lightweight session mechanism.
A lightweight session maintains only the essential communication state needed by constrained IoT devices. It avoids the large messages, repeated negotiations, and complex state machines commonly used in traditional multimedia or enterprise systems.
A lightweight session mechanism should provide:
- Small message size to reduce bandwidth and fragmentation
- Few signaling exchanges to reduce latency and radio energy consumption
- Compact state information to fit limited memory
- Simple parsing for low-power processors
- Support for sleeping and intermittently connected devices
- Reliable retransmission when an unreliable transport is used
- Capability discovery and minimal parameter negotiation
- Authentication and replay protection with acceptable overhead
- Simple session refresh, modification, and termination
Such sessions are useful for constrained sensors, actuators, wearable devices, and low-power wireless nodes.
Describe a constrained session initiation protocol and explain how it reduces signaling overhead for IoT devices.
A constrained session initiation protocol, often represented by lightweight or constrained adaptations of SIP such as CoSIP, provides session establishment functions while reducing the overhead of conventional SIP.
It can reduce overhead through:
- Compact message encoding instead of lengthy textual headers
- Short method names or numeric option identifiers
- Removal of headers not required by constrained applications
- Reduced number of request-response exchanges
- Reuse of existing security and transport contexts
- Caching of endpoint capabilities and session parameters
- Operation through a gateway or proxy that translates between constrained signaling and standard Internet protocols
- Support for lightweight transports and retransmission timers
The protocol should still provide endpoint discovery, capability negotiation, session creation, modification, and termination. A gateway-based design is especially useful because constrained devices perform simple signaling while the gateway handles complex routing, translation, and interoperability.
Describe a complete session initiation sequence between an IoT client and an IoT service.
A typical session initiation sequence is as follows:
- Discovery: The client discovers the service directly, through a resource directory, or through a gateway.
- Initial request: The client sends an initiation request containing its identity, desired service, supported formats, transport details, and proposed session parameters.
- Authentication: The service verifies credentials or performs a security handshake when required.
- Capability negotiation: The service checks whether it supports the requested data format, transport, reliability, and security options.
- Provisional response: An intermediate response may indicate that the request is being processed.
- Final response: The service accepts the proposal, returns modified parameters, or rejects it with a reason.
- Acknowledgment: The client confirms acceptance of the negotiated parameters when the protocol requires it.
- Resource allocation: Both endpoints create session state, timers, buffers, and security contexts.
- Data exchange: Sensor data, commands, or media are transferred according to the agreed parameters.
A constrained design may combine or omit some steps to reduce packet count. Each message should include a transaction or session identifier so that retransmissions are not mistaken for new sessions.
Explain session tear-down in IoT and distinguish graceful termination from abnormal termination.
Session tear-down releases the state and resources associated with an active session.
In a graceful termination:
- One endpoint sends a termination request containing the session identifier.
- The peer stops or completes ongoing data transfer.
- The peer returns a confirmation response.
- Both endpoints release buffers, timers, ports, and temporary security state.
- Logs or final delivery records may be stored.
In an abnormal termination, a device may lose power, move out of coverage, or experience a network failure without sending a termination request. The other endpoint detects the failure through keep-alive expiry, inactivity timers, retransmission limits, transport closure, or a broker Will message.
Graceful tear-down avoids stale state and confirms completion. Abnormal tear-down depends on timers and failure detection, so resources may remain allocated until a timeout occurs.
What is session modification? Explain how an active IoT session can be modified safely.
Session modification changes one or more parameters of an already established session without creating an entirely new session.
Parameters that may be modified include:
- Data format or encoding
- Sampling or publication rate
- Destination address or port
- Reliability or QoS level
- Security algorithm or key context
- Device role or stream direction
- Session expiry time
A safe modification procedure is:
- The requester sends a modification message containing the current session identifier and proposed changes.
- The receiver validates the request and checks resource availability.
- The receiver accepts, rejects, or provides alternative parameters.
- Both sides agree on when the new parameters become active.
- The requester acknowledges the result if required.
- Both endpoints update their session state consistently.
Version numbers, transaction identifiers, acknowledgments, and rollback rules prevent inconsistent state when messages are lost or duplicated.
Compare conventional SIP with a lightweight constrained session initiation approach for IoT.
| Aspect | Conventional SIP | Constrained session initiation |
|---|---|---|
| Message representation | Textual and relatively verbose | Compact textual or binary encoding |
| Header usage | Many flexible headers | Only essential fields are retained |
| Processing requirements | Requires more parsing and memory | Designed for simple processors and small memory |
| Signaling exchanges | May involve several requests and responses | Attempts to minimize round trips |
| Typical transport | UDP, TCP, or TLS | Lightweight transports or optimized UDP-based operation |
| Target environment | Internet telephony and multimedia systems | Sensors, actuators, gateways, and low-power networks |
| Infrastructure | SIP proxies, registrars, and redirect servers | Lightweight proxies, gateways, or resource directories |
| Energy consumption | Often unsuitable for highly constrained nodes | Designed to minimize radio-on time and computation |
Both approaches can support session creation, modification, and termination. However, a constrained approach simplifies encoding, state management, retransmission, discovery, and negotiation to suit limited bandwidth, energy, processing capacity, and memory.
Distinguish between topics and message queues, and explain how MQTT and AMQP use these concepts.
A topic is a logical classification or routing name. Publishers send messages under a topic, and any subscriber with a matching filter can receive them. The same publication may therefore be delivered to many subscribers.
A message queue stores messages until they are consumed. In a competing-consumer arrangement, each queued message is normally processed by one consumer, which supports workload distribution.
- MQTT: Primarily uses hierarchical topics. The broker matches publications against subscriptions. Persistent sessions and queued QoS messages can provide queue-like behavior for offline clients.
- AMQP: Explicitly separates producers, exchanges, bindings, and queues. An exchange routes a message to one or more queues according to routing rules, and consumers retrieve messages from those queues.
Topics are ideal for event distribution, while queues are ideal for durable work processing and load sharing. AMQP exposes queue and routing structures directly, whereas MQTT offers a simpler topic-centered abstraction.
Design an MQTT-based publish/subscribe solution for a smart-building temperature and fire-alert system.
A suitable design includes the following elements:
- Publishers: Temperature, smoke, and fire sensors installed in rooms.
- Broker: A local building broker with an optional connection to a cloud platform.
- Subscribers: Dashboards, alarm controllers, maintenance applications, and emergency services.
- Topic hierarchy: Examples include
building/floor1/room101/temperatureandbuilding/floor1/room101/fire. - Temperature QoS: Routine temperature values can use QoS 0 because newer readings replace older ones.
- Fire-alert QoS: Fire events should use QoS 1 or QoS 2 according to the required reliability and acceptable overhead.
- Retained state: The latest room status can be retained so that a newly connected dashboard receives it immediately.
- Last Will: Each gateway can configure an offline-status Will message.
- Security: TLS, unique client credentials, topic-level authorization, and certificate rotation should be used.
- Availability: A clustered or backup broker can reduce the risk of a single point of failure.
The design separates data producers from consumers, allows several applications to receive the same alarm, and supports future expansion without changing sensor addressing.
Discuss reliability and security requirements during IoT session initiation, maintenance, and termination.
Reliability requirements include:
- Transaction and session identifiers to match requests with responses
- Retransmission timers for lost signaling messages
- Duplicate detection and idempotent request processing
- Keep-alive or inactivity timers to detect failed peers
- Consistent cleanup after normal or abnormal termination
- Recovery or resumption after temporary disconnection
Security requirements include:
- Mutual or server-side authentication
- Authorization for requested services and session changes
- Confidentiality through TLS, DTLS, or another suitable secure channel
- Integrity protection to prevent message modification
- Nonces, timestamps, or sequence numbers to prevent replay attacks
- Secure key establishment and renewal
- Protection against resource-exhaustion and denial-of-service attacks
Security must be applied throughout the session lifecycle. An authenticated initiation is insufficient if later modification or termination messages can be forged. Constrained devices may use gateways, compact credentials, or pre-established security contexts to reduce overhead.
Explain how MQTT session persistence supports intermittently connected IoT devices.
MQTT session persistence allows a client to disconnect temporarily without losing all broker-side session information.
- In MQTT 3.1.1, the client uses the Clean Session flag to request a new temporary session or resume a stored session.
- In MQTT 5, Clean Start and Session Expiry Interval provide more precise control over session creation and lifetime.
- A persistent session may retain subscriptions and queued QoS messages, depending on protocol rules and broker configuration.
- When the client reconnects using the same client identifier, the broker can restore the session and deliver pending messages.
This is useful for battery-powered devices that sleep to conserve energy or devices that frequently lose wireless connectivity. However, long-lived sessions consume broker memory and storage. Therefore, administrators should select reasonable expiry intervals, queue limits, message-expiry values, and policies for inactive clients.
Develop a state-based model for the lifecycle of a lightweight IoT session, covering initiation, operation, modification, failure handling, and tear-down.
A lightweight IoT session can be represented by the following conceptual states:
- Idle: No session state exists. A discovery result or application event triggers initiation.
- Initiating: A session request has been sent. The endpoint waits for acceptance, rejection, or timeout.
- Negotiating: Endpoints select compatible transport, format, security, and reliability parameters.
- Established: Negotiation has succeeded, resources are allocated, and application data can be exchanged.
- Modifying: One endpoint requests a parameter change. The existing configuration remains active until the modification is accepted, unless the protocol defines otherwise.
- Suspended or reconnecting: Connectivity is temporarily lost, but resumable session state is retained for a limited time.
- Terminating: A tear-down request or local shutdown begins resource release.
- Closed: Session state has been removed and allocated resources have been released.
- Failed: Initiation, modification, or maintenance has failed. Cleanup is performed before returning to the idle or closed state.
Important transitions include:
IdletoInitiatingafter a session requestInitiatingtoEstablishedafter successful negotiationEstablishedtoModifyingafter a change requestModifyingtoEstablishedafter acceptance or rollbackEstablishedtoSuspended or reconnectingafter temporary network lossEstablishedtoTerminatingafter a termination request- Any active state to
Failedafter timeout, authentication failure, or unrecoverable error
Timers, transaction identifiers, acknowledgments, and duplicate detection are essential for deterministic transitions. The model prevents stale resources and inconsistent endpoint state while keeping signaling suitable for constrained devices.
Define Message Queue Telemetry Transport (MQTT) and explain its main architectural components.
MQTT is a lightweight messaging protocol designed for devices operating over low-bandwidth, high-latency, or unreliable networks. It uses the publish/subscribe communication model and normally operates over TCP/IP.
Its main architectural components are:
- Publisher: Produces data and publishes messages to a named topic.
- Subscriber: Expresses interest in one or more topics and receives matching messages.
- Broker: Receives messages from publishers, filters them according to topics, and forwards them to subscribers.
- Topic: A hierarchical name used to classify messages, such as
factory/machine1/temperature. - MQTT client: Any device or application acting as a publisher, subscriber, or both.
MQTT is suitable for IoT because it has a small packet header, supports asynchronous communication, and provides configurable delivery reliability.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →