MEGA uses a binary protocol for all communications. Each message follows this general structure:
+----------------+---------------+---------------+-------------+--------------+----------------+
| Correlation | Message | Topic | Topic Name | Timestamp | Optional |
| ID | Type | Length | | | Fields |
+----------------+---------------+---------------+-------------+--------------+----------------+
| 4 bytes | 1 byte | 4 bytes | Variable | 8 bytes | Variable |
- CREATE_TOPIC (0x03)
Header
- PRODUCE (0x01)
Header + Payload Length (4 bytes) + Payload
- CONSUME (0x02)
Header + Offset (4 bytes)
+----------------+---------------+----------------+------------------+
| Correlation | Success | Timestamp | Payload |
| ID | Flag | | |
+----------------+---------------+----------------+------------------+
| 4 bytes | 1 byte | 8 bytes | Variable |
+----------------+---------------+----------------+
| Correlation | Success | Error Code |
| ID | Flag | |
+----------------+---------------+----------------+
| 4 bytes | 1 byte | 1 byte |
- INVALID_REQUEST (1)
- INVALID_MESSAGE_TYPE (2)
- MESSAGE_TOO_LARGE (3)
- TOPIC_NOT_FOUND (4)
- TOPIC_ALREADY_EXISTS (5)
- INVALID_OFFSET (6)
- INTERNAL_ERROR (7)
- NETWORK_ERROR (8)
- RESOURCE_EXHAUSTED (9)
Client -> Broker: CREATE_TOPIC Request
Broker -> Client: Success/Error Response
Client -> Broker: PRODUCE Request
Broker -> Client: Success Response with Offset
Client -> Broker: CONSUME Request with Offset
Broker -> Client: Success Response with Message