You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: course-definition.yml
+44-16Lines changed: 44 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -74,25 +74,48 @@ stages:
74
74
name: "Send Correlation ID"
75
75
difficulty: easy
76
76
description_md: |-
77
-
In this stage, you'll start implementing the Kafka wire protocol.
78
-
The response structure is as follows:
77
+
In this stage, you'll respond to a request with a correlation ID.
79
78
80
-
ResponseHeader: V0
79
+
### Kafka wire protocol
81
80
82
-
ResponseHeader:
83
-
CorrelationId: INT32
81
+
The [Kafka wire protocol](https://kafka.apache.org/protocol.html) is a binary protocol used by Kafka brokers and clients to communicate with each other.
84
82
85
-
The response is structured as follows:
83
+
All communication over this protocol happens in request-response pairs. A client sends a request to the broker, and the broker responds with a response.
You'll implement support for this protocol over the next few stages. We'll break down the protocol into smaller pieces and implement them one by one.
86
+
87
+
### Kafka requests
88
+
89
+
Examples of some commonly used Kafka requests:
90
+
91
+
- `APIVersions`, used to get the supported API versions by the broker
92
+
- `Fetch`, used to get data from the broker
93
+
- `Produce`, used to send data to the broker
94
+
95
+
We'll learn about these in detail later, for now we'll focus on the protocol format itself.
94
96
95
-
In general each response in the Kafka wire protocol starts with a INT32 containing the length of the entire message, followed by the ResponseHeader and then the ResponseBody.
97
+
### Request/Response format
98
+
99
+
As described in [the docs](https://kafka.apache.org/protocol.html#protocol_common), each request and response in the Kafka wire protocol starts with 4 bytes that
100
+
describe the length of the entire message (this includes the header & body), followed by the message. This is true for both requests and responses.
101
+
102
+
The first 4 bytes are encoded as an int32 (4 bytes, big-endian / network byte order).
103
+
104
+
For example, if the length of the message is 10, the first 4 bytes (in hexadecimal) will be `00 00 00 0a` (`0a` is the hexadecimal representation of 10).
105
+
106
+
### Response format
107
+
108
+
Each response to a Kafka request contains a header and a body. The header format is the same across all request types, but the body format varies per request.
109
+
110
+
The header format is as follows:
111
+
112
+
- `correlation_id`: An integer that uniquely identifies the request (the client sends this value in the request)
113
+
- This is an "INT32" according to the Kafka wire protocol
114
+
- It is a signed integer, encoded using 4 bytes in the response (big-endian / network byte order)
115
+
- `tag_buffer`: An array of optional "tagged fields"
116
+
- This can be ignored for now, they're [optional tagged fields](https://cwiki.apache.org/confluence/display/KAFKA/KIP-482%3A+The+Kafka+Protocol+should+Support+Optional+Tagged+Fields) used to introduce additional features over time.
117
+
118
+
Note that as mentioned in the previous section, the header is preceded by 4 bytes that describe the length of the entire message (header and body combined).
96
119
97
120
### Tests
98
121
@@ -102,10 +125,15 @@ stages:
102
125
$ ./your_program.sh
103
126
```
104
127
105
-
It'll then try to connect to your server. It will then send a `APIVersions` request. You don't need to implement the logic to parse this request yet, you need to just send the header with a hardcoded correlation ID.
128
+
It'll then connect to your server on port 9092 and send a `APIVersions` request. You don't need to implement the logic to parse this request yet, in this stage the tester
129
+
will only assert that your server sends back a response with a hardcoded correlation ID of `7` (that's `00 00 00 07` in hexadecimal).
106
130
107
-
In this stage, you don't need to add the actual message length, just send a INT32 with any value. And hardcode the CorrelationId to `7`.
131
+
The tester won't validate the first 4 bytes of your response (the "message length") in this stage.
132
+
133
+
### Notes
108
134
135
+
- Since the response format is currently incomplete, the first 4 bytes of your response (the "message length") will not be validated in this stage. We'll come back to this in later stages.
136
+
- In this stage you're expected to hardcode the correlation ID as `7` in your response. We'll get to reading this value from the request in later stages.
109
137
marketing_md: |-
110
138
In this stage, you'll start implementing the ResponseHeader.
0 commit comments