16 XMPP: Messaging Foundations
Start with the story: XMPP is useful when an IoT system needs addressed conversations, presence, discovery, or federation rather than just another telemetry pipe. Start by asking who needs to know that a device is present, what stanza carries the fact, and whether the extra semantics are worth operating.
16.1 Start With the Decision
An XMPP stanza can carry device state through a long-lived session. The design must name the transport, address, extension, and delivery limit.
16.2 Route Overview
This is part 1 of 2. Continue with XMPP: Protocol Fit and Operations.
16.3 Part Objectives
- Trace XMPP streams, stanzas, addressing, and extensions.
- Identify delivery and scaling limits for IoT messaging.
16.4 Chapter Roadmap
- In 60 Seconds
- Reference Anchors
- XMPP Review Route
- Architecture Roles
- Authentication and Channel Security
- Stanza Roles
- Addressing and Discovery
- Presence and PubSub
- IoT Extension Evidence
16.5 Learning Objectives
By the end of this chapter, you should be able to:
- Explain the core XMPP roles: client, server, stream, stanza, JID, and federation.
- Distinguish message, presence, and IQ stanzas by their system role.
- Describe how service discovery and PubSub extensions fit into an IoT architecture.
- Identify what evidence is needed before using XMPP IoT extensions in a real design.
- Compare XMPP with MQTT, AMQP, CoAP, and WebSocket-based designs using requirements evidence.
- Build a protocol-fit record without relying on stale bandwidth, cost, or vendor claims.
16.6 Reference Anchors
Use current standards and implementation documents before making a deployment decision:
Read these points as one connected sequence: start with RFC 6120: XMPP Core: XML streams, client-to-server and server-to-server behavior, stanza semantics, STARTTLS, SASL, resource binding, and security considerations; then RFC 6121: XMPP Instant Messaging and Presence: presence subscriptions, rosters, messaging behavior, and IM-oriented presence rules; then RFC 7622: XMPP Address Format: modern JID address format replacing the older RFC 6122 address definition; then RFC 7395: XMPP over WebSocket: WebSocket transport for XMPP when browser or web-proxy environments need it; then XEP-0030: Service Discovery: discovering entity identity, supported features, and associated items; then XEP-0060: Publish-Subscribe: PubSub nodes, subscriptions, publications, notifications, and access models; then XEP-0323: Internet of Things - Sensor Data: XMPP sensor-data extension; and finish with XEP-0325: Internet of Things - Control: XMPP control extension for writable device fields.
- RFC 6120: XMPP Core: XML streams, client-to-server and server-to-server behavior, stanza semantics, STARTTLS, SASL, resource binding, and security considerations.
- RFC 6121: XMPP Instant Messaging and Presence: presence subscriptions, rosters, messaging behavior, and IM-oriented presence rules.
- RFC 7622: XMPP Address Format: modern JID address format replacing the older RFC 6122 address definition.
- RFC 7395: XMPP over WebSocket: WebSocket transport for XMPP when browser or web-proxy environments need it.
- XEP-0030: Service Discovery: discovering entity identity, supported features, and associated items.
- XEP-0060: Publish-Subscribe: PubSub nodes, subscriptions, publications, notifications, and access models.
- XEP-0323: Internet of Things - Sensor Data: XMPP sensor-data extension.
- XEP-0325: Internet of Things - Control: XMPP control extension for writable device fields.
These are review anchors, not deployment proof. A real project still needs server support, client libraries, extension compatibility, security review, privacy review, field testing, and operations evidence.
16.7 XMPP Review Route
Start by deciding whether the project needs XMPP semantics or only a transport for device data.
Use Figure 16.1 to keep that decision evidence-led. Begin with the application need, then move from standards claims to implementation and field proof before comparing alternatives.
Read Figure 16.1 from left to right. First name the required semantic—presence, directed messaging, discovery, PubSub, or federation. Next identify the RFC or XEP that defines it, then prove that the selected server and client implement the same feature. Field validation follows because standards support alone says nothing about operations, failure, or interoperability. Only then compare a simpler protocol, preserving the chapter’s distinction between an attractive capability and deployable evidence.
Use this route:
- Record the application need: presence, directed messaging, discovery, PubSub, federation, human-device interaction, or history.
- Map the need to XMPP standards: core streams, stanza type, JID addressing, discovery, PubSub, IoT extensions, or WebSocket transport.
- Check implementation support in the exact server, client, library, gateway, and device profile.
- Validate security, privacy, operational ownership, monitoring, and failure behavior.
- Compare against simpler alternatives when XMPP semantics are not required.
16.8 Architecture Roles
Federation is clearer when one full JID crosses two administrative domains. Figure 16.2 routes a pump alert from plant.example to a contractor resource at service.example.
In Figure 16.2, Client stream authenticates sensor-7@plant.example/pump, and Federated hop discovers and opens an S2S stream to the recipient domain. Stanza semantics separates <message>, <presence>, and <iq>, while Recipient resource makes /mobile routing and queue policy explicit.
XMPP architecture separates local clients, local servers, optional server-to-server federation, and extension services. That is useful for cross-domain identity and presence, but it also creates more surfaces to operate.
Inspect Figure 16.3 to locate each trust and operations boundary before treating federation as a benefit.
In Figure 16.3, start at a device or application opening its client-to-server stream to the local server. The local server authenticates the entity, binds its resource, and routes local stanzas. Then follow the optional server-to-server path across domains, where DNS, certificates, trust, policy, and abuse controls become shared concerns. Extension services hang from those servers rather than from a magical central broker. This architecture explains why XMPP can federate and why the operating surface grows with that choice.
16.9 Authentication and Channel Security
SASL and TLS are named in the Architecture Roles federation checklist above, but “we use TLS” is not evidence by itself. Review the exact mechanism, because XMPP’s authentication and channel-security defaults have specific, documented gaps.
Record the exact SASL mechanism, the point in the stream where TLS becomes mandatory, and whether channel binding is negotiated before approving an XMPP deployment. “STARTTLS is enforced before any stanza is accepted, and SCRAM-SHA-1-PLUS is the negotiated mechanism” is an evidence record; “we use TLS” is not.
16.10 Stanza Roles
XMPP traffic is built around three core stanza families. Each one answers a different design question.
Use Figure 16.4 to classify the application intent before writing XML. Read the three branches as event delivery, availability state, and correlated request-response.
In Figure 16.4, inspect message first for alerts and notifications that do not require an IQ-style result. Move next to presence, where a state change may fan out to subscribers and therefore carries privacy and load consequences. Finish with iq, whose get, set, result, and error types form a request-response exchange. Keeping those roles distinct makes the examples below design evidence rather than three interchangeable XML envelopes.
Message
Use a message stanza for event-like delivery, alerts, chat-style commands, notifications, or PubSub notifications. A message is not the same as a correlated request-response transaction.
Presence
Use presence when availability state is part of the application. Presence is useful for “device reachable”, “operator online”, “maintenance mode”, or “gateway unavailable” workflows, but it must be designed with privacy and fan-out load in mind.
IQ
Use IQ for structured request-response interactions. Service discovery, roster operations, many extension queries, and device control patterns use IQ-like get, set, result, and error flows.
<message from="sensor-7@plant.example/line-a"
to="dashboard@ops.example/web"
type="chat">
<body>threshold alert: vibration review required</body>
</message>
<presence from="gateway-3@plant.example/west">
<show>away</show>
<status>maintenance window</status>
</presence>
<iq from="controller@ops.example/tablet"
to="pump-2@plant.example/panel"
type="get"
id="read-42">
<query xmlns="urn:xmpp:iot:sensordata"/>
</iq>
Keep examples short. Production designs need schema, namespace, validation, authorization, retry, timeout, and audit records.
16.11 Addressing and Discovery
JIDs identify XMPP entities and resources. Service discovery lets a requester ask what an entity is and which features or items it exposes. That combination is useful for device capability review, but it can also leak information if access control is weak.
Inspect Figure 16.5 as a lifecycle record, beginning with identity naming and ending with deprovisioning rather than stopping when a discovery query succeeds.
Read Figure 16.5 from the JID policy through resource binding, then into discovery authorization. The returned identity, feature, and item lists are useful capability evidence, but they also reveal entity existence and device function, so the privacy boundary must be evaluated alongside access control. Finish at version evidence and deprovisioning: a retired or compromised resource must stop advertising and accepting work. That full route connects addressing to the operational proof required by the review route.
Record:
- JID naming policy for devices, gateways, applications, and users.
- Resource binding behavior for multiple sessions or device roles.
- Which discovery queries are allowed to which requesters.
- Feature list and version evidence for each extension.
- Privacy controls for entity existence, item lists, and device capabilities.
- Deprovisioning behavior when a device is replaced, retired, or compromised.
16.12 Presence and PubSub
Presence and PubSub are the most common reasons to consider XMPP in an IoT workflow. They should be reviewed as application semantics, not as a shortcut around telemetry architecture.
Inspect Figure 16.6 to separate availability from published data before estimating fan-out and storage behavior.
In Figure 16.6, follow presence from an entity’s availability change to authorized watchers, then follow a payload into a PubSub node and out to subscribers. Presence answers whether an entity is reachable or in a named state; PubSub distributes items under node policy and may retain them. The authorization and application handoff apply to both branches. This distinction helps decide whether XMPP semantics are genuinely needed or whether a simpler telemetry broker fits the running workload.
16.13 IoT Extension Evidence
XEP-0323 and XEP-0325 define XMPP extension patterns for sensor data and control. They are useful standards anchors, but a deployment decision must prove support in the selected stack.
Inspect Figure 16.7 from specification to field behavior so an XEP citation cannot substitute for compatibility proof.
Read Figure 16.7 by following one sensor field or control command. Confirm the namespace and field contract first, then check the exact server and client-library implementations. Continue through access control and error behavior before running field tests against disconnects, stale values, rejected writes, and timeouts. The fallback at the end matters because partial XEP support is common. This chain turns an extension choice into the implementation evidence demanded by the opening review route.
Before relying on XMPP IoT extensions, check:
- Server support for the needed XEPs and namespaces.
- Client library support on the device, gateway, browser, or application runtime.
- Field naming, type, unit, timestamp, and validation rules.
- Access control for read and write operations.
- Error behavior for unavailable devices, stale fields, rejected commands, and timeouts.
- Monitoring and fallback if an extension is missing or implemented differently.
16.14 Continue to the Next Part
Carry this evidence into XMPP: Protocol Fit and Operations, which begins with Protocol Fit.
