The Knights Who Say NIO: SwiftNIO in Depth
summary
Built a working MQTT broker on SwiftNIO using channels, pipelines, and event loop groups, with a ByteToMessageDecoder/encoder for MQTT’s fixed header and remaining-length parsing, and tests run via EmbeddedChannel decoder verifier. Core data uses ByteBuffer copy-on-write to avoid allocations; published messages use an encode-once outbound optimization to reuse one encoded buffer for thousands of subscribers. Implementation compiles, passes parser tests, and took about 40 hours; enterprise brokers can scale to ~10 million connections.
AI-written summary · about
chapters (23)
- 0:00Intro
- 0:15MQTT
- 2:02MQTT Packet Structure
- 3:20Ping Packet Structure
- 4:31What is SwiftNIO
- 5:26Event Loops
- 7:36Channel
- 8:40Pipeline
- 9:40Channel Handler Protocol
- 10:36Channel Outbound Inbound Events
- 12:23Channel Handler Context
- 13:19What is NIO
- 14:30bytebuffer
- 15:52bytebuffer implementation
- 17:08channelread implementation
- 19:32bytemessage decoder
- 22:42bootstrap
- 24:58plan
- 26:09packet decoder
- 29:26parsing packets
- 31:17packet encoder
- 33:29outbound optimisation
- 35:17NIO tests
related talks
22mEvent driven networking for Swift
05mSwift Superpowers #2
18mImplementing JSON-RPC with SwiftNIO
21mSwift NIO, Vapor, and Server Concurrency
52mA C++ MQTT Message Broker for the Enterprise
27mBuilding the Server-side Swift ecosystem
23mIntroduction to AsyncHTTPClient
22mBuilding a Social Network in Swift
