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
In this stage, you'll send a response with a correlation ID.
2
2
3
-
### Response message
3
+
### The Kafka Wire Protocol
4
4
5
-
Kafka brokers communicate with clients through the [Kafka wire protocol](https://kafka.apache.org/protocol.html). The protocol uses a request-response model, where the client sends a request message and the broker replies with a response message.
5
+
Kafka brokers communicate with clients through the [Kafka wire protocol](https://kafka.apache.org/protocol.html). The protocol uses a request-response model: the client sends a request message, and the broker replies with a response message.
6
6
7
7
A Kafka response message has three parts:
8
8
1.`message_size`
@@ -11,26 +11,32 @@ A Kafka response message has three parts:
11
11
12
12
For this stage, you can ignore the body and just focus on `message_size` and the header. You'll learn about response bodies in a later stage.
13
13
14
-
####The `message_size`field
14
+
### The `message_size`Field
15
15
16
-
The [`message_size`](https://kafka.apache.org/protocol.html#protocol_common) field is a 32-bit signed integer. It specifies the size of the header and body.
16
+
The [`message_size`](https://kafka.apache.org/protocol.html#protocol_common) field is a 32-bit signed integer that specifies the size of the header and body in bytes.
17
17
18
-
For this stage, the tester will only assert that your `message_size` field is 4 bytes long—it won't check the value. You'll implement correct`message_size`values in a later stage.
18
+
All integers in the Kafka protocol are in [big-endian](https://developer.mozilla.org/en-US/docs/Glossary/Endianness) byte order. For example, a`message_size`of `2` looks like this:
19
19
20
-
#### Header
20
+
```
21
+
00 00 00 02 // message_size: 2
22
+
```
23
+
24
+
For this stage, you only need to ensure that your `message_size` field is 4 bytes long. You'll implement the correct `message_size` values in a later stage.
21
25
22
-
Kafka has a few different header versions. The way Kafka determines which header version to use is a bit complicated and is outside the scope of this challenge. For more information, take a look at [KIP-482](https://cwiki.apache.org/confluence/display/KAFKA/KIP-482%3A+The+Kafka+Protocol+should+Support+Optional+Tagged+Fields) and this [Stack Overflow answer](https://stackoverflow.com/a/71853003).
26
+
### Response Header v0
23
27
24
-
In this stage, you will use [response header v0](https://kafka.apache.org/protocol.html#protocol_messages) (scroll down).
28
+
Kafka has multiple header versions. In this stage, you will use [response header v0](https://kafka.apache.org/protocol.html#protocol_messages), which is the simplest version.
25
29
26
-
Response header v0 contains a single field: [`correlation_id`](https://developer.confluent.io/patterns/event/correlation-identifier/). This field lets clients match responses to their original requests. Here's how it works:
30
+
Response header v0 contains a single field: [`correlation_id`](https://developer.confluent.io/patterns/event/correlation-identifier/). This field lets clients match responses to their original requests.
27
31
28
-
1. The client generates a correlation ID.
29
-
2. The client sends a request that includes the correlation ID.
30
-
3. The broker sends a response that includes the same correlation ID.
31
-
4. The client receives the response and matches the correlation ID to the original request.
32
+
The `correlation_id` field is also a 32-bit signed integer. For this stage, your program must respond with a hard-coded `correlation_id` of `7`.
32
33
33
-
The `correlation_id` field is a 32-bit signed integer. For this stage, your program must respond with a hard-coded `correlation_id` of 7.
34
+
Putting it all together, your complete response should be 8 bytes long: 4 bytes for `message_size` and 4 bytes for the header (`correlation_id`).
35
+
36
+
```
37
+
00 00 00 00 // message_size: 0 (any value works for this stage)
38
+
00 00 00 07 // correlation_id: 7
39
+
```
34
40
35
41
### Tests
36
42
@@ -39,18 +45,22 @@ The tester will execute your program like this:
39
45
$ ./your_program.sh
40
46
```
41
47
42
-
It'll then connect to your broker on port 9092 and send a request:
48
+
It will then connect to your broker on port `9092` and send a request:
0 commit comments