|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
| 16 | + |
16 | 17 | package com.hivemq.extensions.kafka.api.builders;
|
17 | 18 |
|
18 | 19 | import com.hivemq.extension.sdk.api.annotations.NotNull;
|
|
22 | 23 | import java.nio.charset.Charset;
|
23 | 24 |
|
24 | 25 | /**
|
| 26 | + * The KafkaRecordBuilder enables the creation of {@link KafkaRecord}s via its fluent API. |
| 27 | + * <p> |
| 28 | + * All data in a {@link KafkaRecord} except the topic is optional. Ensure that you set an topic via the {@link |
| 29 | + * KafkaRecordBuilder#topic(String)} method before you call {@link KafkaRecordBuilder#build()}. |
| 30 | + * <p> |
| 31 | + * The internal state of this interface can only be changed via its methods. All arguments, that have mutable data |
| 32 | + * types, are deep copied before the setting method returns. |
| 33 | + * |
25 | 34 | * @author Christoph Schäbel
|
| 35 | + * @author Georg Held |
| 36 | + * @since 4.4.0 |
26 | 37 | */
|
27 | 38 | public interface KafkaRecordBuilder {
|
28 | 39 |
|
| 40 | + /** |
| 41 | + * Set the topic of the Kafka record. |
| 42 | + * <p> |
| 43 | + * This is required to successfully build a {@link KafkaRecord}. |
| 44 | + * |
| 45 | + * @param topic the name of the topic. |
| 46 | + * @return this builder |
| 47 | + * @since 4.4.0 |
| 48 | + */ |
29 | 49 | @NotNull KafkaRecordBuilder topic(@NotNull String topic);
|
30 | 50 |
|
31 |
| - @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull ByteBuffer value); |
32 |
| - |
33 |
| - @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull byte[] value); |
34 |
| - |
35 |
| - @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull String value); |
36 |
| - |
37 |
| - @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull String value, @NotNull Charset charset); |
38 |
| - |
| 51 | + /** |
| 52 | + * Set the key of the Kafka record. |
| 53 | + * |
| 54 | + * @param key the value of the key. |
| 55 | + * @return this builder |
| 56 | + * @since 4.4.0 |
| 57 | + */ |
39 | 58 | @NotNull KafkaRecordBuilder key(@NotNull ByteBuffer key);
|
40 | 59 |
|
| 60 | + /** |
| 61 | + * Set the key of the Kafka record. |
| 62 | + * |
| 63 | + * @param key the value of the key. |
| 64 | + * @return this builder |
| 65 | + * @since 4.4.0 |
| 66 | + */ |
41 | 67 | @NotNull KafkaRecordBuilder key(@NotNull byte[] key);
|
42 | 68 |
|
| 69 | + /** |
| 70 | + * Set the key of the Kafka record. |
| 71 | + * |
| 72 | + * @param key the value of the key. {@link java.nio.charset.StandardCharsets#UTF_8} is used for encoding. |
| 73 | + * @return this builder |
| 74 | + * @since 4.4.0 |
| 75 | + */ |
43 | 76 | @NotNull KafkaRecordBuilder key(@NotNull String key);
|
44 | 77 |
|
| 78 | + /** |
| 79 | + * Set the key of the Kafka record. |
| 80 | + * |
| 81 | + * @param key the value of the key. |
| 82 | + * @param charset the {@link Charset} used for encoding. |
| 83 | + * @return this builder |
| 84 | + * @since 4.4.0 |
| 85 | + */ |
45 | 86 | @NotNull KafkaRecordBuilder key(@NotNull String key, @NotNull Charset charset);
|
46 | 87 |
|
| 88 | + /** |
| 89 | + * Set the value of the Kafka record. |
| 90 | + * |
| 91 | + * @param value the value of the Kafka value. |
| 92 | + * @return this builder |
| 93 | + * @since 4.4.0 |
| 94 | + */ |
47 | 95 | @NotNull KafkaRecordBuilder value(@NotNull ByteBuffer value);
|
48 | 96 |
|
| 97 | + /** |
| 98 | + * Set the value of the Kafka record. |
| 99 | + * |
| 100 | + * @param value the value of the Kafka value. |
| 101 | + * @return this builder |
| 102 | + * @since 4.4.0 |
| 103 | + */ |
49 | 104 | @NotNull KafkaRecordBuilder value(@NotNull byte[] value);
|
50 | 105 |
|
| 106 | + /** |
| 107 | + * Set the value of the Kafka record. |
| 108 | + * |
| 109 | + * @param value the value of the Kafka value. {@link java.nio.charset.StandardCharsets#UTF_8} is used for encoding. |
| 110 | + * @return this builder |
| 111 | + * @since 4.4.0 |
| 112 | + */ |
51 | 113 | @NotNull KafkaRecordBuilder value(@NotNull String value);
|
52 | 114 |
|
| 115 | + /** |
| 116 | + * Set the value of the Kafka record. |
| 117 | + * |
| 118 | + * @param value the value of the Kafka value. |
| 119 | + * @param charset the {@link Charset} used for encoding. |
| 120 | + * @return this builder |
| 121 | + * @since 4.4.0 |
| 122 | + */ |
53 | 123 | @NotNull KafkaRecordBuilder value(@NotNull String value, @NotNull Charset charset);
|
54 | 124 |
|
| 125 | + /** |
| 126 | + * Add a header to the Kafka record. |
| 127 | + * |
| 128 | + * @param key the key of the header. |
| 129 | + * @param value the value of the header. |
| 130 | + * @return this builder |
| 131 | + * @since 4.4.0 |
| 132 | + */ |
| 133 | + @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull ByteBuffer value); |
| 134 | + |
| 135 | + /** |
| 136 | + * Add a header to the Kafka record. |
| 137 | + * |
| 138 | + * @param key the key of the header. |
| 139 | + * @param value the value of the header. |
| 140 | + * @return this builder |
| 141 | + * @since 4.4.0 |
| 142 | + */ |
| 143 | + @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull byte[] value); |
| 144 | + |
| 145 | + /** |
| 146 | + * Add a header to the Kafka record. |
| 147 | + * |
| 148 | + * @param key the key of the header. |
| 149 | + * @param value the value of the header. {@link java.nio.charset.StandardCharsets#UTF_8} is used for encoding. |
| 150 | + * @return this builder |
| 151 | + * @since 4.4.0 |
| 152 | + */ |
| 153 | + @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull String value); |
| 154 | + |
| 155 | + /** |
| 156 | + * Add a header to the Kafka record. |
| 157 | + * |
| 158 | + * @param key the key of the header. |
| 159 | + * @param value the value of the header. |
| 160 | + * @param charset the {@link Charset} used for encoding the {@code value}. |
| 161 | + * @return this builder |
| 162 | + * @since 4.4.0 |
| 163 | + */ |
| 164 | + @NotNull KafkaRecordBuilder header(@NotNull String key, @NotNull String value, @NotNull Charset charset); |
| 165 | + |
| 166 | + /** |
| 167 | + * Set the timestamp of the Kafka record. |
| 168 | + * |
| 169 | + * @param timestamp the value of the Kafka timestamp. |
| 170 | + * @return this builder |
| 171 | + * @since 4.4.0 |
| 172 | + */ |
55 | 173 | @NotNull KafkaRecordBuilder timestamp(long timestamp);
|
56 | 174 |
|
| 175 | + /** |
| 176 | + * Set the partition number of the Kafka record. |
| 177 | + * |
| 178 | + * @param partition the value of the Kafka partition number. |
| 179 | + * @return this builder |
| 180 | + * @since 4.4.0 |
| 181 | + */ |
57 | 182 | @NotNull KafkaRecordBuilder partition(int partition);
|
58 | 183 |
|
| 184 | + /** |
| 185 | + * Create a new {@link KafkaRecord} from the current state of this builder. The builder can be reused afterwards. |
| 186 | + * |
| 187 | + * @return a new {@link KafkaRecord} containing a snapshot of the current state of this builder. |
| 188 | + * @throws NullPointerException if the topic was not set. |
| 189 | + */ |
59 | 190 | @NotNull KafkaRecord build();
|
60 | 191 | }
|
0 commit comments