|
1 | 1 | package com.hivemq.extensions.kafka.api.services;
|
2 | 2 |
|
| 3 | +import com.hivemq.extension.sdk.api.annotations.Immutable; |
3 | 4 | import com.hivemq.extension.sdk.api.annotations.NotNull;
|
4 | 5 |
|
5 | 6 | import java.util.Map;
|
6 | 7 | import java.util.Set;
|
7 | 8 |
|
| 9 | +/** |
| 10 | + * The KafkaTopicService enables the programmatic interaction with Kafka topics. |
| 11 | + * All methods act on the Kafka cluster, that the calling transformer is associated with. |
| 12 | + * |
| 13 | + * @author Georg Held |
| 14 | + * @see <a href=https://www.hivemq.com/docs/kafka/latest/enterprise-extension-for-kafka/kafka.html#kafka-clusters>Kafka Cluster configuration</a></a>. |
| 15 | + * @since 4.4.0 |
| 16 | + */ |
8 | 17 | public interface KafkaTopicService {
|
9 | 18 |
|
| 19 | + /** |
| 20 | + * Query the state of a single Kafka topic on the associated cluster. |
| 21 | + * <p> |
| 22 | + * This method can block the calling transformer. |
| 23 | + * |
| 24 | + * @param topic the name of a Kafka topic. |
| 25 | + * @return the {@link KafkaTopicState} of the topic. Possible values here are {@link KafkaTopicState#FAILURE}, |
| 26 | + * {@link KafkaTopicState#EXISTS} and {@link KafkaTopicState#MISSING}. |
| 27 | + */ |
10 | 28 | @NotNull KafkaTopicState getKafkaTopicState(@NotNull String topic);
|
11 | 29 |
|
12 |
| - @NotNull Map<String, @NotNull KafkaTopicState> getKafkaTopicStates(@NotNull Set<@NotNull String> topics); |
| 30 | + /** |
| 31 | + * Query the states of multiple Kafka topics on the associated cluster. |
| 32 | + * <p> |
| 33 | + * The returned map contains exactly one entry per queried topic in the argument set. |
| 34 | + * <p> |
| 35 | + * This method can block the calling transformer. |
| 36 | + * |
| 37 | + * @param topics a set containing the names of Kafka topics. |
| 38 | + * @return a mapping of the queried Kafka topics to their {@link KafkaTopicState}. Possible values here are |
| 39 | + * {@link KafkaTopicState#FAILURE}, {@link KafkaTopicState#EXISTS} and {@link KafkaTopicState#MISSING}. |
| 40 | + */ |
| 41 | + @Immutable @NotNull Map<String, @NotNull KafkaTopicState> getKafkaTopicStates(@NotNull Set<@NotNull String> topics); |
13 | 42 |
|
| 43 | + /** |
| 44 | + * Create a single Kafka topic on the associated cluster. |
| 45 | + * Use {@link KafkaTopicService#getKafkaTopicState(String)} if you would like to check, whether the topic already exists. |
| 46 | + * <p> |
| 47 | + * This method can block the calling transformer. |
| 48 | + * <p> |
| 49 | + * |
| 50 | + * @param topic the name of a new Kafka topic. |
| 51 | + * @return the {@link KafkaTopicState} of the topic after this methods completes. Possible values here are {@link KafkaTopicState#FAILURE}, |
| 52 | + * {@link KafkaTopicState#EXISTS} and {@link KafkaTopicState#CREATED}. |
| 53 | + */ |
14 | 54 | @NotNull KafkaTopicState createKafkaTopic(@NotNull String topic);
|
15 | 55 |
|
| 56 | + /** |
| 57 | + * Create multiple Kafka topics on the associated cluster. |
| 58 | + * Use {@link KafkaTopicService#getKafkaTopicStates(Set)} if you would like to check, whether the topics already |
| 59 | + * exists. |
| 60 | + * <p> |
| 61 | + * * The returned map contains exactly one entry per queried topic in the argument set. |
| 62 | + * <p> |
| 63 | + * This method can block the calling transformer. |
| 64 | + * |
| 65 | + * @param topics a set containing the names of new Kafka topics. |
| 66 | + * @return a mapping of the Kafka topics to their {@link KafkaTopicState} after this method completes. Possible values |
| 67 | + * here are {@link KafkaTopicState#FAILURE}, {@link KafkaTopicState#EXISTS} and {@link KafkaTopicState#CREATED}. |
| 68 | + */ |
16 | 69 | @NotNull Map<String, @NotNull KafkaTopicState> createKafkaTopics(@NotNull Set<@NotNull String> topics);
|
17 | 70 |
|
| 71 | + /** |
| 72 | + * KafkaTopicState encodes the current known state of a Kafka topic on the associated cluster. |
| 73 | + */ |
18 | 74 | enum KafkaTopicState {
|
19 |
| - FAILURE, EXISTS, CREATED, MISSING, |
| 75 | + /** |
| 76 | + * FAILURE signals that the operation for the topic was not successful. No possible information about the true |
| 77 | + * state of this topic on the Kafka cluster can be assumed. |
| 78 | + */ |
| 79 | + FAILURE, |
| 80 | + /** |
| 81 | + * This topic is missing from the associated Kafka cluster and may need to be created before a record can be published |
| 82 | + * to it. |
| 83 | + */ |
| 84 | + MISSING, |
| 85 | + /** |
| 86 | + * This topic already exists on the associated Kafka cluster. |
| 87 | + */ |
| 88 | + EXISTS, |
| 89 | + /** |
| 90 | + * This topic was created on the associated Kafka cluster. |
| 91 | + */ |
| 92 | + CREATED, |
20 | 93 | }
|
21 | 94 | }
|
0 commit comments