├── .editorconfig ├── .github ├── maven-cd-settings.xml ├── maven-ci-settings.xml └── workflows │ ├── ci-4.x.yml │ ├── ci-5.x-stable.yml │ ├── ci-5.x.yml │ ├── ci-matrix-5.x.yml │ ├── ci.yml │ └── deploy.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml └── src ├── main ├── asciidoc │ ├── adminclient.adoc │ ├── index.adoc │ └── rxjava2.adoc ├── generated │ └── io │ │ └── vertx │ │ └── kafka │ │ ├── admin │ │ ├── ClusterDescriptionConverter.java │ │ ├── ConfigConverter.java │ │ ├── ConfigEntryConverter.java │ │ ├── ConfigSynonymConverter.java │ │ ├── ConsumerGroupDescriptionConverter.java │ │ ├── ConsumerGroupListingConverter.java │ │ ├── DescribeClusterOptionsConverter.java │ │ ├── DescribeConsumerGroupsOptionsConverter.java │ │ ├── DescribeTopicsOptionsConverter.java │ │ ├── ListConsumerGroupOffsetsOptionsConverter.java │ │ ├── ListOffsetsResultInfoConverter.java │ │ ├── MemberAssignmentConverter.java │ │ ├── MemberDescriptionConverter.java │ │ ├── NewPartitionsConverter.java │ │ ├── NewTopicConverter.java │ │ ├── OffsetSpecConverter.java │ │ └── TopicDescriptionConverter.java │ │ └── client │ │ └── common │ │ ├── ConfigResourceConverter.java │ │ ├── KafkaClientOptionsConverter.java │ │ ├── PartitionInfoConverter.java │ │ └── TopicPartitionInfoConverter.java └── java │ ├── examples │ ├── KafkaAdminClientExamples.java │ ├── VertxKafkaClientExamples.java │ └── package-info.java │ └── io │ └── vertx │ └── kafka │ ├── admin │ ├── ClusterDescription.java │ ├── Config.java │ ├── ConfigEntry.java │ ├── ConfigSynonym.java │ ├── ConsumerGroupDescription.java │ ├── ConsumerGroupListing.java │ ├── DescribeClusterOptions.java │ ├── DescribeConsumerGroupsOptions.java │ ├── DescribeTopicsOptions.java │ ├── KafkaAdminClient.java │ ├── ListConsumerGroupOffsetsOptions.java │ ├── ListOffsetsResultInfo.java │ ├── MemberAssignment.java │ ├── MemberDescription.java │ ├── NewPartitions.java │ ├── NewTopic.java │ ├── OffsetSpec.java │ ├── TopicDescription.java │ ├── impl │ │ └── KafkaAdminClientImpl.java │ └── package-info.java │ └── client │ ├── common │ ├── ConfigResource.java │ ├── KafkaClientOptions.java │ ├── Node.java │ ├── PartitionInfo.java │ ├── TopicPartition.java │ ├── TopicPartitionInfo.java │ ├── impl │ │ ├── CloseHandler.java │ │ └── Helper.java │ └── tracing │ │ ├── ConsumerTracer.java │ │ ├── ProducerTracer.java │ │ ├── TraceContext.java │ │ └── TraceTags.java │ ├── consumer │ ├── KafkaConsumer.java │ ├── KafkaConsumerRecord.java │ ├── KafkaConsumerRecords.java │ ├── KafkaReadStream.java │ ├── OffsetAndMetadata.java │ ├── OffsetAndTimestamp.java │ └── impl │ │ ├── KafkaConsumerImpl.java │ │ ├── KafkaConsumerRecordImpl.java │ │ ├── KafkaConsumerRecordsImpl.java │ │ └── KafkaReadStreamImpl.java │ ├── package-info.java │ ├── producer │ ├── KafkaHeader.java │ ├── KafkaProducer.java │ ├── KafkaProducerRecord.java │ ├── KafkaWriteStream.java │ ├── RecordMetadata.java │ └── impl │ │ ├── KafkaHeaderImpl.java │ │ ├── KafkaProducerImpl.java │ │ ├── KafkaProducerRecordImpl.java │ │ └── KafkaWriteStreamImpl.java │ └── serialization │ ├── BufferDeserializer.java │ ├── BufferSerializer.java │ ├── JsonArrayDeserializer.java │ ├── JsonArraySerializer.java │ ├── JsonObjectDeserializer.java │ ├── JsonObjectSerializer.java │ └── VertxSerdes.java └── test └── java └── io └── vertx └── kafka └── client ├── common └── tracing │ └── TracingTest.java └── tests ├── AdminClientAclTest.java ├── AdminClientConfigEntryTest.java ├── AdminClientTest.java ├── CleanupTest.java ├── CodecsTest.java ├── ConsumerFailedCloseTest.java ├── ConsumerMockTest.java ├── ConsumerMockTestBase.java ├── ConsumerTest.java ├── ConsumerTestBase.java ├── EarliestNativeTest.java ├── EarliestTest.java ├── KafkaClusterTestBase.java ├── KafkaHeaderTest.java ├── KafkaReadStreamMockTest.java ├── KafkaTestBase.java ├── NoClusterTest.java ├── ProducerConsumerContextTest.java ├── ProducerMockTest.java ├── ProducerTest.java ├── TopicPartitionTest.java └── TransactionalProducerTest.java /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.github/maven-cd-settings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | false 20 | 21 | 22 | 23 | vertx-snapshots-repository 24 | ${env.VERTX_NEXUS_USERNAME} 25 | ${env.VERTX_NEXUS_PASSWORD} 26 | 27 | 28 | 29 | 30 | 31 | google-mirror 32 | 33 | true 34 | 35 | 36 | 37 | google-maven-central 38 | GCS Maven Central mirror EU 39 | https://maven-central.storage-download.googleapis.com/maven2/ 40 | 41 | true 42 | 43 | 44 | false 45 | 46 | 47 | 48 | 49 | 50 | google-maven-central 51 | GCS Maven Central mirror 52 | https://maven-central.storage-download.googleapis.com/maven2/ 53 | 54 | true 55 | 56 | 57 | false 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /.github/maven-ci-settings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | false 20 | 21 | 22 | 23 | google-mirror 24 | 25 | true 26 | 27 | 28 | 29 | google-maven-central 30 | GCS Maven Central mirror EU 31 | https://maven-central.storage-download.googleapis.com/maven2/ 32 | 33 | true 34 | 35 | 36 | false 37 | 38 | 39 | 40 | 41 | 42 | google-maven-central 43 | GCS Maven Central mirror 44 | https://maven-central.storage-download.googleapis.com/maven2/ 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /.github/workflows/ci-4.x.yml: -------------------------------------------------------------------------------- 1 | name: vertx-kafka-client (4.x) 2 | on: 3 | schedule: 4 | - cron: '0 4 * * *' 5 | jobs: 6 | CI: 7 | strategy: 8 | matrix: 9 | include: 10 | - os: ubuntu-latest 11 | jdk: 8 12 | - os: ubuntu-latest 13 | jdk: 17 14 | uses: ./.github/workflows/ci.yml 15 | with: 16 | branch: 4.x 17 | jdk: ${{ matrix.jdk }} 18 | os: ${{ matrix.os }} 19 | secrets: inherit 20 | Deploy: 21 | if: ${{ github.repository_owner == 'vert-x3' && (github.event_name == 'push' || github.event_name == 'schedule') }} 22 | needs: CI 23 | uses: ./.github/workflows/deploy.yml 24 | with: 25 | branch: 4.x 26 | jdk: 8 27 | secrets: inherit 28 | -------------------------------------------------------------------------------- /.github/workflows/ci-5.x-stable.yml: -------------------------------------------------------------------------------- 1 | name: vertx-kafka-client (5.x-stable) 2 | on: 3 | push: 4 | branches: 5 | - '5.[0-9]+' 6 | pull_request: 7 | branches: 8 | - '5.[0-9]+' 9 | schedule: 10 | - cron: '0 6 * * *' 11 | jobs: 12 | CI-CD: 13 | uses: ./.github/workflows/ci-matrix-5.x.yml 14 | secrets: inherit 15 | with: 16 | branch: ${{ github.event_name == 'schedule' && vars.VERTX_5_STABLE_BRANCH || github.event.pull_request.head.sha || github.ref_name }} 17 | -------------------------------------------------------------------------------- /.github/workflows/ci-5.x.yml: -------------------------------------------------------------------------------- 1 | name: vertx-kafka-client (5.x) 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | schedule: 10 | - cron: '0 5 * * *' 11 | jobs: 12 | CI-CD: 13 | uses: ./.github/workflows/ci-matrix-5.x.yml 14 | secrets: inherit 15 | with: 16 | branch: ${{ github.event.pull_request.head.sha || github.ref_name }} 17 | -------------------------------------------------------------------------------- /.github/workflows/ci-matrix-5.x.yml: -------------------------------------------------------------------------------- 1 | name: CI matrix (5.x) 2 | on: 3 | workflow_call: 4 | inputs: 5 | branch: 6 | required: true 7 | type: string 8 | jobs: 9 | CI: 10 | strategy: 11 | matrix: 12 | include: 13 | - os: ubuntu-latest 14 | jdk: 11 15 | - os: ubuntu-latest 16 | jdk: 21 17 | uses: ./.github/workflows/ci.yml 18 | with: 19 | branch: ${{ inputs.branch }} 20 | jdk: ${{ matrix.jdk }} 21 | os: ${{ matrix.os }} 22 | secrets: inherit 23 | Deploy: 24 | if: ${{ github.repository_owner == 'vert-x3' && (github.event_name == 'push' || github.event_name == 'schedule') }} 25 | needs: CI 26 | uses: ./.github/workflows/deploy.yml 27 | with: 28 | branch: ${{ inputs.branch }} 29 | jdk: 11 30 | secrets: inherit 31 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_call: 4 | inputs: 5 | branch: 6 | required: true 7 | type: string 8 | jdk: 9 | default: 8 10 | type: string 11 | os: 12 | default: ubuntu-latest 13 | type: string 14 | jobs: 15 | Test: 16 | name: Run tests 17 | runs-on: ${{ inputs.os }} 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v2 21 | with: 22 | ref: ${{ inputs.branch }} 23 | - name: Install JDK 24 | uses: actions/setup-java@v4 25 | with: 26 | java-version: | 27 | ${{ inputs.jdk }} 28 | 17 29 | distribution: temurin 30 | - name: Run tests 31 | run: mvn -s .github/maven-ci-settings.xml -q clean verify -B 32 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | on: 3 | workflow_call: 4 | inputs: 5 | branch: 6 | required: true 7 | type: string 8 | jdk: 9 | default: 8 10 | type: string 11 | jobs: 12 | Deploy: 13 | name: Deploy to OSSRH 14 | runs-on: ubuntu-latest 15 | env: 16 | VERTX_NEXUS_USERNAME: ${{ secrets.VERTX_NEXUS_USERNAME }} 17 | VERTX_NEXUS_PASSWORD: ${{ secrets.VERTX_NEXUS_PASSWORD }} 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v2 21 | with: 22 | ref: ${{ inputs.branch }} 23 | - name: Install JDK 24 | uses: actions/setup-java@v4 25 | with: 26 | java-version: | 27 | ${{ inputs.jdk }} 28 | 17 29 | distribution: temurin 30 | - name: Get project version 31 | run: echo "PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '\[')" >> $GITHUB_ENV 32 | - name: Maven deploy 33 | if: ${{ endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }} 34 | run: mvn deploy -s .github/maven-cd-settings.xml -DskipTests -B 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .gradle 3 | .idea 4 | .classpath 5 | .project 6 | .settings 7 | .yardoc 8 | .yardopts 9 | build 10 | target 11 | out 12 | *.iml 13 | *.ipr 14 | *.iws 15 | .vertx 16 | test-output 17 | src/scratchpad 18 | test-results 19 | test-tmp 20 | *.class 21 | *.swp 22 | .vertx 23 | .vscode 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vert.x Kafka Client 2 | 3 | [![Build Status (5.x)](https://github.com/vert-x3/vertx-kafka-client/actions/workflows/ci-5.x.yml/badge.svg)](https://github.com/vert-x3/vertx-kafka-client/actions/workflows/ci-5.x.yml) 4 | [![Build Status (4.x)](https://github.com/vert-x3/vertx-kafka-client/actions/workflows/ci-4.x.yml/badge.svg)](https://github.com/vert-x3/vertx-kafka-client/actions/workflows/ci-4.x.yml) 5 | 6 | This component provides a Kafka client for reading and sending messages from/to an [Apache Kafka](https://kafka.apache.org/) cluster. 7 | From the consumer point of view, its API provides a bunch of methods for subscribing to a topic partition receiving 8 | messages asynchronously or reading them as a stream (even with the possibility to pause the stream itself). 9 | As producer, its API provides methods for sending message to a topic partition like writing on a stream. 10 | 11 | See the online docs for more details: 12 | - [Java](https://vertx.io/docs/vertx-kafka-client/java) 13 | - [JavaScript](https://vertx.io/docs/vertx-kafka-client/js) 14 | - [Ruby](https://vertx.io/docs/vertx-kafka-client/ruby) 15 | - [Groovy](https://vertx.io/docs/vertx-kafka-client/groovy) 16 | - [Kotlin](https://vertx.io/docs/vertx-kafka-client/kotlin) 17 | 18 | Important aspects of Topic Management, such as creating a topic, deleting a topic, changing configuration of a topic, are also supported. 19 | See the online docs for more details: 20 | - [Java](https://vertx.io/docs/vertx-kafka-client/java/#_vert_x_kafka_adminutils) 21 | - [JavaScript](https://vertx.io/docs/vertx-kafka-client/js/#_vert_x_kafka_adminutils) 22 | - [Ruby](https://vertx.io/docs/vertx-kafka-client/ruby/#_vert_x_kafka_adminutils) 23 | - [Groovy](https://vertx.io/docs/vertx-kafka-client/groovy/#_vert_x_kafka_adminutils) 24 | - [Kotlin](https://vertx.io/docs/vertx-kafka-client/kotlin/#_vert_x_kafka_adminutils) 25 | 26 | **Note: This module has Tech Preview status, this means the API can change between versions.** 27 | -------------------------------------------------------------------------------- /src/main/asciidoc/adminclient.adoc: -------------------------------------------------------------------------------- 1 | == Vert.x Kafka Admin Client 2 | :toc: left 3 | :lang: $lang 4 | :$lang: $lang 5 | 6 | This component provides a Vert.x wrapper around the Kafka Admin Client API. 7 | The Kafka Admin Client is used to create, modify, and delete topics. 8 | It also provides methods for handling ACLs (Access Control Lists), consumer groups and many more. 9 | 10 | === Creating the Kafka Admin Client 11 | 12 | Creating the admin client is quite similar on how it works using the native Kafka client library. 13 | 14 | It needs to be configured with a bunch of properties as described in the official 15 | Apache Kafka documentation, for the link:https://kafka.apache.org/documentation/#adminclientconfigs[admin]. 16 | 17 | To achieve that, a map can be configured with such properties passing it to one of the 18 | static creation methods exposed by {@link io.vertx.kafka.admin.KafkaAdminClient}. 19 | 20 | [source,$lang] 21 | ---- 22 | {@link examples.KafkaAdminClientExamples#exampleCreateAdminClient} 23 | ---- 24 | 25 | === Listing topics 26 | 27 | You can call the {@link io.vertx.kafka.admin.KafkaAdminClient#listTopics} for listing the topics in the cluster. 28 | The only parameter is the usual callback to handle the result, which provides the topics list. 29 | 30 | [source,$lang] 31 | ---- 32 | {@link examples.KafkaAdminClientExamples#exampleListTopics} 33 | ---- 34 | 35 | === Describe topics 36 | 37 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#describeTopics} to describe topics in the cluster. 38 | Describing a topic means getting all related metadata like number of partitions, replicas, leader, in-sync replicas and so on. 39 | The needed parameters are the list of topics names to describe, and the usual callback to handle the result providing 40 | a map with topic names and related {@link io.vertx.kafka.admin.TopicDescription}. 41 | 42 | [source,$lang] 43 | ---- 44 | {@link examples.KafkaAdminClientExamples#exampleDescribeTopics} 45 | ---- 46 | 47 | === Create topic 48 | 49 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#createTopics} to create topics in the cluster. 50 | The needed parameters are the list of the topics to create, and the usual callback to handle the result. 51 | The topics to create are defined via the {@link io.vertx.kafka.admin.NewTopic} class specifying the name, the number of 52 | partitions and the replication factor. 53 | It is also possible to describe the replicas assignment, mapping each replica to the broker id, instead of specifying the 54 | number of partitions and the replication factor (which in this case has to be set to -1). 55 | 56 | [source,$lang] 57 | ---- 58 | {@link examples.KafkaAdminClientExamples#exampleCreateTopics} 59 | ---- 60 | 61 | === Delete topic 62 | 63 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#deleteTopics} to delete topics in the cluster. 64 | The needed parameters are the list of the topics to delete, and the usual callback to handle the result. 65 | 66 | [source,$lang] 67 | ---- 68 | {@link examples.KafkaAdminClientExamples#exampleDeleteTopics} 69 | ---- 70 | 71 | === Describe configuration 72 | 73 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#describeConfigs} to describe resources configuration. 74 | Describing resources configuration means getting all configuration information for cluster resources like topics or brokers. 75 | The needed parameters are the list of the resources for which you want the configuration, and the usual callback to handle the result. 76 | The resources are described by a collection of {@link io.vertx.kafka.client.common.ConfigResource} while the result maps 77 | each resource with a corresponding {@link io.vertx.kafka.admin.Config} which as more {@link io.vertx.kafka.admin.ConfigEntry} for 78 | each configuration parameter. 79 | 80 | [source,$lang] 81 | ---- 82 | {@link examples.KafkaAdminClientExamples#exampleDescribeConfigs} 83 | ---- 84 | 85 | === Alter configuration 86 | 87 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#alterConfigs} to alter resources configuration. 88 | Altering resources configuration means updating configuration information for cluster resources like topics or brokers. 89 | The needed parameters are the list of the resources with the related configurations to updated, and the usual callback to handle the result. 90 | It is possible to alter configurations for different resources with just one call. The input parameter maps each 91 | {@link io.vertx.kafka.client.common.ConfigResource} with the corresponding {@link io.vertx.kafka.admin.Config} you want to apply. 92 | 93 | [source,$lang] 94 | ---- 95 | {@link examples.KafkaAdminClientExamples#exampleAlterConfigs} 96 | ---- 97 | 98 | === List consumer groups 99 | 100 | You can call the {@link io.vertx.kafka.admin.KafkaAdminClient#listConsumerGroups} for listing the consumer groups in the cluster. 101 | The only parameter is the usual callback to handle the result, which provides the consumer groups list. 102 | 103 | [source,$lang] 104 | ---- 105 | {@link examples.KafkaAdminClientExamples#exampleListConsumerGroups} 106 | ---- 107 | 108 | === Describe consumer groups 109 | 110 | You can call {@link io.vertx.kafka.admin.KafkaAdminClient#describeConsumerGroups} to describe consumer groups in the cluster. 111 | Describing a consumer group means getting all related information like members, related ids, topics subscribed, partitions assignment and so on. 112 | The needed parameters are the list of consumer groups names to describe, and the usual callback to handle the result providing 113 | a map with consumer group names and related {@link io.vertx.kafka.admin.MemberDescription}. 114 | 115 | [source,$lang] 116 | ---- 117 | {@link examples.KafkaAdminClientExamples#exampleDescribeTopics} 118 | ---- 119 | -------------------------------------------------------------------------------- /src/main/asciidoc/rxjava2.adoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vert-x3/vertx-kafka-client/c24056f2c52d1879f2b0c3f980ee020a1387769b/src/main/asciidoc/rxjava2.adoc -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ClusterDescriptionConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ClusterDescription}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ClusterDescription} original class using Vert.x codegen. 11 | */ 12 | public class ClusterDescriptionConverter { 13 | 14 | static void fromJson(Iterable> json, ClusterDescription obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "nodes": 18 | if (member.getValue() instanceof JsonArray) { 19 | java.util.ArrayList list = new java.util.ArrayList<>(); 20 | ((Iterable)member.getValue()).forEach( item -> { 21 | if (item instanceof JsonObject) 22 | list.add(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)item)); 23 | }); 24 | obj.setNodes(list); 25 | } 26 | break; 27 | case "controller": 28 | if (member.getValue() instanceof JsonObject) { 29 | obj.setController(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)member.getValue())); 30 | } 31 | break; 32 | case "clusterId": 33 | if (member.getValue() instanceof String) { 34 | obj.setClusterId((String)member.getValue()); 35 | } 36 | break; 37 | case "authorizedOperations": 38 | if (member.getValue() instanceof JsonArray) { 39 | java.util.LinkedHashSet list = new java.util.LinkedHashSet<>(); 40 | ((Iterable)member.getValue()).forEach( item -> { 41 | if (item instanceof String) 42 | list.add(org.apache.kafka.common.acl.AclOperation.valueOf((String)item)); 43 | }); 44 | obj.setAuthorizedOperations(list); 45 | } 46 | break; 47 | } 48 | } 49 | } 50 | 51 | static void toJson(ClusterDescription obj, JsonObject json) { 52 | toJson(obj, json.getMap()); 53 | } 54 | 55 | static void toJson(ClusterDescription obj, java.util.Map json) { 56 | if (obj.getNodes() != null) { 57 | JsonArray array = new JsonArray(); 58 | obj.getNodes().forEach(item -> array.add(item.toJson())); 59 | json.put("nodes", array); 60 | } 61 | if (obj.getController() != null) { 62 | json.put("controller", obj.getController().toJson()); 63 | } 64 | if (obj.getClusterId() != null) { 65 | json.put("clusterId", obj.getClusterId()); 66 | } 67 | if (obj.getAuthorizedOperations() != null) { 68 | JsonArray array = new JsonArray(); 69 | obj.getAuthorizedOperations().forEach(item -> array.add(item.name())); 70 | json.put("authorizedOperations", array); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ConfigConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.Config}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.Config} original class using Vert.x codegen. 11 | */ 12 | public class ConfigConverter { 13 | 14 | static void fromJson(Iterable> json, Config obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "entries": 18 | if (member.getValue() instanceof JsonArray) { 19 | java.util.ArrayList list = new java.util.ArrayList<>(); 20 | ((Iterable)member.getValue()).forEach( item -> { 21 | if (item instanceof JsonObject) 22 | list.add(new io.vertx.kafka.admin.ConfigEntry((io.vertx.core.json.JsonObject)item)); 23 | }); 24 | obj.setEntries(list); 25 | } 26 | break; 27 | } 28 | } 29 | } 30 | 31 | static void toJson(Config obj, JsonObject json) { 32 | toJson(obj, json.getMap()); 33 | } 34 | 35 | static void toJson(Config obj, java.util.Map json) { 36 | if (obj.getEntries() != null) { 37 | JsonArray array = new JsonArray(); 38 | obj.getEntries().forEach(item -> array.add(item.toJson())); 39 | json.put("entries", array); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ConfigEntryConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ConfigEntry}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ConfigEntry} original class using Vert.x codegen. 11 | */ 12 | public class ConfigEntryConverter { 13 | 14 | static void fromJson(Iterable> json, ConfigEntry obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "name": 18 | if (member.getValue() instanceof String) { 19 | obj.setName((String)member.getValue()); 20 | } 21 | break; 22 | case "default": 23 | if (member.getValue() instanceof Boolean) { 24 | obj.setDefault((Boolean)member.getValue()); 25 | } 26 | break; 27 | case "readOnly": 28 | if (member.getValue() instanceof Boolean) { 29 | obj.setReadOnly((Boolean)member.getValue()); 30 | } 31 | break; 32 | case "sensitive": 33 | if (member.getValue() instanceof Boolean) { 34 | obj.setSensitive((Boolean)member.getValue()); 35 | } 36 | break; 37 | case "source": 38 | if (member.getValue() instanceof String) { 39 | obj.setSource(org.apache.kafka.clients.admin.ConfigEntry.ConfigSource.valueOf((String)member.getValue())); 40 | } 41 | break; 42 | case "synonyms": 43 | if (member.getValue() instanceof JsonArray) { 44 | java.util.ArrayList list = new java.util.ArrayList<>(); 45 | ((Iterable)member.getValue()).forEach( item -> { 46 | if (item instanceof JsonObject) 47 | list.add(new io.vertx.kafka.admin.ConfigSynonym((io.vertx.core.json.JsonObject)item)); 48 | }); 49 | obj.setSynonyms(list); 50 | } 51 | break; 52 | case "value": 53 | if (member.getValue() instanceof String) { 54 | obj.setValue((String)member.getValue()); 55 | } 56 | break; 57 | } 58 | } 59 | } 60 | 61 | static void toJson(ConfigEntry obj, JsonObject json) { 62 | toJson(obj, json.getMap()); 63 | } 64 | 65 | static void toJson(ConfigEntry obj, java.util.Map json) { 66 | if (obj.getName() != null) { 67 | json.put("name", obj.getName()); 68 | } 69 | json.put("default", obj.isDefault()); 70 | json.put("readOnly", obj.isReadOnly()); 71 | json.put("sensitive", obj.isSensitive()); 72 | if (obj.getSource() != null) { 73 | json.put("source", obj.getSource().name()); 74 | } 75 | if (obj.getSynonyms() != null) { 76 | JsonArray array = new JsonArray(); 77 | obj.getSynonyms().forEach(item -> array.add(item.toJson())); 78 | json.put("synonyms", array); 79 | } 80 | if (obj.getValue() != null) { 81 | json.put("value", obj.getValue()); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ConfigSynonymConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ConfigSynonym}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ConfigSynonym} original class using Vert.x codegen. 11 | */ 12 | public class ConfigSynonymConverter { 13 | 14 | static void fromJson(Iterable> json, ConfigSynonym obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "name": 18 | if (member.getValue() instanceof String) { 19 | obj.setName((String)member.getValue()); 20 | } 21 | break; 22 | case "value": 23 | if (member.getValue() instanceof String) { 24 | obj.setValue((String)member.getValue()); 25 | } 26 | break; 27 | case "source": 28 | if (member.getValue() instanceof String) { 29 | obj.setSource(org.apache.kafka.clients.admin.ConfigEntry.ConfigSource.valueOf((String)member.getValue())); 30 | } 31 | break; 32 | } 33 | } 34 | } 35 | 36 | static void toJson(ConfigSynonym obj, JsonObject json) { 37 | toJson(obj, json.getMap()); 38 | } 39 | 40 | static void toJson(ConfigSynonym obj, java.util.Map json) { 41 | if (obj.getName() != null) { 42 | json.put("name", obj.getName()); 43 | } 44 | if (obj.getValue() != null) { 45 | json.put("value", obj.getValue()); 46 | } 47 | if (obj.getSource() != null) { 48 | json.put("source", obj.getSource().name()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ConsumerGroupDescriptionConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ConsumerGroupDescription}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ConsumerGroupDescription} original class using Vert.x codegen. 11 | */ 12 | public class ConsumerGroupDescriptionConverter { 13 | 14 | static void fromJson(Iterable> json, ConsumerGroupDescription obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "groupId": 18 | if (member.getValue() instanceof String) { 19 | obj.setGroupId((String)member.getValue()); 20 | } 21 | break; 22 | case "simpleConsumerGroup": 23 | if (member.getValue() instanceof Boolean) { 24 | obj.setSimpleConsumerGroup((Boolean)member.getValue()); 25 | } 26 | break; 27 | case "coordinator": 28 | if (member.getValue() instanceof JsonObject) { 29 | obj.setCoordinator(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)member.getValue())); 30 | } 31 | break; 32 | case "members": 33 | if (member.getValue() instanceof JsonArray) { 34 | java.util.ArrayList list = new java.util.ArrayList<>(); 35 | ((Iterable)member.getValue()).forEach( item -> { 36 | if (item instanceof JsonObject) 37 | list.add(new io.vertx.kafka.admin.MemberDescription((io.vertx.core.json.JsonObject)item)); 38 | }); 39 | obj.setMembers(list); 40 | } 41 | break; 42 | case "partitionAssignor": 43 | if (member.getValue() instanceof String) { 44 | obj.setPartitionAssignor((String)member.getValue()); 45 | } 46 | break; 47 | case "state": 48 | if (member.getValue() instanceof String) { 49 | obj.setState(org.apache.kafka.common.ConsumerGroupState.valueOf((String)member.getValue())); 50 | } 51 | break; 52 | case "authorizedOperations": 53 | if (member.getValue() instanceof JsonArray) { 54 | java.util.LinkedHashSet list = new java.util.LinkedHashSet<>(); 55 | ((Iterable)member.getValue()).forEach( item -> { 56 | if (item instanceof String) 57 | list.add(org.apache.kafka.common.acl.AclOperation.valueOf((String)item)); 58 | }); 59 | obj.setAuthorizedOperations(list); 60 | } 61 | break; 62 | } 63 | } 64 | } 65 | 66 | static void toJson(ConsumerGroupDescription obj, JsonObject json) { 67 | toJson(obj, json.getMap()); 68 | } 69 | 70 | static void toJson(ConsumerGroupDescription obj, java.util.Map json) { 71 | if (obj.getGroupId() != null) { 72 | json.put("groupId", obj.getGroupId()); 73 | } 74 | json.put("simpleConsumerGroup", obj.isSimpleConsumerGroup()); 75 | if (obj.getCoordinator() != null) { 76 | json.put("coordinator", obj.getCoordinator().toJson()); 77 | } 78 | if (obj.getMembers() != null) { 79 | JsonArray array = new JsonArray(); 80 | obj.getMembers().forEach(item -> array.add(item.toJson())); 81 | json.put("members", array); 82 | } 83 | if (obj.getPartitionAssignor() != null) { 84 | json.put("partitionAssignor", obj.getPartitionAssignor()); 85 | } 86 | if (obj.getState() != null) { 87 | json.put("state", obj.getState().name()); 88 | } 89 | if (obj.getAuthorizedOperations() != null) { 90 | JsonArray array = new JsonArray(); 91 | obj.getAuthorizedOperations().forEach(item -> array.add(item.name())); 92 | json.put("authorizedOperations", array); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ConsumerGroupListingConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ConsumerGroupListing}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ConsumerGroupListing} original class using Vert.x codegen. 11 | */ 12 | public class ConsumerGroupListingConverter { 13 | 14 | static void fromJson(Iterable> json, ConsumerGroupListing obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "groupId": 18 | if (member.getValue() instanceof String) { 19 | obj.setGroupId((String)member.getValue()); 20 | } 21 | break; 22 | case "simpleConsumerGroup": 23 | if (member.getValue() instanceof Boolean) { 24 | obj.setSimpleConsumerGroup((Boolean)member.getValue()); 25 | } 26 | break; 27 | } 28 | } 29 | } 30 | 31 | static void toJson(ConsumerGroupListing obj, JsonObject json) { 32 | toJson(obj, json.getMap()); 33 | } 34 | 35 | static void toJson(ConsumerGroupListing obj, java.util.Map json) { 36 | if (obj.getGroupId() != null) { 37 | json.put("groupId", obj.getGroupId()); 38 | } 39 | json.put("simpleConsumerGroup", obj.isSimpleConsumerGroup()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/DescribeClusterOptionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.DescribeClusterOptions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.DescribeClusterOptions} original class using Vert.x codegen. 11 | */ 12 | public class DescribeClusterOptionsConverter { 13 | 14 | static void fromJson(Iterable> json, DescribeClusterOptions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | } 18 | } 19 | } 20 | 21 | static void toJson(DescribeClusterOptions obj, JsonObject json) { 22 | toJson(obj, json.getMap()); 23 | } 24 | 25 | static void toJson(DescribeClusterOptions obj, java.util.Map json) { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/DescribeConsumerGroupsOptionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.DescribeConsumerGroupsOptions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.DescribeConsumerGroupsOptions} original class using Vert.x codegen. 11 | */ 12 | public class DescribeConsumerGroupsOptionsConverter { 13 | 14 | static void fromJson(Iterable> json, DescribeConsumerGroupsOptions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | } 18 | } 19 | } 20 | 21 | static void toJson(DescribeConsumerGroupsOptions obj, JsonObject json) { 22 | toJson(obj, json.getMap()); 23 | } 24 | 25 | static void toJson(DescribeConsumerGroupsOptions obj, java.util.Map json) { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/DescribeTopicsOptionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.DescribeTopicsOptions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.DescribeTopicsOptions} original class using Vert.x codegen. 11 | */ 12 | public class DescribeTopicsOptionsConverter { 13 | 14 | static void fromJson(Iterable> json, DescribeTopicsOptions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | } 18 | } 19 | } 20 | 21 | static void toJson(DescribeTopicsOptions obj, JsonObject json) { 22 | toJson(obj, json.getMap()); 23 | } 24 | 25 | static void toJson(DescribeTopicsOptions obj, java.util.Map json) { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ListConsumerGroupOffsetsOptionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ListConsumerGroupOffsetsOptions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ListConsumerGroupOffsetsOptions} original class using Vert.x codegen. 11 | */ 12 | public class ListConsumerGroupOffsetsOptionsConverter { 13 | 14 | static void fromJson(Iterable> json, ListConsumerGroupOffsetsOptions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | } 18 | } 19 | } 20 | 21 | static void toJson(ListConsumerGroupOffsetsOptions obj, JsonObject json) { 22 | toJson(obj, json.getMap()); 23 | } 24 | 25 | static void toJson(ListConsumerGroupOffsetsOptions obj, java.util.Map json) { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/ListOffsetsResultInfoConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.ListOffsetsResultInfo}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.ListOffsetsResultInfo} original class using Vert.x codegen. 11 | */ 12 | public class ListOffsetsResultInfoConverter { 13 | 14 | static void fromJson(Iterable> json, ListOffsetsResultInfo obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "offset": 18 | if (member.getValue() instanceof Number) { 19 | obj.setOffset(((Number)member.getValue()).longValue()); 20 | } 21 | break; 22 | case "timestamp": 23 | if (member.getValue() instanceof Number) { 24 | obj.setTimestamp(((Number)member.getValue()).longValue()); 25 | } 26 | break; 27 | case "leaderEpoch": 28 | if (member.getValue() instanceof Number) { 29 | obj.setLeaderEpoch(((Number)member.getValue()).intValue()); 30 | } 31 | break; 32 | } 33 | } 34 | } 35 | 36 | static void toJson(ListOffsetsResultInfo obj, JsonObject json) { 37 | toJson(obj, json.getMap()); 38 | } 39 | 40 | static void toJson(ListOffsetsResultInfo obj, java.util.Map json) { 41 | json.put("offset", obj.getOffset()); 42 | json.put("timestamp", obj.getTimestamp()); 43 | if (obj.getLeaderEpoch() != null) { 44 | json.put("leaderEpoch", obj.getLeaderEpoch()); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/MemberAssignmentConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.MemberAssignment}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.MemberAssignment} original class using Vert.x codegen. 11 | */ 12 | public class MemberAssignmentConverter { 13 | 14 | static void fromJson(Iterable> json, MemberAssignment obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "topicPartitions": 18 | if (member.getValue() instanceof JsonArray) { 19 | java.util.LinkedHashSet list = new java.util.LinkedHashSet<>(); 20 | ((Iterable)member.getValue()).forEach( item -> { 21 | if (item instanceof JsonObject) 22 | list.add(new io.vertx.kafka.client.common.TopicPartition((io.vertx.core.json.JsonObject)item)); 23 | }); 24 | obj.setTopicPartitions(list); 25 | } 26 | break; 27 | } 28 | } 29 | } 30 | 31 | static void toJson(MemberAssignment obj, JsonObject json) { 32 | toJson(obj, json.getMap()); 33 | } 34 | 35 | static void toJson(MemberAssignment obj, java.util.Map json) { 36 | if (obj.getTopicPartitions() != null) { 37 | JsonArray array = new JsonArray(); 38 | obj.getTopicPartitions().forEach(item -> array.add(item.toJson())); 39 | json.put("topicPartitions", array); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/MemberDescriptionConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.MemberDescription}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.MemberDescription} original class using Vert.x codegen. 11 | */ 12 | public class MemberDescriptionConverter { 13 | 14 | static void fromJson(Iterable> json, MemberDescription obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "consumerId": 18 | if (member.getValue() instanceof String) { 19 | obj.setConsumerId((String)member.getValue()); 20 | } 21 | break; 22 | case "clientId": 23 | if (member.getValue() instanceof String) { 24 | obj.setClientId((String)member.getValue()); 25 | } 26 | break; 27 | case "assignment": 28 | if (member.getValue() instanceof JsonObject) { 29 | obj.setAssignment(new io.vertx.kafka.admin.MemberAssignment((io.vertx.core.json.JsonObject)member.getValue())); 30 | } 31 | break; 32 | case "host": 33 | if (member.getValue() instanceof String) { 34 | obj.setHost((String)member.getValue()); 35 | } 36 | break; 37 | } 38 | } 39 | } 40 | 41 | static void toJson(MemberDescription obj, JsonObject json) { 42 | toJson(obj, json.getMap()); 43 | } 44 | 45 | static void toJson(MemberDescription obj, java.util.Map json) { 46 | if (obj.getConsumerId() != null) { 47 | json.put("consumerId", obj.getConsumerId()); 48 | } 49 | if (obj.getClientId() != null) { 50 | json.put("clientId", obj.getClientId()); 51 | } 52 | if (obj.getAssignment() != null) { 53 | json.put("assignment", obj.getAssignment().toJson()); 54 | } 55 | if (obj.getHost() != null) { 56 | json.put("host", obj.getHost()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/NewPartitionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.NewPartitions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.NewPartitions} original class using Vert.x codegen. 11 | */ 12 | public class NewPartitionsConverter { 13 | 14 | static void fromJson(Iterable> json, NewPartitions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "totalCount": 18 | if (member.getValue() instanceof Number) { 19 | obj.setTotalCount(((Number)member.getValue()).intValue()); 20 | } 21 | break; 22 | } 23 | } 24 | } 25 | 26 | static void toJson(NewPartitions obj, JsonObject json) { 27 | toJson(obj, json.getMap()); 28 | } 29 | 30 | static void toJson(NewPartitions obj, java.util.Map json) { 31 | json.put("totalCount", obj.getTotalCount()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/NewTopicConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.NewTopic}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.NewTopic} original class using Vert.x codegen. 11 | */ 12 | public class NewTopicConverter { 13 | 14 | static void fromJson(Iterable> json, NewTopic obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "name": 18 | if (member.getValue() instanceof String) { 19 | obj.setName((String)member.getValue()); 20 | } 21 | break; 22 | case "numPartitions": 23 | if (member.getValue() instanceof Number) { 24 | obj.setNumPartitions(((Number)member.getValue()).intValue()); 25 | } 26 | break; 27 | case "replicationFactor": 28 | if (member.getValue() instanceof Number) { 29 | obj.setReplicationFactor(((Number)member.getValue()).shortValue()); 30 | } 31 | break; 32 | case "config": 33 | if (member.getValue() instanceof JsonObject) { 34 | java.util.Map map = new java.util.LinkedHashMap<>(); 35 | ((Iterable>)member.getValue()).forEach(entry -> { 36 | if (entry.getValue() instanceof String) 37 | map.put(entry.getKey(), (String)entry.getValue()); 38 | }); 39 | obj.setConfig(map); 40 | } 41 | break; 42 | } 43 | } 44 | } 45 | 46 | static void toJson(NewTopic obj, JsonObject json) { 47 | toJson(obj, json.getMap()); 48 | } 49 | 50 | static void toJson(NewTopic obj, java.util.Map json) { 51 | if (obj.getName() != null) { 52 | json.put("name", obj.getName()); 53 | } 54 | json.put("numPartitions", obj.getNumPartitions()); 55 | json.put("replicationFactor", obj.getReplicationFactor()); 56 | if (obj.getConfig() != null) { 57 | JsonObject map = new JsonObject(); 58 | obj.getConfig().forEach((key, value) -> map.put(key, value)); 59 | json.put("config", map); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/OffsetSpecConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.OffsetSpec}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.OffsetSpec} original class using Vert.x codegen. 11 | */ 12 | public class OffsetSpecConverter { 13 | 14 | static void fromJson(Iterable> json, OffsetSpec obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "spec": 18 | if (member.getValue() instanceof Number) { 19 | obj.setSpec(((Number)member.getValue()).longValue()); 20 | } 21 | break; 22 | } 23 | } 24 | } 25 | 26 | static void toJson(OffsetSpec obj, JsonObject json) { 27 | toJson(obj, json.getMap()); 28 | } 29 | 30 | static void toJson(OffsetSpec obj, java.util.Map json) { 31 | json.put("spec", obj.getSpec()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/admin/TopicDescriptionConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.admin; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.admin.TopicDescription}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.admin.TopicDescription} original class using Vert.x codegen. 11 | */ 12 | public class TopicDescriptionConverter { 13 | 14 | static void fromJson(Iterable> json, TopicDescription obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "internal": 18 | if (member.getValue() instanceof Boolean) { 19 | obj.setInternal((Boolean)member.getValue()); 20 | } 21 | break; 22 | case "name": 23 | if (member.getValue() instanceof String) { 24 | obj.setName((String)member.getValue()); 25 | } 26 | break; 27 | case "authorizedOperations": 28 | if (member.getValue() instanceof JsonArray) { 29 | java.util.LinkedHashSet list = new java.util.LinkedHashSet<>(); 30 | ((Iterable)member.getValue()).forEach( item -> { 31 | if (item instanceof String) 32 | list.add(org.apache.kafka.common.acl.AclOperation.valueOf((String)item)); 33 | }); 34 | obj.setAuthorizedOperations(list); 35 | } 36 | break; 37 | case "partitions": 38 | if (member.getValue() instanceof JsonArray) { 39 | java.util.ArrayList list = new java.util.ArrayList<>(); 40 | ((Iterable)member.getValue()).forEach( item -> { 41 | if (item instanceof JsonObject) 42 | list.add(new io.vertx.kafka.client.common.TopicPartitionInfo((io.vertx.core.json.JsonObject)item)); 43 | }); 44 | obj.setPartitions(list); 45 | } 46 | break; 47 | } 48 | } 49 | } 50 | 51 | static void toJson(TopicDescription obj, JsonObject json) { 52 | toJson(obj, json.getMap()); 53 | } 54 | 55 | static void toJson(TopicDescription obj, java.util.Map json) { 56 | json.put("internal", obj.isInternal()); 57 | if (obj.getName() != null) { 58 | json.put("name", obj.getName()); 59 | } 60 | if (obj.getAuthorizedOperations() != null) { 61 | JsonArray array = new JsonArray(); 62 | obj.getAuthorizedOperations().forEach(item -> array.add(item.name())); 63 | json.put("authorizedOperations", array); 64 | } 65 | if (obj.getPartitions() != null) { 66 | JsonArray array = new JsonArray(); 67 | obj.getPartitions().forEach(item -> array.add(item.toJson())); 68 | json.put("partitions", array); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/client/common/ConfigResourceConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.common; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.client.common.ConfigResource}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.common.ConfigResource} original class using Vert.x codegen. 11 | */ 12 | public class ConfigResourceConverter { 13 | 14 | static void fromJson(Iterable> json, ConfigResource obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "name": 18 | if (member.getValue() instanceof String) { 19 | obj.setName((String)member.getValue()); 20 | } 21 | break; 22 | case "default": 23 | if (member.getValue() instanceof Boolean) { 24 | obj.setDefault((Boolean)member.getValue()); 25 | } 26 | break; 27 | case "type": 28 | if (member.getValue() instanceof String) { 29 | obj.setType(org.apache.kafka.common.config.ConfigResource.Type.valueOf((String)member.getValue())); 30 | } 31 | break; 32 | } 33 | } 34 | } 35 | 36 | static void toJson(ConfigResource obj, JsonObject json) { 37 | toJson(obj, json.getMap()); 38 | } 39 | 40 | static void toJson(ConfigResource obj, java.util.Map json) { 41 | if (obj.getName() != null) { 42 | json.put("name", obj.getName()); 43 | } 44 | json.put("default", obj.isDefault()); 45 | if (obj.getType() != null) { 46 | json.put("type", obj.getType().name()); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/client/common/KafkaClientOptionsConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.common; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.client.common.KafkaClientOptions}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.common.KafkaClientOptions} original class using Vert.x codegen. 11 | */ 12 | public class KafkaClientOptionsConverter { 13 | 14 | static void fromJson(Iterable> json, KafkaClientOptions obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "config": 18 | if (member.getValue() instanceof JsonObject) { 19 | java.util.Map map = new java.util.LinkedHashMap<>(); 20 | ((Iterable>)member.getValue()).forEach(entry -> { 21 | if (entry.getValue() instanceof Object) 22 | map.put(entry.getKey(), entry.getValue()); 23 | }); 24 | obj.setConfig(map); 25 | } 26 | break; 27 | case "tracingPolicy": 28 | if (member.getValue() instanceof String) { 29 | obj.setTracingPolicy(io.vertx.core.tracing.TracingPolicy.valueOf((String)member.getValue())); 30 | } 31 | break; 32 | case "tracePeerAddress": 33 | if (member.getValue() instanceof String) { 34 | obj.setTracePeerAddress((String)member.getValue()); 35 | } 36 | break; 37 | } 38 | } 39 | } 40 | 41 | static void toJson(KafkaClientOptions obj, JsonObject json) { 42 | toJson(obj, json.getMap()); 43 | } 44 | 45 | static void toJson(KafkaClientOptions obj, java.util.Map json) { 46 | if (obj.getConfig() != null) { 47 | JsonObject map = new JsonObject(); 48 | obj.getConfig().forEach((key, value) -> map.put(key, value)); 49 | json.put("config", map); 50 | } 51 | if (obj.getTracingPolicy() != null) { 52 | json.put("tracingPolicy", obj.getTracingPolicy().name()); 53 | } 54 | if (obj.getTracePeerAddress() != null) { 55 | json.put("tracePeerAddress", obj.getTracePeerAddress()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/client/common/PartitionInfoConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.common; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.client.common.PartitionInfo}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.common.PartitionInfo} original class using Vert.x codegen. 11 | */ 12 | public class PartitionInfoConverter { 13 | 14 | static void fromJson(Iterable> json, PartitionInfo obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "inSyncReplicas": 18 | if (member.getValue() instanceof JsonArray) { 19 | java.util.ArrayList list = new java.util.ArrayList<>(); 20 | ((Iterable)member.getValue()).forEach( item -> { 21 | if (item instanceof JsonObject) 22 | list.add(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)item)); 23 | }); 24 | obj.setInSyncReplicas(list); 25 | } 26 | break; 27 | case "leader": 28 | if (member.getValue() instanceof JsonObject) { 29 | obj.setLeader(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)member.getValue())); 30 | } 31 | break; 32 | case "partition": 33 | if (member.getValue() instanceof Number) { 34 | obj.setPartition(((Number)member.getValue()).intValue()); 35 | } 36 | break; 37 | case "replicas": 38 | if (member.getValue() instanceof JsonArray) { 39 | java.util.ArrayList list = new java.util.ArrayList<>(); 40 | ((Iterable)member.getValue()).forEach( item -> { 41 | if (item instanceof JsonObject) 42 | list.add(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)item)); 43 | }); 44 | obj.setReplicas(list); 45 | } 46 | break; 47 | case "topic": 48 | if (member.getValue() instanceof String) { 49 | obj.setTopic((String)member.getValue()); 50 | } 51 | break; 52 | } 53 | } 54 | } 55 | 56 | static void toJson(PartitionInfo obj, JsonObject json) { 57 | toJson(obj, json.getMap()); 58 | } 59 | 60 | static void toJson(PartitionInfo obj, java.util.Map json) { 61 | if (obj.getInSyncReplicas() != null) { 62 | JsonArray array = new JsonArray(); 63 | obj.getInSyncReplicas().forEach(item -> array.add(item.toJson())); 64 | json.put("inSyncReplicas", array); 65 | } 66 | if (obj.getLeader() != null) { 67 | json.put("leader", obj.getLeader().toJson()); 68 | } 69 | json.put("partition", obj.getPartition()); 70 | if (obj.getReplicas() != null) { 71 | JsonArray array = new JsonArray(); 72 | obj.getReplicas().forEach(item -> array.add(item.toJson())); 73 | json.put("replicas", array); 74 | } 75 | if (obj.getTopic() != null) { 76 | json.put("topic", obj.getTopic()); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/generated/io/vertx/kafka/client/common/TopicPartitionInfoConverter.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.common; 2 | 3 | import io.vertx.core.json.JsonObject; 4 | import io.vertx.core.json.JsonArray; 5 | import java.time.Instant; 6 | import java.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * Converter and mapper for {@link io.vertx.kafka.client.common.TopicPartitionInfo}. 10 | * NOTE: This class has been automatically generated from the {@link io.vertx.kafka.client.common.TopicPartitionInfo} original class using Vert.x codegen. 11 | */ 12 | public class TopicPartitionInfoConverter { 13 | 14 | static void fromJson(Iterable> json, TopicPartitionInfo obj) { 15 | for (java.util.Map.Entry member : json) { 16 | switch (member.getKey()) { 17 | case "isr": 18 | if (member.getValue() instanceof JsonArray) { 19 | java.util.ArrayList list = new java.util.ArrayList<>(); 20 | ((Iterable)member.getValue()).forEach( item -> { 21 | if (item instanceof JsonObject) 22 | list.add(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)item)); 23 | }); 24 | obj.setIsr(list); 25 | } 26 | break; 27 | case "leader": 28 | if (member.getValue() instanceof JsonObject) { 29 | obj.setLeader(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)member.getValue())); 30 | } 31 | break; 32 | case "partition": 33 | if (member.getValue() instanceof Number) { 34 | obj.setPartition(((Number)member.getValue()).intValue()); 35 | } 36 | break; 37 | case "replicas": 38 | if (member.getValue() instanceof JsonArray) { 39 | java.util.ArrayList list = new java.util.ArrayList<>(); 40 | ((Iterable)member.getValue()).forEach( item -> { 41 | if (item instanceof JsonObject) 42 | list.add(new io.vertx.kafka.client.common.Node((io.vertx.core.json.JsonObject)item)); 43 | }); 44 | obj.setReplicas(list); 45 | } 46 | break; 47 | } 48 | } 49 | } 50 | 51 | static void toJson(TopicPartitionInfo obj, JsonObject json) { 52 | toJson(obj, json.getMap()); 53 | } 54 | 55 | static void toJson(TopicPartitionInfo obj, java.util.Map json) { 56 | if (obj.getIsr() != null) { 57 | JsonArray array = new JsonArray(); 58 | obj.getIsr().forEach(item -> array.add(item.toJson())); 59 | json.put("isr", array); 60 | } 61 | if (obj.getLeader() != null) { 62 | json.put("leader", obj.getLeader().toJson()); 63 | } 64 | json.put("partition", obj.getPartition()); 65 | if (obj.getReplicas() != null) { 66 | JsonArray array = new JsonArray(); 67 | obj.getReplicas().forEach(item -> array.add(item.toJson())); 68 | json.put("replicas", array); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @Source 18 | package examples; 19 | 20 | import io.vertx.docgen.Source; 21 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/ClusterDescription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import io.vertx.kafka.client.common.Node; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Objects; 27 | import java.util.Set; 28 | 29 | import org.apache.kafka.common.acl.AclOperation; 30 | 31 | /** 32 | * A detailed description of the cluster 33 | */ 34 | @DataObject 35 | @JsonGen(publicConverter = false) 36 | public class ClusterDescription { 37 | private String clusterId; 38 | private Node controller; 39 | private List nodes; 40 | private Set authorizedOperations; 41 | 42 | /** 43 | * Constructor 44 | */ 45 | public ClusterDescription() { 46 | 47 | } 48 | 49 | /** 50 | * Constructor 51 | * 52 | * @param clusterId The cluster ID. 53 | * @param controller The controller node. 54 | * @param nodes A collection of nodes belonging to this cluster. 55 | * @param authorizedOperations A collection of authorized operations on this cluster. 56 | */ 57 | public ClusterDescription(String clusterId, Node controller, List nodes, Set authorizedOperations) { 58 | this.clusterId = clusterId; 59 | this.controller = controller; 60 | this.nodes = nodes; 61 | this.authorizedOperations = authorizedOperations; 62 | } 63 | 64 | /** 65 | * Constructor (from JSON representation) 66 | * 67 | * @param json JSON representation 68 | */ 69 | public ClusterDescription(JsonObject json) { 70 | 71 | ClusterDescriptionConverter.fromJson(json, this); 72 | } 73 | 74 | /** 75 | * 76 | * @return the nodes belonging to this cluster. 77 | */ 78 | public List getNodes() { 79 | return nodes; 80 | } 81 | 82 | /** 83 | * Set the nodes belonging to this cluster 84 | * 85 | * @param nodes the nodes 86 | * @return current instance of the class to be fluent 87 | */ 88 | public ClusterDescription setNodes(List nodes) { 89 | this.nodes = nodes; 90 | return this; 91 | } 92 | 93 | /** 94 | * Add a node belonging to this cluster to the current node list. 95 | * 96 | * @param node the node to add 97 | * @return current instance of the class to be fluent 98 | */ 99 | public ClusterDescription addNode(Node node) { 100 | Objects.requireNonNull(node, "Cannot accept null node"); 101 | if (nodes == null) { 102 | nodes = new ArrayList<>(); 103 | } 104 | nodes.add(node); 105 | return this; 106 | } 107 | 108 | /** 109 | * 110 | * @return the controller node. 111 | */ 112 | public Node getController() { 113 | return controller; 114 | } 115 | 116 | /** 117 | * Set the controller node. 118 | * 119 | * @param controller the controller node 120 | * @return current instance of the class to be fluent 121 | */ 122 | public ClusterDescription setController(Node controller) { 123 | this.controller = controller; 124 | return this; 125 | } 126 | 127 | /** 128 | * 129 | * @return the cluster ID 130 | */ 131 | public String getClusterId() { 132 | return clusterId; 133 | } 134 | 135 | /** 136 | * Set the cluster ID 137 | * 138 | * @param clusterId 139 | * @return current instance of the class to be fluent 140 | */ 141 | public ClusterDescription setClusterId(String clusterId) { 142 | this.clusterId = clusterId; 143 | return this; 144 | } 145 | 146 | /** 147 | * 148 | * @return the authorizedOperations 149 | */ 150 | public Set getAuthorizedOperations() { 151 | return authorizedOperations; 152 | } 153 | 154 | /** 155 | * Set the authorizedOperations 156 | * 157 | * @param authorizedOperations 158 | * @return current instance of the class to be fluent 159 | */ 160 | public ClusterDescription setAuthorizedOperations(Set authorizedOperations) { 161 | this.authorizedOperations = authorizedOperations; 162 | return this; 163 | } 164 | 165 | 166 | /** 167 | * Convert object to JSON representation 168 | * 169 | * @return JSON representation 170 | */ 171 | public JsonObject toJson() { 172 | 173 | JsonObject json = new JsonObject(); 174 | ClusterDescriptionConverter.toJson(this, json); 175 | return json; 176 | } 177 | 178 | @Override 179 | public String toString() { 180 | 181 | return "ClusterDescription{" + 182 | "clusterId=" + this.clusterId + 183 | ",controller=" + this.controller + 184 | ",nodes=" + this.nodes + 185 | ",authorizedOperatioins=" + this.authorizedOperations + 186 | "}"; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/Config.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * A configuration object containing the configuration entries for a resource 27 | */ 28 | @DataObject 29 | @JsonGen(publicConverter = false) 30 | public class Config { 31 | 32 | private List entries; 33 | 34 | /** 35 | * Constructor 36 | */ 37 | public Config() { 38 | 39 | } 40 | 41 | /** 42 | * Constructor 43 | * 44 | * @param entries configuration entries for a resource 45 | */ 46 | public Config(List entries) { 47 | this.entries = entries; 48 | } 49 | 50 | /** 51 | * Constructor (from JSON representation) 52 | * 53 | * @param json JSON representation 54 | */ 55 | public Config(JsonObject json) { 56 | 57 | ConfigConverter.fromJson(json, this); 58 | } 59 | 60 | /** 61 | * @return configuration entries for a resource 62 | */ 63 | public List getEntries() { 64 | return entries; 65 | } 66 | 67 | /** 68 | * Set the configuration entries for a resource 69 | * 70 | * @param entries configuration entries for a resource 71 | * @return current instance of the class to be fluent 72 | */ 73 | public Config setEntries(List entries) { 74 | this.entries = entries; 75 | return this; 76 | } 77 | 78 | /** 79 | * Convert object to JSON representation 80 | * 81 | * @return JSON representation 82 | */ 83 | public JsonObject toJson() { 84 | 85 | JsonObject json = new JsonObject(); 86 | ConfigConverter.toJson(this, json); 87 | return json; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | 93 | return "Config{" + 94 | "entries=" + this.entries + 95 | "}"; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/ConfigSynonym.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import org.apache.kafka.clients.admin.ConfigEntry.ConfigSource; 23 | 24 | /** 25 | * Class representing a configuration synonym of a {@link ConfigEntry} 26 | */ 27 | @DataObject 28 | @JsonGen(publicConverter = false) 29 | public class ConfigSynonym { 30 | 31 | private String name; 32 | private String value; 33 | private ConfigSource source; 34 | 35 | /** 36 | * Constructor 37 | */ 38 | public ConfigSynonym() { 39 | 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param name the name of this configuration 46 | * @param value the value of this configuration, which may be null if the configuration is sensitive 47 | * @param source the source of this configuration 48 | */ 49 | public ConfigSynonym(String name, String value, ConfigSource source) { 50 | this.name = name; 51 | this.value = value; 52 | this.source = source; 53 | } 54 | 55 | /** 56 | * Constructor (from JSON representation) 57 | * 58 | * @param json JSON representation 59 | */ 60 | public ConfigSynonym(JsonObject json) { 61 | 62 | ConfigSynonymConverter.fromJson(json, this); 63 | } 64 | 65 | /** 66 | * @return the name of this configuration 67 | */ 68 | public String getName() { 69 | return name; 70 | } 71 | 72 | /** 73 | * Set the name of this configuration 74 | * 75 | * @param name the name of this configuration 76 | * @return current instance of the class to be fluent 77 | */ 78 | public ConfigSynonym setName(String name) { 79 | this.name = name; 80 | return this; 81 | } 82 | 83 | /** 84 | * @return the value of this configuration, which may be null if the configuration is sensitive 85 | */ 86 | public String getValue() { 87 | return value; 88 | } 89 | 90 | /** 91 | * Set the value of this configuration, which may be null if the configuration is sensitive 92 | * 93 | * @param value the value of this configuration, which may be null if the configuration is sensitive 94 | * @return current instance of the class to be fluent 95 | */ 96 | public ConfigSynonym setValue(String value) { 97 | this.value = value; 98 | return this; 99 | } 100 | 101 | /** 102 | * @return the source of this configuration 103 | */ 104 | public ConfigSource getSource() { 105 | return source; 106 | } 107 | 108 | /** 109 | * Set the source of this configuration 110 | * 111 | * @param source the source of this configuration 112 | * @return current instance of the class to be fluent 113 | */ 114 | public ConfigSynonym setSource(ConfigSource source) { 115 | this.source = source; 116 | return this; 117 | } 118 | 119 | /** 120 | * Convert object to JSON representation 121 | * 122 | * @return JSON representation 123 | */ 124 | public JsonObject toJson() { 125 | 126 | JsonObject json = new JsonObject(); 127 | ConfigSynonymConverter.toJson(this, json); 128 | return json; 129 | } 130 | 131 | @Override 132 | public String toString() { 133 | 134 | return "ConfigSynonym{" + 135 | "name=" + this.name + 136 | ",value=" + this.value + 137 | ",source=" + this.source + 138 | "}"; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/ConsumerGroupListing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | /** 24 | * A listing of a consumer group in the cluster. 25 | */ 26 | @DataObject 27 | @JsonGen(publicConverter = false) 28 | public class ConsumerGroupListing { 29 | 30 | private String groupId; 31 | private boolean isSimpleConsumerGroup; 32 | 33 | /** 34 | * Constructor 35 | */ 36 | public ConsumerGroupListing() { 37 | 38 | } 39 | 40 | /** 41 | * Constructor 42 | * 43 | * @param groupId consumer group id 44 | * @param isSimpleConsumerGroup if consumer group is simple or not 45 | */ 46 | public ConsumerGroupListing(String groupId, boolean isSimpleConsumerGroup) { 47 | this.groupId = groupId; 48 | this.isSimpleConsumerGroup = isSimpleConsumerGroup; 49 | } 50 | 51 | /** 52 | * Constructor (from JSON representation) 53 | * 54 | * @param json JSON representation 55 | */ 56 | public ConsumerGroupListing(JsonObject json) { 57 | 58 | ConsumerGroupListingConverter.fromJson(json, this); 59 | } 60 | 61 | /** 62 | * @return consumer group id 63 | */ 64 | public String getGroupId() { 65 | return groupId; 66 | } 67 | 68 | /** 69 | * Set the consumer group id 70 | * 71 | * @param groupId consumer group id 72 | * @return current instance of the class to be fluent 73 | */ 74 | public ConsumerGroupListing setGroupId(String groupId) { 75 | this.groupId = groupId; 76 | return this; 77 | } 78 | 79 | /** 80 | * @return if consumer group is simple or not 81 | */ 82 | public boolean isSimpleConsumerGroup() { 83 | return isSimpleConsumerGroup; 84 | } 85 | 86 | /** 87 | * Set if consumer group is simple or not 88 | * 89 | * @param isSimpleConsumerGroup if consumer group is simple or not 90 | * @return current instance of the class to be fluent 91 | */ 92 | public ConsumerGroupListing setSimpleConsumerGroup(boolean isSimpleConsumerGroup) { 93 | this.isSimpleConsumerGroup = isSimpleConsumerGroup; 94 | return this; 95 | } 96 | 97 | /** 98 | * Convert object to JSON representation 99 | * 100 | * @return JSON representation 101 | */ 102 | public JsonObject toJson() { 103 | 104 | JsonObject json = new JsonObject(); 105 | ConsumerGroupListingConverter.toJson(this, json); 106 | return json; 107 | } 108 | 109 | @Override 110 | public String toString() { 111 | 112 | return "ConsumerGroupListing{" + 113 | "groupId=" + this.groupId + 114 | ",isSimpleConsumerGroup=" + this.isSimpleConsumerGroup + 115 | "}"; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/DescribeClusterOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | @DataObject 24 | @JsonGen(publicConverter = false) 25 | public class DescribeClusterOptions { 26 | 27 | private boolean includeAuthorizedOperations; 28 | 29 | /** 30 | * Constructor 31 | */ 32 | public DescribeClusterOptions() {} 33 | 34 | 35 | /** 36 | * Constructor (from JSON representation) 37 | * 38 | * @param json JSON representation 39 | */ 40 | public DescribeClusterOptions(JsonObject json) { 41 | DescribeClusterOptionsConverter.fromJson(json, this); 42 | } 43 | 44 | public DescribeClusterOptions includeAuthorizedOperations(boolean includeAuthorizedOperations) { 45 | this.includeAuthorizedOperations = includeAuthorizedOperations; 46 | return this; 47 | } 48 | 49 | /** 50 | * Specify if authorized operations should be included in the response. Note that some 51 | * older brokers cannot not supply this information even if it is requested. 52 | */ 53 | public boolean includeAuthorizedOperations() { 54 | return includeAuthorizedOperations; 55 | } 56 | 57 | /** 58 | * Convert object to JSON representation 59 | * 60 | * @return JSON representation 61 | */ 62 | public JsonObject toJson() { 63 | JsonObject json = new JsonObject(); 64 | DescribeClusterOptionsConverter.toJson(this, json); 65 | return json; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "DescribeClusterOptions{" + 71 | "includeAuthorizedOperations=" + includeAuthorizedOperations + 72 | '}'; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/DescribeConsumerGroupsOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | @DataObject 24 | @JsonGen(publicConverter = false) 25 | public class DescribeConsumerGroupsOptions { 26 | private boolean includeAuthorizedOperations; 27 | 28 | /** 29 | * Constructor 30 | */ 31 | public DescribeConsumerGroupsOptions() {} 32 | 33 | 34 | /** 35 | * Constructor (from JSON representation) 36 | * 37 | * @param json JSON representation 38 | */ 39 | public DescribeConsumerGroupsOptions(JsonObject json) { 40 | DescribeConsumerGroupsOptionsConverter.fromJson(json, this); 41 | } 42 | 43 | public DescribeConsumerGroupsOptions includeAuthorizedOperations(boolean includeAuthorizedOperations) { 44 | this.includeAuthorizedOperations = includeAuthorizedOperations; 45 | return this; 46 | } 47 | 48 | public boolean includeAuthorizedOperations() { 49 | return includeAuthorizedOperations; 50 | } 51 | 52 | /** 53 | * Convert object to JSON representation 54 | * 55 | * @return JSON representation 56 | */ 57 | public JsonObject toJson() { 58 | JsonObject json = new JsonObject(); 59 | DescribeConsumerGroupsOptionsConverter.toJson(this, json); 60 | return json; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "DescribeConsumerGroupsOptions{" + 66 | "includeAuthorizedOperations=" + includeAuthorizedOperations + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/DescribeTopicsOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | @DataObject 24 | @JsonGen(publicConverter = false) 25 | public class DescribeTopicsOptions { 26 | private boolean includeAuthorizedOperations; 27 | 28 | /** 29 | * Constructor 30 | */ 31 | public DescribeTopicsOptions() {} 32 | 33 | /** 34 | * Constructor (from JSON representation) 35 | * 36 | * @param json JSON representation 37 | */ 38 | public DescribeTopicsOptions(JsonObject json) { 39 | DescribeTopicsOptionsConverter.fromJson(json, this); 40 | } 41 | 42 | public DescribeTopicsOptions includeAuthorizedOperations(boolean includeAuthorizedOperations) { 43 | this.includeAuthorizedOperations = includeAuthorizedOperations; 44 | return this; 45 | } 46 | 47 | public boolean includeAuthorizedOperations() { 48 | return includeAuthorizedOperations; 49 | } 50 | /** 51 | * Convert object to JSON representation 52 | * 53 | * @return JSON representation 54 | */ 55 | public JsonObject toJson() { 56 | JsonObject json = new JsonObject(); 57 | DescribeTopicsOptionsConverter.toJson(this, json); 58 | return json; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "DescribeConsumerGroupsOptions{" + 64 | "includeAuthorizedOperations=" + includeAuthorizedOperations + 65 | '}'; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/ListConsumerGroupOffsetsOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import io.vertx.kafka.client.common.TopicPartition; 23 | import java.util.List; 24 | 25 | @DataObject 26 | @JsonGen(publicConverter = false) 27 | public class ListConsumerGroupOffsetsOptions { 28 | 29 | private List topicPartitions = null; 30 | 31 | /** 32 | * Constructor 33 | */ 34 | public ListConsumerGroupOffsetsOptions() {} 35 | 36 | /** 37 | * Constructor (from JSON representation) 38 | * 39 | * @param json JSON representation 40 | */ 41 | public ListConsumerGroupOffsetsOptions(JsonObject json) { 42 | ListConsumerGroupOffsetsOptionsConverter.fromJson(json, this); 43 | } 44 | 45 | /** 46 | * Set the topic partitions to list as part of the result. 47 | * {@code null} includes all topic partitions. 48 | * 49 | * @param topicPartitions List of topic partitions to include 50 | * @return This ListGroupOffsetsOptions 51 | */ 52 | public ListConsumerGroupOffsetsOptions topicPartitions(List topicPartitions) { 53 | this.topicPartitions = topicPartitions; 54 | return this; 55 | } 56 | 57 | /** 58 | * Returns a list of topic partitions to add as part of the result. 59 | */ 60 | public List topicPartitions() { 61 | return topicPartitions; 62 | } 63 | 64 | /** 65 | * Convert object to JSON representation 66 | * 67 | * @return JSON representation 68 | */ 69 | public JsonObject toJson() { 70 | JsonObject json = new JsonObject(); 71 | ListConsumerGroupOffsetsOptionsConverter.toJson(this, json); 72 | return json; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "ListConsumerGroupOffsetsOptions{" + 78 | "topicPartitions=" + topicPartitions + 79 | '}'; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/ListOffsetsResultInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | @DataObject 24 | @JsonGen(publicConverter = false) 25 | public class ListOffsetsResultInfo { 26 | private long offset; 27 | private long timestamp; 28 | private Integer leaderEpoch; 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @param offset the offset 34 | * @param timestamp the timestamp 35 | * @param leaderEpoch the leader epoch 36 | */ 37 | public ListOffsetsResultInfo(long offset, long timestamp, Integer leaderEpoch) { 38 | this.offset = offset; 39 | this.timestamp = timestamp; 40 | this.leaderEpoch = leaderEpoch; 41 | } 42 | 43 | 44 | /** 45 | * Constructor (from JSON representation) 46 | * 47 | * @param json JSON representation 48 | */ 49 | public ListOffsetsResultInfo(JsonObject json) { 50 | ListOffsetsResultInfoConverter.fromJson(json, this); 51 | } 52 | 53 | /** 54 | * @return the offset 55 | */ 56 | public long getOffset() { 57 | return offset; 58 | } 59 | 60 | /** 61 | * @return the timestamp 62 | */ 63 | public long getTimestamp() { 64 | return timestamp; 65 | } 66 | 67 | /** 68 | * @return the leader epoch 69 | */ 70 | public Integer getLeaderEpoch() { 71 | return leaderEpoch; 72 | } 73 | 74 | /** 75 | * Set the offset 76 | * 77 | * @param offset the offset 78 | * @return current instance of the class to be fluent 79 | */ 80 | public ListOffsetsResultInfo setOffset(long offset) { 81 | this.offset = offset; 82 | return this; 83 | } 84 | /** 85 | * Set the timestamp 86 | * 87 | * @param timestamp the timestamp 88 | * @return current instance of the class to be fluent 89 | */ 90 | public ListOffsetsResultInfo setTimestamp(long timestamp) { 91 | this.timestamp = timestamp; 92 | return this; 93 | } 94 | /** 95 | * Set the leader epoch 96 | * 97 | * @param leaderEpoch the leader epoch 98 | * @return current instance of the class to be fluent 99 | */ 100 | public ListOffsetsResultInfo setLeaderEpoch(Integer leaderEpoch) { 101 | this.leaderEpoch = leaderEpoch; 102 | return this; 103 | } 104 | 105 | /** 106 | * Convert object to JSON representation 107 | * 108 | * @return JSON representation 109 | */ 110 | public JsonObject toJson() { 111 | 112 | JsonObject json = new JsonObject(); 113 | ListOffsetsResultInfoConverter.toJson(this, json); 114 | return json; 115 | } 116 | 117 | @Override 118 | public String toString() { 119 | return "ListOffsetsResultInfo{" + 120 | "offset=" + this.offset + 121 | ",timestamp=" + this.timestamp + 122 | (this.leaderEpoch != null ? ",leaderEpoch=" + this.leaderEpoch : "") + 123 | "}"; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/MemberAssignment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import io.vertx.kafka.client.common.TopicPartition; 23 | 24 | import java.util.Set; 25 | 26 | /** 27 | * A description of the assignments of a specific group member 28 | */ 29 | @DataObject 30 | @JsonGen(publicConverter = false) 31 | public class MemberAssignment { 32 | 33 | private Set topicPartitions; 34 | 35 | /** 36 | * Constructor 37 | */ 38 | public MemberAssignment() { 39 | 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param topicPartitions list of topic partitions 46 | */ 47 | public MemberAssignment(Set topicPartitions) { 48 | this.topicPartitions = topicPartitions; 49 | } 50 | 51 | /** 52 | * Constructor (from JSON representation) 53 | * 54 | * @param json JSON representation 55 | */ 56 | public MemberAssignment(JsonObject json) { 57 | 58 | MemberAssignmentConverter.fromJson(json, this); 59 | } 60 | 61 | /** 62 | * @return list of topic partitions 63 | */ 64 | public Set getTopicPartitions() { 65 | return topicPartitions; 66 | } 67 | 68 | /** 69 | * Set the list of topic partitions 70 | * 71 | * @param topicPartitions list of topic partitions 72 | * @return current instance of the class to be fluent 73 | */ 74 | public MemberAssignment setTopicPartitions(Set topicPartitions) { 75 | this.topicPartitions = topicPartitions; 76 | return this; 77 | } 78 | 79 | /** 80 | * Convert object to JSON representation 81 | * 82 | * @return JSON representation 83 | */ 84 | public JsonObject toJson() { 85 | 86 | JsonObject json = new JsonObject(); 87 | MemberAssignmentConverter.toJson(this, json); 88 | return json; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | 94 | return "MemberAssignment{" + 95 | "topicPartitions=" + this.topicPartitions + 96 | "}"; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/MemberDescription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | /** 24 | * A detailed description of a single group instance in the cluster 25 | */ 26 | @DataObject 27 | @JsonGen(publicConverter = false) 28 | public class MemberDescription { 29 | 30 | private String consumerId; 31 | private String clientId; 32 | private MemberAssignment assignment; 33 | private String host; 34 | 35 | /** 36 | * Constructor 37 | */ 38 | public MemberDescription() { 39 | 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param consumerId the consumer id of the group member 46 | * @param clientId the client id of the group member 47 | * @param host the host where the group member is running 48 | * @param assignment the assignment of the group member 49 | */ 50 | public MemberDescription(String consumerId, String clientId, String host, MemberAssignment assignment) { 51 | this.consumerId = consumerId; 52 | this.clientId = clientId; 53 | this.host = host; 54 | this.assignment = assignment; 55 | } 56 | 57 | /** 58 | * Constructor (from JSON representation) 59 | * 60 | * @param json JSON representation 61 | */ 62 | public MemberDescription(JsonObject json) { 63 | 64 | MemberDescriptionConverter.fromJson(json, this); 65 | } 66 | 67 | /** 68 | * @return the consumer id of the group member 69 | */ 70 | public String getConsumerId() { 71 | return consumerId; 72 | } 73 | 74 | /** 75 | * Set the consumer id of the group member 76 | * 77 | * @param consumerId the consumer id of the group member 78 | * @return current instance of the class to be fluent 79 | */ 80 | public MemberDescription setConsumerId(String consumerId) { 81 | this.consumerId = consumerId; 82 | return this; 83 | } 84 | 85 | /** 86 | * @return the client id of the group member 87 | */ 88 | public String getClientId() { 89 | return clientId; 90 | } 91 | 92 | /** 93 | * Set the client id of the group member 94 | * 95 | * @param clientId the client id of the group member 96 | * @return current instance of the class to be fluent 97 | */ 98 | public MemberDescription setClientId(String clientId) { 99 | this.clientId = clientId; 100 | return this; 101 | } 102 | 103 | /** 104 | * @return the assignment of the group member 105 | */ 106 | public MemberAssignment getAssignment() { 107 | return assignment; 108 | } 109 | 110 | /** 111 | * Set the assignment of the group member 112 | * 113 | * @param assignment the assignment of the group member 114 | * @return current instance of the class to be fluent 115 | */ 116 | public MemberDescription setAssignment(MemberAssignment assignment) { 117 | this.assignment = assignment; 118 | return this; 119 | } 120 | 121 | /** 122 | * @return the host where the group member is running 123 | */ 124 | public String getHost() { 125 | return host; 126 | } 127 | 128 | /** 129 | * Set the host where the group member is running 130 | * 131 | * @param host the host where the group member is running 132 | * @return current instance of the class to be fluent 133 | */ 134 | public MemberDescription setHost(String host) { 135 | this.host = host; 136 | return this; 137 | } 138 | 139 | /** 140 | * Convert object to JSON representation 141 | * 142 | * @return JSON representation 143 | */ 144 | public JsonObject toJson() { 145 | 146 | JsonObject json = new JsonObject(); 147 | MemberDescriptionConverter.toJson(this, json); 148 | return json; 149 | } 150 | 151 | @Override 152 | public String toString() { 153 | 154 | return "MemberDescription{" + 155 | "consumerId=" + this.consumerId + 156 | ",clientId=" + this.clientId + 157 | ",assignment=" + this.assignment + 158 | ",host=" + this.host + 159 | "}"; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/NewPartitions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * An update to the number of partitions including assignment. 27 | * Partitions can be increased only. If decrease, an exception from Kafka broker is received. 28 | * If no assignment is specifies brokers will randomly assign the partitions. 29 | */ 30 | @DataObject 31 | @JsonGen(publicConverter = false) 32 | public class NewPartitions { 33 | 34 | private int totalCount; 35 | 36 | private List> newAssignments; 37 | 38 | /** 39 | * Constructor 40 | */ 41 | public NewPartitions() { 42 | 43 | } 44 | 45 | 46 | /** 47 | * Constructor 48 | * 49 | * @param totalCount total count of partitions 50 | * @param newAssignments assignment to the brokers 51 | */ 52 | public NewPartitions(int totalCount, List> newAssignments) { 53 | this.totalCount = totalCount; 54 | this.newAssignments = newAssignments; 55 | } 56 | 57 | /** 58 | * Constructor 59 | * 60 | * @param totalCount total count of partitions 61 | */ 62 | public void NewPartitions(int totalCount) { 63 | this.totalCount = totalCount; 64 | this.newAssignments = null; 65 | } 66 | 67 | 68 | /** 69 | * Constructor (from JSON representation) 70 | * 71 | * @param json JSON representation 72 | */ 73 | public NewPartitions(JsonObject json) { 74 | 75 | NewPartitionsConverter.fromJson(json, this); 76 | } 77 | 78 | 79 | /** 80 | * Set the number of partitions for the topic 81 | * @param totalCount the number of partitions for the topic 82 | * @return current instance of the class to be fluent 83 | */ 84 | public NewPartitions setTotalCount(int totalCount) { 85 | this.totalCount = totalCount; 86 | return this; 87 | } 88 | 89 | /** 90 | * Set the assignment for the new partitions 91 | * @param assignments assignments of the partitions to the brokers 92 | * @return current instance of the class to be fluent 93 | */ 94 | public NewPartitions setNewAssignments(List> assignments) { 95 | this.newAssignments = assignments; 96 | return this; 97 | } 98 | 99 | /** 100 | * @return number of total partitions 101 | */ 102 | public int getTotalCount() { 103 | return this.totalCount; 104 | } 105 | 106 | /** 107 | * @return assignment of partitions to the brokers 108 | */ 109 | public List> getNewAssignments() { 110 | return this.newAssignments; 111 | } 112 | 113 | /** 114 | * Convert object to JSON representation 115 | * 116 | * @return JSON representation 117 | */ 118 | public JsonObject toJson() { 119 | 120 | JsonObject json = new JsonObject(); 121 | NewPartitionsConverter.toJson(this, json); 122 | return json; 123 | } 124 | 125 | @Override 126 | public String toString() { 127 | return "NewPartitions{" + 128 | "totalCount=" + this.totalCount + 129 | ",newAssignments=" + this.newAssignments + 130 | "}"; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/OffsetSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | @DataObject 24 | @JsonGen(publicConverter = false) 25 | public class OffsetSpec { 26 | public final static OffsetSpec EARLIEST = new OffsetSpec(-2L); 27 | public final static OffsetSpec LATEST = new OffsetSpec(-1L); 28 | public final static OffsetSpec TIMESTAMP(long timestamp) { 29 | return new OffsetSpec(timestamp); 30 | } 31 | 32 | private long spec; 33 | 34 | /** 35 | * Constructor 36 | * 37 | * @param spec the offset spec Spec.EARLIEST, Spec.LATEST, or a Spec.TIMESTAMP(long) value 38 | */ 39 | public OffsetSpec(long spec) { 40 | this.spec = spec; 41 | } 42 | 43 | /** 44 | * Constructor (from JSON representation) 45 | * 46 | * @param json JSON representation 47 | */ 48 | public OffsetSpec(JsonObject json) { 49 | OffsetSpecConverter.fromJson(json, this); 50 | } 51 | 52 | /** 53 | * @return offset spec 54 | */ 55 | public long getSpec() { 56 | return spec; 57 | } 58 | 59 | /** 60 | * Set the offset spec 61 | * 62 | * @param spec the offset spec 63 | * @return current instance of the class to be fluent 64 | */ 65 | public OffsetSpec setSpec(long spec) { 66 | this.spec = spec; 67 | return this; 68 | } 69 | 70 | /** 71 | * Convert object to JSON representation 72 | * 73 | * @return JSON representation 74 | */ 75 | public JsonObject toJson() { 76 | 77 | JsonObject json = new JsonObject(); 78 | OffsetSpecConverter.toJson(this, json); 79 | return json; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | String value; 85 | if (EARLIEST == this) { 86 | value = "EARLIEST"; 87 | } else if (LATEST == this) { 88 | value = "LATEST"; 89 | } else { 90 | value = String.format("TIMESTAMP(%d)", this.spec); 91 | } 92 | 93 | return "OffsetSpec{" + 94 | "spec=" + value + 95 | "}"; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/admin/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @ModuleGen(name = "vertx-kafka-client", groupPackage = "io.vertx") 17 | package io.vertx.kafka.admin; 18 | 19 | import io.vertx.codegen.annotations.ModuleGen; 20 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/ConfigResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.common; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import org.apache.kafka.common.config.ConfigResource.Type; 23 | 24 | /** 25 | * A class representing resources that have configuration 26 | */ 27 | @DataObject 28 | @JsonGen(publicConverter = false) 29 | public class ConfigResource { 30 | 31 | private String name; 32 | private boolean isDefault; 33 | private Type type; 34 | 35 | /** 36 | * Constructor 37 | */ 38 | public ConfigResource() { 39 | } 40 | 41 | /** 42 | * Constructor 43 | * 44 | * @param type a non-null resource type 45 | * @param name a non-null resource name 46 | */ 47 | public ConfigResource(Type type, 48 | java.lang.String name) { 49 | this.type = type; 50 | this.name = name; 51 | } 52 | 53 | /** 54 | * Constructor (from JSON representation) 55 | * 56 | * @param json JSON representation 57 | */ 58 | public ConfigResource(JsonObject json) { 59 | 60 | ConfigResourceConverter.fromJson(json, this); 61 | } 62 | 63 | /** 64 | * @return the resource name 65 | */ 66 | public String getName() { 67 | return name; 68 | } 69 | 70 | /** 71 | * Set the resource name 72 | * 73 | * @param name the resource name 74 | * @return current instance of the class to be fluent 75 | */ 76 | public ConfigResource setName(String name) { 77 | this.name = name; 78 | return this; 79 | } 80 | 81 | /** 82 | * @return true if this is the default resource of a resource type. Resource name is empty for the default resource. 83 | */ 84 | public boolean isDefault() { 85 | return isDefault; 86 | } 87 | 88 | /** 89 | * Set if this is the default resource of a resource type. Resource name is empty for the default resource. 90 | * 91 | * @param isDefault if this is the default resource of a resource type 92 | * @return current instance of the class to be fluent 93 | */ 94 | public ConfigResource setDefault(boolean isDefault) { 95 | this.isDefault = isDefault; 96 | return this; 97 | } 98 | 99 | /** 100 | * @return the resource type 101 | */ 102 | public Type getType() { 103 | return type; 104 | } 105 | 106 | /** 107 | * Set the resource type 108 | * 109 | * @param type the resource type 110 | * @return current instance of the class to be fluent 111 | */ 112 | public ConfigResource setType(Type type) { 113 | this.type = type; 114 | return this; 115 | } 116 | 117 | /** 118 | * Convert object to JSON representation 119 | * 120 | * @return JSON representation 121 | */ 122 | public JsonObject toJson() { 123 | 124 | JsonObject json = new JsonObject(); 125 | ConfigResourceConverter.toJson(this, json); 126 | return json; 127 | } 128 | 129 | @Override 130 | public boolean equals(Object o) { 131 | if (this == o) return true; 132 | if (o == null || getClass() != o.getClass()) return false; 133 | 134 | ConfigResource that = (ConfigResource) o; 135 | 136 | if (!name.equals(that.name)) return false; 137 | if (isDefault != that.isDefault) return false; 138 | return type == that.type; 139 | } 140 | 141 | @Override 142 | public int hashCode() { 143 | int result = 1; 144 | result = 31 * result + (name != null ? name.hashCode() : 0); 145 | result = 31 * result + (isDefault ? 1 : 0); 146 | result = 31 * result + type.ordinal(); 147 | return result; 148 | } 149 | 150 | @Override 151 | public String toString() { 152 | 153 | return "ConfigResource{" + 154 | "name=" + this.name + 155 | ",type=" + this.type + 156 | ",isDefault=" + this.isDefault + 157 | "}"; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/KafkaClientOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common; 17 | 18 | import io.vertx.codegen.annotations.DataObject; 19 | import io.vertx.codegen.annotations.GenIgnore; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | import io.vertx.core.tracing.TracingPolicy; 23 | import org.apache.kafka.clients.consumer.ConsumerConfig; 24 | import org.apache.kafka.clients.producer.ProducerConfig; 25 | 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.Properties; 29 | 30 | /** 31 | * Generic KafkaClient options. 32 | */ 33 | @DataObject 34 | @JsonGen(publicConverter = false) 35 | public class KafkaClientOptions { 36 | /** 37 | * Default peer address to set in traces tags is null, and will automatically pick up bootstrap server from config 38 | */ 39 | public static final String DEFAULT_TRACE_PEER_ADDRESS = null; 40 | 41 | /** 42 | * Default tracing policy is 'propagate' 43 | */ 44 | public static final TracingPolicy DEFAULT_TRACING_POLICY = TracingPolicy.PROPAGATE; 45 | 46 | private Map config; 47 | private String tracePeerAddress = DEFAULT_TRACE_PEER_ADDRESS; 48 | private TracingPolicy tracingPolicy = DEFAULT_TRACING_POLICY; 49 | 50 | public KafkaClientOptions() { 51 | } 52 | 53 | public KafkaClientOptions(JsonObject json) { 54 | this(); 55 | KafkaClientOptionsConverter.fromJson(json, this); 56 | } 57 | 58 | /** 59 | * Create KafkaClientOptions from underlying Kafka config as map 60 | * @param config config map to be passed down to underlying Kafka client 61 | * @return an instance of KafkaClientOptions 62 | */ 63 | public static KafkaClientOptions fromMap(Map config, boolean isProducer) { 64 | String tracePeerAddress = (String) config.getOrDefault(isProducer ? ProducerConfig.BOOTSTRAP_SERVERS_CONFIG : ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, ""); 65 | return new KafkaClientOptions().setTracePeerAddress(tracePeerAddress); 66 | } 67 | 68 | /** 69 | * Create KafkaClientOptions from underlying Kafka config as Properties 70 | * @param config config properties to be passed down to underlying Kafka client 71 | * @return an instance of KafkaClientOptions 72 | */ 73 | public static KafkaClientOptions fromProperties(Properties config, boolean isProducer) { 74 | String tracePeerAddress = (String) config.getOrDefault(isProducer ? ProducerConfig.BOOTSTRAP_SERVERS_CONFIG : ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, ""); 75 | return new KafkaClientOptions().setTracePeerAddress(tracePeerAddress); 76 | } 77 | 78 | /** 79 | * @return the kafka config 80 | */ 81 | public Map getConfig() { 82 | return config; 83 | } 84 | 85 | /** 86 | * Set the Kafka config. 87 | * 88 | * @param config the config 89 | * @return a reference to this, so the API can be used fluently 90 | */ 91 | public KafkaClientOptions setConfig(Map config) { 92 | this.config = config; 93 | return this; 94 | } 95 | 96 | /** 97 | * Set a Kafka config entry. 98 | * 99 | * @param key the config key 100 | * @param value the config value 101 | * @return a reference to this, so the API can be used fluently 102 | */ 103 | @GenIgnore 104 | public KafkaClientOptions setConfig(String key, Object value) { 105 | if (config == null) { 106 | config = new HashMap<>(); 107 | } 108 | config.put(key, value); 109 | return this; 110 | } 111 | 112 | /** 113 | * @return the kafka tracing policy 114 | */ 115 | public TracingPolicy getTracingPolicy() { 116 | return tracingPolicy; 117 | } 118 | 119 | /** 120 | * Set the Kafka tracing policy. 121 | * 122 | * @param tracingPolicy the tracing policy 123 | * @return a reference to this, so the API can be used fluently 124 | */ 125 | public KafkaClientOptions setTracingPolicy(TracingPolicy tracingPolicy) { 126 | this.tracingPolicy = tracingPolicy; 127 | return this; 128 | } 129 | 130 | /** 131 | * @return the Kafka "peer address" to show in trace tags 132 | */ 133 | public String getTracePeerAddress() { 134 | return tracePeerAddress; 135 | } 136 | 137 | /** 138 | * Set the Kafka address to show in trace tags. 139 | * Or leave it unset to automatically pick up bootstrap server from config instead. 140 | * 141 | * @param tracePeerAddress the Kafka "peer address" to show in trace tags 142 | * @return a reference to this, so the API can be used fluently 143 | */ 144 | public KafkaClientOptions setTracePeerAddress(String tracePeerAddress) { 145 | this.tracePeerAddress = tracePeerAddress; 146 | return this; 147 | } 148 | 149 | public JsonObject toJson() { 150 | return new JsonObject(config); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/PartitionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.common; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Information about a specific Kafka topic partition 27 | */ 28 | @DataObject 29 | @JsonGen(publicConverter = false) 30 | public class PartitionInfo { 31 | 32 | private List inSyncReplicas; 33 | private Node leader; 34 | private int partition; 35 | private List replicas; 36 | private String topic; 37 | 38 | /** 39 | * Constructor 40 | */ 41 | public PartitionInfo() { 42 | 43 | } 44 | 45 | /** 46 | * Constructor 47 | * 48 | * @param inSyncReplicas the subset of the replicas that are in sync 49 | * @param leader the node id of the node currently acting as a leader 50 | * @param partition the partition id 51 | * @param replicas the complete set of replicas for this partition 52 | * @param topic the topic name 53 | */ 54 | public PartitionInfo(List inSyncReplicas, Node leader, int partition, List replicas, String topic) { 55 | this.inSyncReplicas = inSyncReplicas; 56 | this.leader = leader; 57 | this.partition = partition; 58 | this.replicas = replicas; 59 | this.topic = topic; 60 | } 61 | 62 | /** 63 | * Constructor (from JSON representation) 64 | * 65 | * @param json JSON representation 66 | */ 67 | public PartitionInfo(JsonObject json) { 68 | 69 | PartitionInfoConverter.fromJson(json, this); 70 | } 71 | 72 | /** 73 | * @return the subset of the replicas that are in sync, that is caught-up to the leader and ready to take over as leader if the leader should fail 74 | */ 75 | public List getInSyncReplicas() { 76 | return this.inSyncReplicas; 77 | } 78 | 79 | /** 80 | * Set the subset of the replicas that are in sync 81 | * 82 | * @param inSyncReplicas the subset of the replicas that are in sync 83 | * @return current instance of the class to be fluent 84 | */ 85 | public PartitionInfo setInSyncReplicas(List inSyncReplicas) { 86 | this.inSyncReplicas = inSyncReplicas; 87 | return this; 88 | } 89 | 90 | /** 91 | * @return the node id of the node currently acting as a leader for this partition or null if there is no leader 92 | */ 93 | public Node getLeader() { 94 | return this.leader; 95 | } 96 | 97 | /** 98 | * Set the node id of the node currently acting as a leader 99 | * 100 | * @param leader the node id of the node currently acting as a leader 101 | * @return current instance of the class to be fluent 102 | */ 103 | public PartitionInfo setLeader(Node leader) { 104 | this.leader = leader; 105 | return this; 106 | } 107 | 108 | /** 109 | * @return the partition id 110 | */ 111 | public int getPartition() { 112 | return this.partition; 113 | } 114 | 115 | /** 116 | * Set the partition id 117 | * 118 | * @param partition the partition id 119 | * @return current instance of the class to be fluent 120 | */ 121 | public PartitionInfo setPartition(int partition) { 122 | this.partition = partition; 123 | return this; 124 | } 125 | 126 | /** 127 | * @return the complete set of replicas for this partition regardless of whether they are alive or up-to-date 128 | */ 129 | public List getReplicas() { 130 | return this.replicas; 131 | } 132 | 133 | /** 134 | * Set the complete set of replicas for this partition 135 | * 136 | * @param replicas the complete set of replicas for this partition 137 | * @return current instance of the class to be fluent 138 | */ 139 | public PartitionInfo setReplicas(List replicas) { 140 | this.replicas = replicas; 141 | return this; 142 | } 143 | 144 | /** 145 | * @return the topic name 146 | */ 147 | public String getTopic() { 148 | return this.topic; 149 | } 150 | 151 | /** 152 | * Set the topic name 153 | * 154 | * @param topic the topic name 155 | * @return current instance of the class to be fluent 156 | */ 157 | public PartitionInfo setTopic(String topic) { 158 | this.topic = topic; 159 | return this; 160 | } 161 | 162 | /** 163 | * Convert object to JSON representation 164 | * 165 | * @return JSON representation 166 | */ 167 | public JsonObject toJson() { 168 | 169 | JsonObject json = new JsonObject(); 170 | PartitionInfoConverter.toJson(this, json); 171 | return json; 172 | } 173 | 174 | @Override 175 | public String toString() { 176 | 177 | return "PartitionInfo{" + 178 | "topic=" + this.topic + 179 | ", partition=" + this.partition + 180 | ", inSyncReplicas=" + this.inSyncReplicas + 181 | ", leader=" + this.leader + 182 | ", replicas=" + this.replicas + 183 | "}"; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/TopicPartition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.common; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.core.json.JsonObject; 21 | 22 | /** 23 | * Represent information related to a partition for a topic 24 | */ 25 | @DataObject 26 | public class TopicPartition { 27 | 28 | private String topic; 29 | private int partition; 30 | 31 | /** 32 | * Constructor 33 | */ 34 | public TopicPartition() { 35 | } 36 | 37 | /** 38 | * Constructor 39 | * 40 | * @param topic the topic name 41 | * @param partition the partition number 42 | */ 43 | public TopicPartition(String topic, int partition) { 44 | this.topic = topic; 45 | this.partition = partition; 46 | } 47 | 48 | /** 49 | * Constructor (from JSON representation) 50 | * 51 | * @param json JSON representation 52 | */ 53 | public TopicPartition(JsonObject json) { 54 | this.topic = json.getString("topic"); 55 | this.partition = json.getInteger("partition"); 56 | } 57 | 58 | /** 59 | * Constructor (copy) 60 | * 61 | * @param that object to copy 62 | */ 63 | public TopicPartition(TopicPartition that) { 64 | this.topic = that.topic; 65 | this.partition = that.partition; 66 | } 67 | 68 | /** 69 | * @return the topic name 70 | */ 71 | public String getTopic() { 72 | return this.topic; 73 | } 74 | 75 | /** 76 | * Set the topic name 77 | * 78 | * @param topic the topic name 79 | * @return current instance of the class to be fluent 80 | */ 81 | public TopicPartition setTopic(String topic) { 82 | this.topic = topic; 83 | return this; 84 | } 85 | 86 | /** 87 | * @return the partition number 88 | */ 89 | public int getPartition() { 90 | return this.partition; 91 | } 92 | 93 | /** 94 | * Set the partition number 95 | * 96 | * @param partition the partition number 97 | * @return current instance of the class to be fluent 98 | */ 99 | public TopicPartition setPartition(int partition) { 100 | this.partition = partition; 101 | return this; 102 | } 103 | 104 | /** 105 | * Convert object to JSON representation 106 | * 107 | * @return JSON representation 108 | */ 109 | public JsonObject toJson() { 110 | return new JsonObject().put("topic", this.topic).put("partition", this.partition); 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | 116 | return "TopicPartition{" + 117 | "topic=" + this.topic + 118 | ", partition=" + this.partition + 119 | "}"; 120 | } 121 | 122 | @Override 123 | public boolean equals(Object o) { 124 | if (this == o) return true; 125 | if (o == null || getClass() != o.getClass()) return false; 126 | 127 | TopicPartition that = (TopicPartition) o; 128 | 129 | if (partition != that.partition) return false; 130 | return topic != null ? topic.equals(that.topic) : that.topic == null; 131 | } 132 | 133 | @Override 134 | public int hashCode() { 135 | int result = 1; 136 | result = 31 * result + partition; 137 | result = 31 * result + (topic != null ? topic.hashCode() : 0); 138 | return result; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/TopicPartitionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.common; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.codegen.json.annotations.JsonGen; 21 | import io.vertx.core.json.JsonObject; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * A class containing leadership, replicas and ISR information for a topic partition. 27 | */ 28 | @DataObject 29 | @JsonGen(publicConverter = false) 30 | public class TopicPartitionInfo { 31 | 32 | private List isr; 33 | private Node leader; 34 | private int partition; 35 | private List replicas; 36 | 37 | /** 38 | * Constructor 39 | */ 40 | public TopicPartitionInfo() { 41 | 42 | } 43 | 44 | /** 45 | * Constructor 46 | * 47 | * @param isr the subset of the replicas that are in sync 48 | * @param leader the node id of the node currently acting as a leader 49 | * @param partition the partition id 50 | * @param replicas the complete set of replicas for this partition 51 | */ 52 | public TopicPartitionInfo(List isr, Node leader, int partition, List replicas) { 53 | this.isr = isr; 54 | this.leader = leader; 55 | this.partition = partition; 56 | this.replicas = replicas; 57 | } 58 | 59 | /** 60 | * Constructor (from JSON representation) 61 | * 62 | * @param json JSON representation 63 | */ 64 | public TopicPartitionInfo(JsonObject json) { 65 | 66 | TopicPartitionInfoConverter.fromJson(json, this); 67 | } 68 | 69 | /** 70 | * @return the subset of the replicas that are in sync, that is caught-up to the leader and ready to take over as leader if the leader should fail 71 | */ 72 | public List getIsr() { 73 | return this.isr; 74 | } 75 | 76 | /** 77 | * Set the subset of the replicas that are in sync 78 | * 79 | * @param isr the subset of the replicas that are in sync 80 | * @return current instance of the class to be fluent 81 | */ 82 | public TopicPartitionInfo setIsr(List isr) { 83 | this.isr = isr; 84 | return this; 85 | } 86 | 87 | /** 88 | * @return the node id of the node currently acting as a leader for this partition or null if there is no leader 89 | */ 90 | public Node getLeader() { 91 | return this.leader; 92 | } 93 | 94 | /** 95 | * Set the node id of the node currently acting as a leader 96 | * 97 | * @param leader the node id of the node currently acting as a leader 98 | * @return current instance of the class to be fluent 99 | */ 100 | public TopicPartitionInfo setLeader(Node leader) { 101 | this.leader = leader; 102 | return this; 103 | } 104 | 105 | /** 106 | * @return the partition id 107 | */ 108 | public int getPartition() { 109 | return this.partition; 110 | } 111 | 112 | /** 113 | * Set the partition id 114 | * 115 | * @param partition the partition id 116 | * @return current instance of the class to be fluent 117 | */ 118 | public TopicPartitionInfo setPartition(int partition) { 119 | this.partition = partition; 120 | return this; 121 | } 122 | 123 | /** 124 | * @return the complete set of replicas for this partition regardless of whether they are alive or up-to-date 125 | */ 126 | public List getReplicas() { 127 | return this.replicas; 128 | } 129 | 130 | /** 131 | * Set the complete set of replicas for this partition 132 | * 133 | * @param replicas the complete set of replicas for this partition 134 | * @return current instance of the class to be fluent 135 | */ 136 | public TopicPartitionInfo setReplicas(List replicas) { 137 | this.replicas = replicas; 138 | return this; 139 | } 140 | 141 | /** 142 | * Convert object to JSON representation 143 | * 144 | * @return JSON representation 145 | */ 146 | public JsonObject toJson() { 147 | 148 | JsonObject json = new JsonObject(); 149 | TopicPartitionInfoConverter.toJson(this, json); 150 | return json; 151 | } 152 | 153 | @Override 154 | public String toString() { 155 | 156 | return "PartitionInfo{" + 157 | "partition=" + this.partition + 158 | ", isr=" + this.isr + 159 | ", leader=" + this.leader + 160 | ", replicas=" + this.replicas + 161 | "}"; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/impl/CloseHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common.impl; 17 | 18 | import io.vertx.core.*; 19 | import io.vertx.core.internal.ContextInternal; 20 | import io.vertx.core.internal.VertxInternal; 21 | 22 | import java.util.function.BiConsumer; 23 | import java.util.function.Consumer; 24 | 25 | /** 26 | * An helper class for managing automatic clean-up in verticles. 27 | * 28 | * @author Julien Viet 29 | */ 30 | public class CloseHandler { 31 | 32 | private Closeable closeable; 33 | private Runnable closeableHookCleanup; 34 | private final BiConsumer> close; 35 | 36 | public CloseHandler(BiConsumer> close) { 37 | this.close = close; 38 | } 39 | 40 | public void registerCloseHook(VertxInternal vertx) { 41 | registerCloseHook(vertx::addCloseHook, vertx::removeCloseHook); 42 | } 43 | 44 | public void registerCloseHook(ContextInternal context) { 45 | registerCloseHook(context::addCloseHook, context::removeCloseHook); 46 | } 47 | 48 | private synchronized void registerCloseHook(Consumer addCloseHook, Consumer removeCloseHook) { 49 | if (closeable == null) { 50 | closeable = ar -> { 51 | synchronized (CloseHandler.this) { 52 | if (closeable == null) { 53 | ar.succeed(); 54 | return; 55 | } 56 | closeable = null; 57 | } 58 | close.accept(0L, ar); 59 | }; 60 | closeableHookCleanup = () -> { 61 | synchronized (CloseHandler.this) { 62 | if (closeable != null) { 63 | removeCloseHook.accept(closeable); 64 | closeable = null; 65 | } 66 | } 67 | }; 68 | addCloseHook.accept(closeable); 69 | } 70 | } 71 | 72 | public synchronized void unregisterCloseHook() { 73 | if (closeableHookCleanup != null) { 74 | closeableHookCleanup.run(); 75 | } 76 | } 77 | 78 | public void close() { 79 | unregisterCloseHook(); 80 | close.accept(0L, (res, err) -> {}); 81 | } 82 | 83 | public void close(Completable completionHandler) { 84 | unregisterCloseHook(); 85 | close.accept(0L, completionHandler); 86 | } 87 | 88 | public void close(long timeout, Completable completionHandler) { 89 | unregisterCloseHook(); 90 | close.accept(timeout, completionHandler); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/tracing/ConsumerTracer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common.tracing; 17 | 18 | import io.vertx.core.Context; 19 | import io.vertx.core.spi.tracing.SpanKind; 20 | import io.vertx.core.spi.tracing.TagExtractor; 21 | import io.vertx.core.spi.tracing.VertxTracer; 22 | import io.vertx.core.tracing.TracingPolicy; 23 | import io.vertx.kafka.client.common.KafkaClientOptions; 24 | import org.apache.kafka.clients.consumer.ConsumerConfig; 25 | import org.apache.kafka.clients.consumer.ConsumerRecord; 26 | import org.apache.kafka.common.header.Headers; 27 | import org.apache.kafka.common.utils.Utils; 28 | 29 | import java.util.AbstractMap; 30 | import java.util.Collections; 31 | import java.util.Map; 32 | import java.util.stream.StreamSupport; 33 | 34 | /** 35 | * Tracer for Kafka consumer, wrapping the generic tracer. 36 | */ 37 | public class ConsumerTracer { 38 | private final VertxTracer tracer; 39 | private final String address; 40 | private final String port; 41 | private final TracingPolicy policy; 42 | 43 | /** 44 | * Creates a ConsumerTracer, which provides an opinionated facade for using {@link io.vertx.core.spi.tracing.VertxTracer} 45 | * with a Kafka Consumer use case. 46 | * The method will return {@code null} if Tracing is not setup in Vert.x, or if {@code TracingPolicy.IGNORE} is used. 47 | * @param tracer the generic tracer object 48 | * @param opts Kafka client options 49 | * @param the type of spans that is going to be generated, depending on the tracing system (zipkin, opentracing ...) 50 | * @return a new instance of {@code ConsumerTracer}, or {@code null} 51 | */ 52 | public static ConsumerTracer create(VertxTracer tracer, KafkaClientOptions opts) { 53 | TracingPolicy policy = opts.getTracingPolicy() != null ? opts.getTracingPolicy() : TracingPolicy.ALWAYS; 54 | if (policy == TracingPolicy.IGNORE || tracer == null) { 55 | // No need to create a tracer if it won't be used 56 | return null; 57 | } 58 | String address = opts.getTracePeerAddress(); 59 | // Search for peer address in config if not provided 60 | if (address == null) { 61 | if (opts.getConfig() != null) { 62 | address = (String) opts.getConfig().getOrDefault(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, ""); 63 | } else { 64 | address = ""; 65 | } 66 | } 67 | return new ConsumerTracer(tracer, policy, address); 68 | } 69 | 70 | private ConsumerTracer(VertxTracer tracer, TracingPolicy policy, String bootstrapServer) { 71 | this.tracer = tracer; 72 | this.address = bootstrapServer; 73 | Integer port = Utils.getPort(bootstrapServer); 74 | this.port = port == null ? null : port.toString(); 75 | this.policy = policy; 76 | } 77 | 78 | private static Iterable> convertHeaders(Headers headers) { 79 | if (headers == null) { 80 | return Collections.emptyList(); 81 | } 82 | return () -> StreamSupport.stream(headers.spliterator(), false) 83 | .map(h -> (Map.Entry) new AbstractMap.SimpleEntry<>(h.key(), new String(h.value()))).iterator(); 84 | } 85 | 86 | public StartedSpan prepareMessageReceived(Context context, ConsumerRecord rec) { 87 | TraceContext tc = new TraceContext("consumer", address, port, rec.topic()); 88 | S span = tracer.receiveRequest(context, SpanKind.MESSAGING, policy, tc, "kafka_receive", convertHeaders(rec.headers()), TraceTags.TAG_EXTRACTOR); 89 | return new StartedSpan(span); 90 | } 91 | 92 | public class StartedSpan { 93 | private final S span; 94 | 95 | private StartedSpan(S span) { 96 | this.span = span; 97 | } 98 | 99 | public void finish(Context context) { 100 | // We don't add any new tag to the span here, just stop span timer 101 | tracer.sendResponse(context, null, span, null, TagExtractor.empty()); 102 | } 103 | 104 | public void fail(Context context, Throwable failure) { 105 | tracer.sendResponse(context, null, span, failure, TagExtractor.empty()); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/tracing/ProducerTracer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common.tracing; 17 | 18 | import io.vertx.core.Context; 19 | import io.vertx.core.spi.tracing.SpanKind; 20 | import io.vertx.core.spi.tracing.TagExtractor; 21 | import io.vertx.core.spi.tracing.VertxTracer; 22 | import io.vertx.core.tracing.TracingPolicy; 23 | import io.vertx.kafka.client.common.KafkaClientOptions; 24 | import org.apache.kafka.clients.producer.ProducerConfig; 25 | import org.apache.kafka.clients.producer.ProducerRecord; 26 | import org.apache.kafka.common.utils.Utils; 27 | 28 | /** 29 | * Tracer for Kafka producer, wrapping the generic tracer. 30 | */ 31 | public class ProducerTracer { 32 | private final VertxTracer tracer; 33 | private final String address; 34 | private final String port; 35 | private final TracingPolicy policy; 36 | 37 | /** 38 | * Creates a ProducerTracer, which provides an opinionated facade for using {@link io.vertx.core.spi.tracing.VertxTracer} 39 | * with a Kafka Producer use case. 40 | * The method will return {@code null} if Tracing is not setup in Vert.x, or if {@code TracingPolicy.IGNORE} is used. 41 | * @param tracer the generic tracer object 42 | * @param opts Kafka client options 43 | * @param the type of spans that is going to be generated, depending on the tracing system (zipkin, opentracing ...) 44 | * @return a new instance of {@code ProducerTracer}, or {@code null} 45 | */ 46 | public static ProducerTracer create(VertxTracer tracer, KafkaClientOptions opts) { 47 | TracingPolicy policy = opts.getTracingPolicy() != null ? opts.getTracingPolicy() : TracingPolicy.PROPAGATE; 48 | if (policy == TracingPolicy.IGNORE || tracer == null) { 49 | // No need to create a tracer if it won't be used 50 | return null; 51 | } 52 | String address = opts.getTracePeerAddress(); 53 | // Search for peer address in config if not provided 54 | if (address == null) { 55 | if (opts.getConfig() != null) { 56 | address = (String) opts.getConfig().getOrDefault(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, ""); 57 | } else { 58 | address = ""; 59 | } 60 | } 61 | return new ProducerTracer(tracer, policy, address); 62 | } 63 | 64 | private ProducerTracer(VertxTracer tracer, TracingPolicy policy, String bootstrapServer) { 65 | this.tracer = tracer; 66 | this.address = bootstrapServer; 67 | Integer port = Utils.getPort(bootstrapServer); 68 | this.port = port == null ? null : port.toString(); 69 | this.policy = policy; 70 | } 71 | 72 | public StartedSpan prepareSendMessage(Context context, ProducerRecord record) { 73 | TraceContext tc = new TraceContext("producer", address, port, record.topic()); 74 | S span = tracer.sendRequest(context, SpanKind.MESSAGING, policy, tc, "kafka_send", (k, v) -> record.headers().add(k, v.getBytes()), TraceTags.TAG_EXTRACTOR); 75 | return new StartedSpan(span); 76 | } 77 | 78 | public class StartedSpan { 79 | private final S span; 80 | 81 | private StartedSpan(S span) { 82 | this.span = span; 83 | } 84 | 85 | public void finish(Context context) { 86 | // We don't add any new tag to the span here, just stop span timer 87 | tracer.receiveResponse(context, null, span, null, TagExtractor.empty()); 88 | } 89 | 90 | public void fail(Context context, Throwable failure) { 91 | tracer.receiveResponse(context, null, span, failure, TagExtractor.empty()); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/tracing/TraceContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common.tracing; 17 | 18 | /** 19 | * TraceContext holds some context for tracing during a message writing / reading process 20 | */ 21 | class TraceContext { 22 | final String kind; 23 | final String address; 24 | final String port; 25 | final String topic; 26 | 27 | TraceContext(String kind, String address, String port, String topic) { 28 | this.kind = kind; 29 | this.address = address; 30 | this.port = port; 31 | this.topic = topic; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/common/tracing/TraceTags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.common.tracing; 17 | 18 | import io.vertx.core.spi.tracing.TagExtractor; 19 | 20 | import java.util.function.Function; 21 | 22 | /** 23 | * Tags for Kafka Tracing 24 | */ 25 | public enum TraceTags { 26 | // See https://opentelemetry.io/docs/specs/semconv/messaging/kafka/ 27 | SERVER_ADDRESS("server.address", q -> q.address), 28 | SERVER_PORT("server.port", q -> q.port), 29 | PEER_SERVICE("peer.service", q -> "kafka"), 30 | BUS_DESTINATION("messaging.destination.name", q -> q.topic); 31 | 32 | static final TagExtractor TAG_EXTRACTOR = new TagExtractor<>() { 33 | private final TraceTags[] TAGS = TraceTags.values(); 34 | 35 | @Override 36 | public int len(TraceContext obj) { 37 | return TAGS.length; 38 | } 39 | 40 | @Override 41 | public String name(TraceContext obj, int index) { 42 | return TAGS[index].name; 43 | } 44 | 45 | @Override 46 | public String value(TraceContext obj, int index) { 47 | return TAGS[index].fn.apply(obj); 48 | } 49 | }; 50 | 51 | final String name; 52 | final Function fn; 53 | 54 | TraceTags(String name, Function fn) { 55 | this.name = name; 56 | this.fn = fn; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/KafkaConsumerRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.consumer; 18 | 19 | import io.vertx.codegen.annotations.GenIgnore; 20 | import io.vertx.codegen.annotations.VertxGen; 21 | import io.vertx.kafka.client.producer.KafkaHeader; 22 | import org.apache.kafka.clients.consumer.ConsumerRecord; 23 | import org.apache.kafka.common.record.TimestampType; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Vert.x Kafka consumer record 29 | */ 30 | @VertxGen 31 | public interface KafkaConsumerRecord { 32 | 33 | /** 34 | * @return the topic this record is received from 35 | */ 36 | String topic(); 37 | 38 | /** 39 | * @return the partition from which this record is received 40 | */ 41 | int partition(); 42 | 43 | /** 44 | * @return the position of this record in the corresponding Kafka partition. 45 | */ 46 | long offset(); 47 | 48 | /** 49 | * @return the timestamp of this record 50 | */ 51 | long timestamp(); 52 | 53 | /** 54 | * @return the timestamp type of this record 55 | */ 56 | TimestampType timestampType(); 57 | 58 | /** 59 | * @return the key (or null if no key is specified) 60 | */ 61 | K key(); 62 | 63 | /** 64 | * @return the value 65 | */ 66 | V value(); 67 | 68 | /** 69 | * @return the list of consumer record headers 70 | */ 71 | List headers(); 72 | 73 | /** 74 | * @return the native Kafka consumer record with backed information 75 | */ 76 | @GenIgnore 77 | ConsumerRecord record(); 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/KafkaConsumerRecords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.consumer; 17 | 18 | import org.apache.kafka.clients.consumer.ConsumerRecords; 19 | 20 | import io.vertx.codegen.annotations.GenIgnore; 21 | import io.vertx.codegen.annotations.VertxGen; 22 | 23 | /** 24 | * Vert.x Kafka consumer records 25 | */ 26 | @VertxGen 27 | public interface KafkaConsumerRecords { 28 | /** 29 | * @return the total number of records in this batch 30 | */ 31 | int size(); 32 | /** 33 | * @return whether this batch contains any records 34 | */ 35 | boolean isEmpty(); 36 | /** 37 | * Get the record at the given index 38 | * @param index the index of the record to get 39 | * @throws IndexOutOfBoundsException if index <0 or index>={@link #size()} 40 | */ 41 | KafkaConsumerRecord recordAt(int index); 42 | 43 | /** 44 | * @return the native Kafka consumer records with backed information 45 | */ 46 | @GenIgnore 47 | ConsumerRecords records(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/OffsetAndMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.consumer; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.core.json.JsonObject; 21 | 22 | /** 23 | * Provide additional metadata when an offset is committed 24 | */ 25 | @DataObject 26 | public class OffsetAndMetadata { 27 | 28 | private long offset; 29 | private String metadata; 30 | 31 | /** 32 | * Constructor 33 | */ 34 | public OffsetAndMetadata() { 35 | } 36 | 37 | /** 38 | * Constructor 39 | * 40 | * @param offset offset to commit 41 | * @param metadata additional metadata with the offset committed 42 | */ 43 | public OffsetAndMetadata(long offset, String metadata) { 44 | this.offset = offset; 45 | this.metadata = metadata; 46 | } 47 | 48 | /** 49 | * Constructor (from JSON representation) 50 | * 51 | * @param json JSON representation 52 | */ 53 | public OffsetAndMetadata(JsonObject json) { 54 | this.offset = json.getLong("offset"); 55 | this.metadata = json.getString("metadata"); 56 | } 57 | 58 | /** 59 | * Constructor (copy) 60 | * 61 | * @param that object to copy 62 | */ 63 | public OffsetAndMetadata(OffsetAndMetadata that) { 64 | this.offset = that.offset; 65 | this.metadata = that.metadata; 66 | } 67 | 68 | /** 69 | * @return offset to commit 70 | */ 71 | public long getOffset() { 72 | return this.offset; 73 | } 74 | 75 | /** 76 | * Set the offset to commit 77 | * 78 | * @param offset offset to commit 79 | * @return current instance of the class to be fluent 80 | */ 81 | public OffsetAndMetadata setOffset(long offset) { 82 | this.offset = offset; 83 | return this; 84 | } 85 | 86 | /** 87 | * @return additional metadata with the offset committed 88 | */ 89 | public String getMetadata() { 90 | return this.metadata; 91 | } 92 | 93 | /** 94 | * Set additional metadata for the offset committed 95 | * 96 | * @param metadata additional metadata 97 | * @return current instance of the class to be fluent 98 | */ 99 | public OffsetAndMetadata setMetadata(String metadata) { 100 | this.metadata = metadata; 101 | return this; 102 | } 103 | 104 | /** 105 | * Convert object to JSON representation 106 | * 107 | * @return JSON representation 108 | */ 109 | public JsonObject toJson() { 110 | return new JsonObject().put("offset", this.offset).put("metadata", this.metadata); 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | 116 | return "OffsetAndMetadata{" + 117 | "offset=" + this.offset + 118 | ", metadata=" + this.metadata + 119 | "}"; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/OffsetAndTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.consumer; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.core.json.JsonObject; 21 | 22 | /** 23 | * Represent information related to a Offset with timestamp information 24 | */ 25 | @DataObject 26 | public class OffsetAndTimestamp { 27 | 28 | private long offset; 29 | private long timestamp; 30 | 31 | /** 32 | * Constructor 33 | */ 34 | public OffsetAndTimestamp() { 35 | } 36 | 37 | /** 38 | * Constructor 39 | * 40 | * @param offset the offset 41 | * @param timestamp the timestamp 42 | */ 43 | public OffsetAndTimestamp(long offset, long timestamp) { 44 | this.offset = offset; 45 | this.timestamp = timestamp; 46 | } 47 | 48 | /** 49 | * Constructor (from JSON representation) 50 | * 51 | * @param json JSON representation 52 | */ 53 | public OffsetAndTimestamp(JsonObject json) { 54 | this.offset = json.getLong("offset"); 55 | this.timestamp = json.getLong("timestamp"); 56 | } 57 | 58 | /** 59 | * Constructor (copy) 60 | * 61 | * @param that object to copy 62 | */ 63 | public OffsetAndTimestamp(OffsetAndTimestamp that) { 64 | this.offset = that.offset; 65 | this.timestamp = that.timestamp; 66 | } 67 | 68 | /** 69 | * @return the offset 70 | */ 71 | public long getOffset() { 72 | return this.offset; 73 | } 74 | 75 | /** 76 | * Set the offset 77 | * 78 | * @param offset the offset 79 | * @return current instance of the class to be fluent 80 | */ 81 | public OffsetAndTimestamp setOffset(long offset) { 82 | this.offset = offset; 83 | return this; 84 | } 85 | 86 | /** 87 | * @return the timestamp 88 | */ 89 | public long getTimestamp() { 90 | return this.timestamp; 91 | } 92 | 93 | /** 94 | * Set the timestamp 95 | * 96 | * @param timestamp the timestamp 97 | * @return current instance of the class to be fluent 98 | */ 99 | public OffsetAndTimestamp setTimestamp(long timestamp) { 100 | this.timestamp = timestamp; 101 | return this; 102 | } 103 | 104 | /** 105 | * Convert object to JSON representation 106 | * 107 | * @return JSON representation 108 | */ 109 | public JsonObject toJson() { 110 | return new JsonObject().put("offset", this.offset).put("timestamp", this.timestamp); 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | 116 | return "OffsetAndTimestamp{" + 117 | "offset=" + this.offset + 118 | ", timestamp=" + this.timestamp + 119 | "}"; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/impl/KafkaConsumerRecordImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.consumer.impl; 18 | 19 | import io.vertx.kafka.client.consumer.KafkaConsumerRecord; 20 | import io.vertx.kafka.client.producer.KafkaHeader; 21 | import org.apache.kafka.clients.consumer.ConsumerRecord; 22 | import org.apache.kafka.common.header.Header; 23 | import org.apache.kafka.common.record.TimestampType; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * Vert.x Kafka consumer record implementation 31 | */ 32 | public class KafkaConsumerRecordImpl implements KafkaConsumerRecord { 33 | 34 | private final ConsumerRecord record; 35 | private List headers; 36 | 37 | /** 38 | * Constructor 39 | * 40 | * @param record Kafka consumer record for backing information 41 | */ 42 | public KafkaConsumerRecordImpl(ConsumerRecord record) { 43 | this.record = record; 44 | } 45 | 46 | @Override 47 | public String topic() { 48 | return this.record.topic(); 49 | } 50 | 51 | @Override 52 | public int partition() { 53 | return this.record.partition(); 54 | } 55 | 56 | @Override 57 | public long offset() { 58 | return this.record.offset(); 59 | } 60 | 61 | @Override 62 | public long timestamp() { 63 | return this.record.timestamp(); 64 | } 65 | 66 | @Override 67 | public TimestampType timestampType() { 68 | return this.record.timestampType(); 69 | } 70 | 71 | @Override 72 | public K key() { 73 | return this.record.key(); 74 | } 75 | 76 | @Override 77 | public V value() { 78 | return this.record.value(); 79 | } 80 | 81 | @Override 82 | public ConsumerRecord record() { 83 | return this.record; 84 | } 85 | 86 | @Override 87 | public List headers() { 88 | if (headers == null) { 89 | if (record.headers() == null) { 90 | headers = Collections.emptyList(); 91 | } else { 92 | headers = new ArrayList<>(); 93 | for (Header header : record.headers()) { 94 | headers.add(KafkaHeader.header(header.key(), header.value())); 95 | } 96 | } 97 | } 98 | return headers; 99 | } 100 | 101 | @Override 102 | public String toString() { 103 | 104 | return "KafkaConsumerRecord{" + 105 | "topic=" + this.record.topic() + 106 | ",partition=" + this.record.partition() + 107 | ",offset=" + this.record.offset() + 108 | ",timestamp=" + this.record.timestamp() + 109 | ",key=" + this.record.key() + 110 | ",value=" + this.record.value() + 111 | ",headers=" + this.record.headers() + 112 | "}"; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/consumer/impl/KafkaConsumerRecordsImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.consumer.impl; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import org.apache.kafka.clients.consumer.ConsumerRecords; 22 | 23 | import io.vertx.kafka.client.consumer.KafkaConsumerRecord; 24 | import io.vertx.kafka.client.consumer.KafkaConsumerRecords; 25 | 26 | public class KafkaConsumerRecordsImpl implements KafkaConsumerRecords{ 27 | 28 | private final ConsumerRecords records; 29 | private List> list; 30 | 31 | public KafkaConsumerRecordsImpl(ConsumerRecords records) { 32 | this.records = records; 33 | } 34 | 35 | @Override 36 | public int size() { 37 | return records.count(); 38 | } 39 | 40 | @Override 41 | public boolean isEmpty() { 42 | return records.isEmpty(); 43 | } 44 | 45 | @Override 46 | public KafkaConsumerRecord recordAt(int index) { 47 | if (list == null) { 48 | list = new ArrayList<>(records.count()); 49 | records.forEach(record -> list.add(new KafkaConsumerRecordImpl(record))); 50 | } 51 | return list.get(index); 52 | } 53 | 54 | @Override 55 | public ConsumerRecords records() { 56 | return records; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | @ModuleGen(name = "vertx-kafka-client", groupPackage = "io.vertx") 17 | package io.vertx.kafka.client; 18 | 19 | import io.vertx.codegen.annotations.ModuleGen; 20 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/producer/KafkaHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.producer; 18 | 19 | import io.vertx.codegen.annotations.CacheReturn; 20 | import io.vertx.codegen.annotations.GenIgnore; 21 | import io.vertx.codegen.annotations.VertxGen; 22 | import io.vertx.core.buffer.Buffer; 23 | import io.vertx.kafka.client.producer.impl.KafkaHeaderImpl; 24 | 25 | /** 26 | * Vert.x Kafka producer record header. 27 | */ 28 | @VertxGen 29 | public interface KafkaHeader { 30 | 31 | static KafkaHeader header(String key, Buffer value) { 32 | return new KafkaHeaderImpl(key, value); 33 | } 34 | 35 | static KafkaHeader header(String key, String value) { 36 | return new KafkaHeaderImpl(key, value); 37 | } 38 | 39 | @GenIgnore 40 | static KafkaHeader header(String key, byte[] value) { 41 | return new KafkaHeaderImpl(key, Buffer.buffer(value)); 42 | } 43 | 44 | /** 45 | * @return the buffer key 46 | */ 47 | @CacheReturn 48 | String key(); 49 | 50 | /** 51 | * @return the buffer value 52 | */ 53 | @CacheReturn 54 | Buffer value(); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/producer/KafkaProducerRecord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.producer; 18 | 19 | import io.vertx.codegen.annotations.CacheReturn; 20 | import io.vertx.codegen.annotations.Fluent; 21 | import io.vertx.codegen.annotations.GenIgnore; 22 | import io.vertx.codegen.annotations.VertxGen; 23 | import io.vertx.core.buffer.Buffer; 24 | import io.vertx.kafka.client.producer.impl.KafkaProducerRecordImpl; 25 | import org.apache.kafka.clients.producer.ProducerRecord; 26 | 27 | import java.util.List; 28 | 29 | /** 30 | * Vert.x Kafka producer record. 31 | */ 32 | @VertxGen 33 | public interface KafkaProducerRecord { 34 | 35 | /** 36 | * Create a concrete instance of a Vert.x producer record 37 | * 38 | * @param topic the topic this record is being sent to 39 | * @param key the key (or null if no key is specified) 40 | * @param value the value 41 | * @param timestamp the timestamp of this record 42 | * @param partition the partition to which the record will be sent (or null if no partition was specified) 43 | * @param key type 44 | * @param value type 45 | * @return Vert.x producer record 46 | */ 47 | static KafkaProducerRecord create(String topic, K key, V value, Long timestamp, Integer partition) { 48 | 49 | return new KafkaProducerRecordImpl<>(topic, key, value, timestamp, partition); 50 | } 51 | 52 | /** 53 | * Create a concrete instance of a Vert.x producer record 54 | * 55 | * @param topic the topic this record is being sent to 56 | * @param key the key (or null if no key is specified) 57 | * @param value the value 58 | * @param partition the partition to which the record will be sent (or null if no partition was specified) 59 | * @param key type 60 | * @param value type 61 | * @return Vert.x producer record 62 | */ 63 | @GenIgnore 64 | static KafkaProducerRecord create(String topic, K key, V value, Integer partition) { 65 | 66 | return new KafkaProducerRecordImpl<>(topic, key, value, partition); 67 | } 68 | 69 | /** 70 | * Create a concrete instance of a Vert.x producer record 71 | * 72 | * @param topic the topic this record is being sent to 73 | * @param key the key (or null if no key is specified) 74 | * @param value the value 75 | * @param key type 76 | * @param value type 77 | * @return Vert.x producer record 78 | */ 79 | static KafkaProducerRecord create(String topic, K key, V value) { 80 | 81 | return new KafkaProducerRecordImpl<>(topic, key, value); 82 | } 83 | 84 | /** 85 | * Create a concrete instance of a Vert.x producer record 86 | * 87 | * @param topic the topic this record is being sent to 88 | * @param value the value 89 | * @param key type 90 | * @param value type 91 | * @return Vert.x producer record 92 | */ 93 | static KafkaProducerRecord create(String topic, V value) { 94 | 95 | return new KafkaProducerRecordImpl<>(topic, value); 96 | } 97 | 98 | /** 99 | * @return the topic this record is being sent to 100 | */ 101 | String topic(); 102 | 103 | /** 104 | * @return the key (or null if no key is specified) 105 | */ 106 | K key(); 107 | 108 | /** 109 | * @return the value 110 | */ 111 | V value(); 112 | 113 | /** 114 | * @return the timestamp of this record 115 | */ 116 | Long timestamp(); 117 | 118 | /** 119 | * @return the partition to which the record will be sent (or null if no partition was specified) 120 | */ 121 | Integer partition(); 122 | 123 | /** 124 | * Like {@link #addHeader(KafkaHeader)} but with a key/value pair 125 | */ 126 | @Fluent 127 | KafkaProducerRecord addHeader(String key, String value); 128 | 129 | /** 130 | * Like {@link #addHeader(KafkaHeader)} but with a key/value pair 131 | */ 132 | @Fluent 133 | KafkaProducerRecord addHeader(String key, Buffer value); 134 | 135 | /** 136 | * Add an header to this record. 137 | * 138 | * @param header the header 139 | * @return current KafkaProducerRecord instance 140 | */ 141 | @Fluent 142 | KafkaProducerRecord addHeader(KafkaHeader header); 143 | 144 | /** 145 | * Add a list of headers to this record. 146 | * 147 | * @param headers the headers 148 | * @return current KafkaProducerRecord instance 149 | */ 150 | @Fluent 151 | KafkaProducerRecord addHeaders(List headers); 152 | 153 | /** 154 | * @return the headers of this record 155 | */ 156 | @CacheReturn 157 | List headers(); 158 | 159 | /** 160 | * @return a created native Kafka producer record with backed information 161 | */ 162 | @GenIgnore 163 | ProducerRecord record(); 164 | 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/producer/RecordMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.producer; 18 | 19 | import io.vertx.codegen.annotations.DataObject; 20 | import io.vertx.core.json.JsonObject; 21 | 22 | /** 23 | * Metadata related to a Kafka record 24 | */ 25 | @DataObject 26 | public class RecordMetadata { 27 | 28 | private long offset; 29 | private int partition; 30 | private long timestamp; 31 | private String topic; 32 | 33 | /** 34 | * Constructor 35 | */ 36 | public RecordMetadata() { 37 | 38 | } 39 | 40 | /** 41 | * Constructor 42 | * 43 | * @param offset the offset of the record in the topic/partition. 44 | * @param partition the partition the record was sent to 45 | * @param timestamp the timestamp of the record in the topic/partition 46 | * @param topic the topic the record was appended to 47 | */ 48 | public RecordMetadata(long offset, int partition, long timestamp, String topic) { 49 | this.offset = offset; 50 | this.partition = partition; 51 | this.timestamp = timestamp; 52 | this.topic = topic; 53 | } 54 | 55 | /** 56 | * Constructor (from JSON representation) 57 | * 58 | * @param json JSON representation 59 | */ 60 | public RecordMetadata(JsonObject json) { 61 | this.offset = json.getLong("offset"); 62 | this.partition = json.getInteger("partition"); 63 | this.timestamp = json.getLong("timestamp"); 64 | this.topic = json.getString("topic"); 65 | } 66 | 67 | /** 68 | * @return the offset of the record in the topic/partition. 69 | */ 70 | public long getOffset() { 71 | return this.offset; 72 | } 73 | 74 | /** 75 | * Set the offset of the record in the topic/partition. 76 | * 77 | * @param offset offset of the record in the topic/partition 78 | * @return current instance of the class to be fluent 79 | */ 80 | public RecordMetadata setOffset(long offset) { 81 | this.offset = offset; 82 | return this; 83 | } 84 | 85 | /** 86 | * @return the partition the record was sent to 87 | */ 88 | public int getPartition() { 89 | return this.partition; 90 | } 91 | 92 | /** 93 | * Set the partition the record was sent to 94 | * 95 | * @param partition the partition the record was sent to 96 | * @return current instance of the class to be fluent 97 | */ 98 | public RecordMetadata setPartition(int partition) { 99 | this.partition = partition; 100 | return this; 101 | } 102 | 103 | /** 104 | * @return the timestamp of the record in the topic/partition 105 | */ 106 | public long getTimestamp() { 107 | return this.timestamp; 108 | } 109 | 110 | /** 111 | * Set the timestamp of the record in the topic/partition 112 | * 113 | * @param timestamp the timestamp of the record in the topic/partition 114 | * @return current instance of the class to be fluent 115 | */ 116 | public RecordMetadata setTimestamp(long timestamp) { 117 | this.timestamp = timestamp; 118 | return this; 119 | } 120 | 121 | /** 122 | * @return the topic the record was appended to 123 | */ 124 | public String getTopic() { 125 | return this.topic; 126 | } 127 | 128 | /** 129 | * Set the topic the record was appended to 130 | * 131 | * @param topic the topic the record was appended to 132 | * @return current instance of the class to be fluent 133 | */ 134 | public RecordMetadata setTopic(String topic) { 135 | this.topic = topic; 136 | return this; 137 | } 138 | 139 | /** 140 | * Convert object to JSON representation 141 | * 142 | * @return JSON representation 143 | */ 144 | public JsonObject toJson() { 145 | JsonObject jsonObject = new JsonObject(); 146 | 147 | jsonObject 148 | .put("offset", this.offset) 149 | .put("partition", this.partition) 150 | .put("timestamp", this.timestamp) 151 | .put("topic", this.topic); 152 | 153 | return jsonObject; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/producer/impl/KafkaHeaderImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.producer.impl; 18 | 19 | import io.vertx.core.buffer.Buffer; 20 | import io.vertx.kafka.client.producer.KafkaHeader; 21 | 22 | import java.util.Objects; 23 | 24 | /** 25 | * Vert.x Kafka producer record header implementation 26 | */ 27 | public class KafkaHeaderImpl implements KafkaHeader { 28 | 29 | private String key; 30 | private Buffer value; 31 | 32 | public KafkaHeaderImpl(String key, Buffer value) { 33 | this.key = key; 34 | this.value = value; 35 | } 36 | 37 | public KafkaHeaderImpl(String key, String value) { 38 | this(key, Buffer.buffer(value)); 39 | } 40 | 41 | @Override 42 | public String key() { 43 | return key; 44 | } 45 | 46 | @Override 47 | public Buffer value() { 48 | return value; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (o == null || getClass() != o.getClass()) return false; 55 | KafkaHeaderImpl that = (KafkaHeaderImpl) o; 56 | return Objects.equals(key, that.key) && Objects.equals(value, that.value); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(key, value); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "KafkaHeaderImpl{'" + key + "': " + value + '}'; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/BufferDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.buffer.Buffer; 20 | import org.apache.kafka.common.serialization.Deserializer; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Kafka deserializer for raw bytes in a buffer 26 | */ 27 | public class BufferDeserializer implements Deserializer { 28 | 29 | @Override 30 | public void configure(Map configs, boolean isKey) { 31 | } 32 | 33 | @Override 34 | public Buffer deserialize(String topic, byte[] data) { 35 | if (data == null) 36 | return null; 37 | 38 | return Buffer.buffer(data); 39 | } 40 | 41 | @Override 42 | public void close() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/BufferSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.buffer.Buffer; 20 | import org.apache.kafka.common.serialization.Serializer; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Kafka serializer for raw bytes in a buffer 26 | */ 27 | public class BufferSerializer implements Serializer { 28 | 29 | @Override 30 | public void configure(Map configs, boolean isKey) { 31 | } 32 | 33 | @Override 34 | public byte[] serialize(String topic, Buffer data) { 35 | if (data == null) 36 | return null; 37 | 38 | return data.getBytes(); 39 | } 40 | 41 | @Override 42 | public void close() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/JsonArrayDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.buffer.Buffer; 20 | import io.vertx.core.json.JsonArray; 21 | import org.apache.kafka.common.serialization.Deserializer; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * Kafka deserializer for raw bytes in a buffer 27 | */ 28 | public class JsonArrayDeserializer implements Deserializer { 29 | 30 | @Override 31 | public void configure(Map configs, boolean isKey) { 32 | } 33 | 34 | @Override 35 | public JsonArray deserialize(String topic, byte[] data) { 36 | if (data == null) 37 | return null; 38 | 39 | return Buffer.buffer(data).toJsonArray(); 40 | } 41 | 42 | @Override 43 | public void close() { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/JsonArraySerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.json.JsonArray; 20 | import org.apache.kafka.common.serialization.Serializer; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Kafka serializer for raw bytes in a buffer 26 | */ 27 | public class JsonArraySerializer implements Serializer { 28 | 29 | @Override 30 | public void configure(Map configs, boolean isKey) { 31 | } 32 | 33 | @Override 34 | public byte[] serialize(String topic, JsonArray data) { 35 | if (data == null) 36 | return null; 37 | 38 | return data.encode().getBytes(); 39 | } 40 | 41 | @Override 42 | public void close() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/JsonObjectDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.buffer.Buffer; 20 | import io.vertx.core.json.JsonObject; 21 | import org.apache.kafka.common.serialization.Deserializer; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * Kafka deserializer for raw bytes in a buffer 27 | */ 28 | public class JsonObjectDeserializer implements Deserializer { 29 | 30 | @Override 31 | public void configure(Map configs, boolean isKey) { 32 | } 33 | 34 | @Override 35 | public JsonObject deserialize(String topic, byte[] data) { 36 | if (data == null) 37 | return null; 38 | 39 | return Buffer.buffer(data).toJsonObject(); 40 | } 41 | 42 | @Override 43 | public void close() { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/JsonObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.serialization; 18 | 19 | import io.vertx.core.json.JsonObject; 20 | import org.apache.kafka.common.serialization.Serializer; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Kafka serializer for raw bytes in a buffer 26 | */ 27 | public class JsonObjectSerializer implements Serializer { 28 | 29 | @Override 30 | public void configure(Map configs, boolean isKey) { 31 | } 32 | 33 | @Override 34 | public byte[] serialize(String topic, JsonObject data) { 35 | if (data == null) 36 | return null; 37 | 38 | return data.encode().getBytes(); 39 | } 40 | 41 | @Override 42 | public void close() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/vertx/kafka/client/serialization/VertxSerdes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.vertx.kafka.client.serialization; 17 | 18 | import io.vertx.core.buffer.Buffer; 19 | import io.vertx.core.json.JsonArray; 20 | import io.vertx.core.json.JsonObject; 21 | import org.apache.kafka.common.serialization.Serde; 22 | import org.apache.kafka.common.serialization.Serdes; 23 | 24 | /** 25 | * @author Matthias Wessendorf 26 | */ 27 | public class VertxSerdes extends Serdes { 28 | 29 | static public Serde Buffer() { 30 | return new BufferSerde(); 31 | } 32 | 33 | static public Serde JsonArray() { 34 | return new JsonArraySerde(); 35 | } 36 | 37 | static public Serde JsonObject() { 38 | return new JsonObjectSerde(); 39 | } 40 | 41 | 42 | static public final class BufferSerde extends WrapperSerde { 43 | public BufferSerde() { 44 | super(new BufferSerializer(), new BufferDeserializer()); 45 | } 46 | } 47 | 48 | static public final class JsonArraySerde extends WrapperSerde { 49 | public JsonArraySerde() { 50 | super(new JsonArraySerializer(), new JsonArrayDeserializer()); 51 | } 52 | } 53 | 54 | static public final class JsonObjectSerde extends WrapperSerde { 55 | public JsonObjectSerde() { 56 | super(new JsonObjectSerializer(), new JsonObjectDeserializer()); 57 | } 58 | } 59 | 60 | static public Serde serdeFrom(Class type) { 61 | if (Buffer.class.isAssignableFrom(type)) { 62 | return (Serde) Buffer(); 63 | } 64 | 65 | if (JsonArray.class.isAssignableFrom(type)) { 66 | return (Serde) JsonArray(); 67 | } 68 | 69 | if (JsonObject.class.isAssignableFrom(type)) { 70 | return (Serde) JsonObject(); 71 | } 72 | 73 | // delegate to look up default Kafka SerDes: 74 | return Serdes.serdeFrom(type); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/AdminClientConfigEntryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import java.io.IOException; 20 | import java.util.Collections; 21 | import java.util.Properties; 22 | 23 | import org.apache.kafka.clients.admin.AdminClientConfig; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.BeforeClass; 27 | import org.junit.Test; 28 | 29 | import io.vertx.core.Vertx; 30 | import io.vertx.ext.unit.TestContext; 31 | import io.vertx.kafka.admin.ConfigEntry; 32 | import io.vertx.kafka.admin.KafkaAdminClient; 33 | import io.vertx.kafka.admin.NewTopic; 34 | import io.vertx.kafka.client.common.ConfigResource; 35 | 36 | public class AdminClientConfigEntryTest extends KafkaClusterTestBase { 37 | private static final String MIN_INSYNC_REPLICAS = "min.insync.replicas"; 38 | private Vertx vertx; 39 | private Properties config; 40 | 41 | @Before 42 | public void beforeTest() { 43 | this.vertx = Vertx.vertx(); 44 | this.config = new Properties(); 45 | this.config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); 46 | } 47 | 48 | @After 49 | public void afterTest(TestContext ctx) { 50 | this.vertx.close().onComplete(ctx.asyncAssertSuccess()); 51 | } 52 | 53 | @BeforeClass 54 | public static void setUp() throws IOException { 55 | kafkaCluster = kafkaCluster(true).deleteDataPriorToStartup(true).addBrokers(2).startup(); 56 | } 57 | 58 | @Test 59 | public void testPropertiesOfEntryNotConfiguredExplicitly(TestContext ctx) { 60 | KafkaAdminClient adminClient = KafkaAdminClient.create(this.vertx, config); 61 | 62 | String topicName = "topic-default-min-isr"; 63 | NewTopic topic = new NewTopic(topicName, 1, (short)1); 64 | 65 | adminClient.createTopics(Collections.singletonList(topic)).onComplete(ctx.asyncAssertSuccess(v -> { 66 | 67 | ConfigResource topicResource = new ConfigResource(org.apache.kafka.common.config.ConfigResource.Type.TOPIC, topicName); 68 | adminClient.describeConfigs(Collections.singletonList(topicResource)).onComplete(ctx.asyncAssertSuccess(desc -> { 69 | 70 | ConfigEntry minISREntry = desc.get(topicResource) 71 | .getEntries() 72 | .stream() 73 | .filter(entry -> MIN_INSYNC_REPLICAS.equals(entry.getName())) 74 | .findFirst() 75 | .get(); 76 | 77 | ctx.assertTrue(minISREntry.isDefault()); 78 | ctx.assertEquals(minISREntry.getSource(), org.apache.kafka.clients.admin.ConfigEntry.ConfigSource.DEFAULT_CONFIG); 79 | 80 | adminClient.deleteTopics(Collections.singletonList(topicName)).onComplete(ctx.asyncAssertSuccess(r -> { 81 | adminClient.close(); 82 | })); 83 | })); 84 | })); 85 | } 86 | 87 | @Test 88 | public void testPropertiesOfEntryConfiguredExplicitly(TestContext ctx) { 89 | KafkaAdminClient adminClient = KafkaAdminClient.create(this.vertx, config); 90 | 91 | String topicName = "topic-custom-min-isr"; 92 | NewTopic topic = new NewTopic(topicName, 1, (short)1); 93 | topic.setConfig(Collections.singletonMap(MIN_INSYNC_REPLICAS, "1")); 94 | 95 | adminClient.createTopics(Collections.singletonList(topic)).onComplete(ctx.asyncAssertSuccess(v -> { 96 | 97 | ConfigResource topicResource = new ConfigResource(org.apache.kafka.common.config.ConfigResource.Type.TOPIC, topicName); 98 | adminClient.describeConfigs(Collections.singletonList(topicResource)).onComplete(ctx.asyncAssertSuccess(desc -> { 99 | 100 | ConfigEntry minISREntry = desc.get(topicResource) 101 | .getEntries() 102 | .stream() 103 | .filter(entry -> MIN_INSYNC_REPLICAS.equals(entry.getName())) 104 | .findFirst() 105 | .get(); 106 | 107 | ctx.assertFalse(minISREntry.isDefault()); 108 | ctx.assertEquals(minISREntry.getSource(), org.apache.kafka.clients.admin.ConfigEntry.ConfigSource.DYNAMIC_TOPIC_CONFIG); 109 | 110 | adminClient.deleteTopics(Collections.singletonList(topicName)).onComplete(ctx.asyncAssertSuccess(r -> { 111 | adminClient.close(); 112 | })); 113 | })); 114 | })); 115 | } 116 | 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/ConsumerFailedCloseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.Vertx; 20 | import io.vertx.kafka.client.common.KafkaClientOptions; 21 | import io.vertx.kafka.client.consumer.KafkaReadStream; 22 | import io.vertx.kafka.client.consumer.impl.KafkaReadStreamImpl; 23 | import org.apache.kafka.common.KafkaException; 24 | 25 | import java.time.Duration; 26 | import java.util.Properties; 27 | 28 | public class ConsumerFailedCloseTest extends ConsumerTestBase { 29 | 30 | @Override 31 | KafkaReadStream createConsumer(Vertx vertx, Properties config) { 32 | return new KafkaReadStreamImpl<>( 33 | vertx, 34 | new org.apache.kafka.clients.consumer.KafkaConsumer(config) { 35 | @Override 36 | public void close(final Duration timeout) { 37 | super.close(timeout); 38 | throw new KafkaException("failed to close consumer"); 39 | } 40 | }, 41 | KafkaClientOptions.fromProperties(config, false)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/ConsumerMockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.Vertx; 20 | import io.vertx.kafka.client.consumer.KafkaReadStream; 21 | import org.apache.kafka.clients.consumer.Consumer; 22 | 23 | /** 24 | * Tests using mock consumer 25 | */ 26 | public class ConsumerMockTest extends ConsumerMockTestBase { 27 | 28 | @Override 29 | KafkaReadStream createConsumer(Vertx vertx, Consumer consumer) { 30 | return KafkaReadStream.create(vertx, consumer); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/ConsumerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.Vertx; 20 | import io.vertx.kafka.client.consumer.KafkaReadStream; 21 | 22 | import java.util.Properties; 23 | 24 | /** 25 | * Consumer tests 26 | */ 27 | public class ConsumerTest extends ConsumerTestBase { 28 | 29 | @Override 30 | KafkaReadStream createConsumer(Vertx vertx, Properties config) { 31 | return KafkaReadStream.create(vertx, config); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/EarliestNativeTest.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.tests; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerConfig; 4 | import org.apache.kafka.clients.consumer.ConsumerRecord; 5 | import org.apache.kafka.clients.consumer.ConsumerRecords; 6 | import org.apache.kafka.clients.consumer.KafkaConsumer; 7 | import org.apache.kafka.common.serialization.StringDeserializer; 8 | 9 | import java.time.Duration; 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class EarliestNativeTest { 15 | 16 | public static void main(String[] args) { 17 | 18 | Map config = new HashMap<>(); 19 | config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); 20 | config.put(ConsumerConfig.GROUP_ID_CONFIG, "my-group"); 21 | config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true"); 22 | config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); 23 | config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 24 | config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 25 | 26 | KafkaConsumer consumer = new KafkaConsumer(config); 27 | consumer.subscribe(Collections.singleton("my-topic")); 28 | 29 | while (true) { 30 | ConsumerRecords records = consumer.poll(Duration.ofMillis(1000)); 31 | for (ConsumerRecord record: records) { 32 | System.out.println(record); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/EarliestTest.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.tests; 2 | 3 | import io.vertx.core.AbstractVerticle; 4 | import io.vertx.core.Promise; 5 | import io.vertx.core.Vertx; 6 | import io.vertx.kafka.client.consumer.KafkaConsumer; 7 | import org.apache.kafka.clients.consumer.ConsumerConfig; 8 | import org.apache.kafka.common.serialization.StringDeserializer; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class EarliestTest extends AbstractVerticle { 14 | 15 | public static void main(String[] args) { 16 | 17 | Vertx vertx = Vertx.vertx(); 18 | 19 | EarliestTest earliestTest = new EarliestTest(); 20 | 21 | vertx.deployVerticle(earliestTest).onComplete(res -> { 22 | if (res.succeeded()) { 23 | System.out.println("ok"); 24 | } else { 25 | System.out.println("ko"); 26 | } 27 | }); 28 | 29 | 30 | } 31 | 32 | @Override 33 | public void start(Promise startFuture) throws Exception { 34 | 35 | Map config = new HashMap<>(); 36 | config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); 37 | config.put(ConsumerConfig.GROUP_ID_CONFIG, "my-group"); 38 | config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true"); 39 | config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); 40 | config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 41 | config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 42 | 43 | KafkaConsumer consumer = KafkaConsumer.create(vertx, config); 44 | consumer.handler(r -> { 45 | 46 | System.out.println(r); 47 | }); 48 | consumer.subscribe("my-topic"); 49 | 50 | startFuture.complete(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/KafkaClusterTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.debezium.kafka.KafkaCluster; 20 | import io.debezium.util.Testing; 21 | import io.vertx.ext.unit.junit.VertxUnitRunner; 22 | import org.junit.AfterClass; 23 | import org.junit.BeforeClass; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.util.Properties; 30 | 31 | /** 32 | * Base class for tests providing a Kafka cluster 33 | */ 34 | @RunWith(VertxUnitRunner.class) 35 | public abstract class KafkaClusterTestBase extends KafkaTestBase { 36 | 37 | protected static File dataDir; 38 | protected static KafkaCluster kafkaCluster; 39 | protected static boolean ACL = false; 40 | 41 | public static KafkaCluster kafkaCluster(boolean acl) { 42 | if (kafkaCluster != null) { 43 | throw new IllegalStateException(); 44 | } 45 | dataDir = Testing.Files.createTestingDirectory("cluster"); 46 | Properties kafkaProps = new Properties(); 47 | if (acl) { 48 | kafkaProps.put("authorizer.class.name", "kafka.security.authorizer.AclAuthorizer"); 49 | kafkaProps.put("super.users", "User:ANONYMOUS"); 50 | } 51 | kafkaCluster = new KafkaCluster().usingDirectory(dataDir).withPorts(2181, 9092).withKafkaConfiguration(kafkaProps); 52 | return kafkaCluster; 53 | } 54 | 55 | @BeforeClass 56 | public static void setUp() throws IOException { 57 | kafkaCluster = kafkaCluster(false).deleteDataPriorToStartup(true).addBrokers(2).startup(); 58 | } 59 | 60 | 61 | @AfterClass 62 | public static void tearDown() { 63 | if (kafkaCluster != null) { 64 | kafkaCluster.shutdown(); 65 | kafkaCluster = null; 66 | boolean delete = dataDir.delete(); 67 | // If files are still locked and a test fails: delete on exit to allow subsequent test execution 68 | if(!delete) { 69 | dataDir.deleteOnExit(); 70 | } 71 | } 72 | } 73 | 74 | @Test 75 | public void dummy() { 76 | // 'No runnable methods' is thrown without this 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/KafkaHeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.kafka.client.producer.KafkaHeader; 20 | import io.vertx.kafka.client.producer.KafkaProducerRecord; 21 | import org.junit.Test; 22 | 23 | import java.util.Arrays; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | import static org.junit.Assert.assertNotNull; 29 | 30 | public class KafkaHeaderTest { 31 | 32 | @Test 33 | public void testEmptyHeaders() { 34 | List kafkaHeaders = KafkaProducerRecord.create("topic", "key", "value").headers(); 35 | assertEquals(Collections.emptyList(), kafkaHeaders); 36 | } 37 | 38 | @Test 39 | public void testRecordWithHeaders() { 40 | List headers = Arrays.asList( 41 | KafkaHeader.header("key1", "value1"), 42 | KafkaHeader.header("key2", "value2") 43 | ); 44 | 45 | List recordHeaders = 46 | KafkaProducerRecord.create("mytopic", "mykey", "myvalue").addHeaders(headers).headers(); 47 | 48 | assertNotNull(recordHeaders); 49 | assertEquals(2, recordHeaders.size()); 50 | 51 | KafkaHeader kafkaHeader1 = recordHeaders.get(0); 52 | assertEquals("key1", kafkaHeader1.key()); 53 | assertEquals("value1", kafkaHeader1.value().toString()); 54 | 55 | KafkaHeader kafkaHeader2 = recordHeaders.get(1); 56 | assertEquals("key2", kafkaHeader2.key()); 57 | assertEquals("value2", kafkaHeader2.value().toString()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/KafkaReadStreamMockTest.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.tests; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedHashSet; 5 | import java.util.LinkedList; 6 | import java.util.Map; 7 | import java.util.Set; 8 | import java.util.concurrent.atomic.AtomicLong; 9 | 10 | import org.apache.kafka.clients.consumer.ConsumerRecord; 11 | import org.apache.kafka.clients.consumer.MockConsumer; 12 | import org.apache.kafka.clients.consumer.OffsetResetStrategy; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | 16 | import io.vertx.core.Vertx; 17 | import io.vertx.ext.unit.Async; 18 | import io.vertx.ext.unit.TestContext; 19 | import io.vertx.ext.unit.junit.VertxUnitRunner; 20 | import io.vertx.kafka.client.common.TopicPartition; 21 | import io.vertx.kafka.client.consumer.KafkaConsumer; 22 | import io.vertx.kafka.client.consumer.KafkaReadStream; 23 | import io.vertx.kafka.client.consumer.impl.KafkaConsumerImpl; 24 | 25 | @RunWith(VertxUnitRunner.class) 26 | public class KafkaReadStreamMockTest extends KafkaTestBase { 27 | 28 | private LinkedList> recordsMock = new LinkedList<>(); 29 | 30 | private int SEND_BATCH = 5; 31 | private int TOTAL_MESSAGES = 400; 32 | private final String TOPIC = "topic"; 33 | private Long timer = null; 34 | 35 | private void initRecords(){ 36 | int numMessages = TOTAL_MESSAGES; 37 | for (int i = 0;i < numMessages;i++) { 38 | String key = "key-" + i; 39 | String value = "value-" + i; 40 | recordsMock.add(new ConsumerRecord(TOPIC, 0, i, key, value)); 41 | } 42 | } 43 | 44 | private MockConsumer createMockConsumer(){ 45 | MockConsumer consumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST); 46 | 47 | Map beginningOffsets = new HashMap<>(); 48 | beginningOffsets.put(new org.apache.kafka.common.TopicPartition(TOPIC, 0), 0L); 49 | consumer.updateBeginningOffsets(beginningOffsets); 50 | return consumer; 51 | } 52 | 53 | private void sendNextBatch(MockConsumer consumer){ 54 | for(int i=0;i0;i++) 55 | consumer.addRecord(recordsMock.pop()); 56 | 57 | } 58 | 59 | @Test 60 | public void shouldNotLoseMessages(TestContext ctx){ 61 | Vertx vertx = Vertx.vertx(); 62 | 63 | Async done = ctx.async(); 64 | 65 | initRecords(); 66 | 67 | MockConsumer consumer = createMockConsumer(); 68 | KafkaReadStream readStream = KafkaReadStream.create(vertx, consumer); 69 | KafkaConsumer consumerVertx = new KafkaConsumerImpl<>(readStream); 70 | 71 | 72 | AtomicLong partitionOffset = new AtomicLong(-1); 73 | 74 | 75 | consumerVertx.handler((r)->{ 76 | long offset = r.offset(); 77 | 78 | partitionOffset.addAndGet(1); 79 | ctx.assertEquals(partitionOffset.get(), offset); 80 | 81 | if(offset == TOTAL_MESSAGES-1){ 82 | consumerVertx.close(); 83 | done.complete(); 84 | } else { 85 | 86 | if(timer!=null) vertx.cancelTimer(timer); 87 | timer = vertx.setTimer(5, (t)->{ 88 | consumerVertx.pause(); 89 | ctx.assertEquals(0L, consumerVertx.demand()); 90 | vertx.getOrCreateContext().runOnContext((t1)->{ 91 | consumerVertx.commit(); 92 | consumerVertx.resume(); 93 | ctx.assertEquals(Long.MAX_VALUE, consumerVertx.demand()); 94 | sendNextBatch(consumer); 95 | // sends two batches of messages 96 | vertx.getOrCreateContext().runOnContext((t2)->{ 97 | sendNextBatch(consumer); 98 | }); 99 | }); 100 | }); 101 | 102 | } 103 | 104 | }); 105 | 106 | consumerVertx.exceptionHandler(t->ctx.fail(t)); 107 | 108 | 109 | Set partitions = new LinkedHashSet<>(); 110 | partitions.add(new TopicPartition(TOPIC, 0)); 111 | 112 | consumerVertx.assign(partitions).onComplete((h)->{ 113 | sendNextBatch(consumer); 114 | }); 115 | 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/KafkaTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.AsyncResult; 20 | import io.vertx.core.Handler; 21 | import io.vertx.core.Vertx; 22 | import io.vertx.ext.unit.Async; 23 | import io.vertx.ext.unit.TestContext; 24 | import io.vertx.kafka.client.common.KafkaClientOptions; 25 | import io.vertx.kafka.client.consumer.KafkaReadStream; 26 | import io.vertx.kafka.client.producer.KafkaWriteStream; 27 | import org.apache.kafka.clients.producer.Producer; 28 | 29 | import java.util.HashMap; 30 | import java.util.Map; 31 | import java.util.Properties; 32 | import java.util.function.Consumer; 33 | 34 | /** 35 | * Base class for tests 36 | */ 37 | public class KafkaTestBase { 38 | 39 | static void close(TestContext ctx, Consumer>> producer) { 40 | if (producer != null) { 41 | Async closeAsync = ctx.async(); 42 | producer.accept(v -> { 43 | closeAsync.complete(); 44 | }); 45 | closeAsync.awaitSuccess(10000); 46 | } 47 | } 48 | 49 | public static void close(TestContext ctx, KafkaWriteStream producer) { 50 | if (producer != null) { 51 | close(ctx, handler -> producer.close(2000L).onComplete(handler)); 52 | } 53 | } 54 | 55 | public static void close(TestContext ctx, KafkaReadStream consumer) { 56 | if (consumer != null) { 57 | KafkaTestBase.close(ctx, asyncResultHandler -> consumer.close().onComplete(asyncResultHandler)); 58 | } 59 | } 60 | 61 | public static Map mapConfig(Properties cfg) { 62 | Map map = new HashMap<>(); 63 | cfg.forEach((k, v) -> map.put("" + k, v)); 64 | return map; 65 | } 66 | 67 | public static KafkaWriteStream producer(Vertx vertx, KafkaClientOptions opts) { 68 | return KafkaWriteStream.create(vertx, opts); 69 | } 70 | 71 | public static KafkaWriteStream producer(Vertx vertx, Properties config) { 72 | return KafkaWriteStream.create(vertx, config); 73 | } 74 | 75 | static KafkaWriteStream producer(Vertx vertx, Properties config, Class keyType, Class valueType) { 76 | return KafkaWriteStream.create(vertx, config, keyType, valueType); 77 | } 78 | 79 | static KafkaWriteStream producer(Vertx vertx, Producer producer) { 80 | return KafkaWriteStream.create(vertx, producer); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/NoClusterTest.java: -------------------------------------------------------------------------------- 1 | package io.vertx.kafka.client.tests; 2 | 3 | import io.vertx.core.Vertx; 4 | import io.vertx.ext.unit.Async; 5 | import io.vertx.ext.unit.TestContext; 6 | import io.vertx.ext.unit.junit.VertxUnitRunner; 7 | import io.vertx.kafka.client.producer.KafkaProducer; 8 | import org.apache.kafka.clients.producer.ProducerConfig; 9 | import org.apache.kafka.common.errors.TimeoutException; 10 | import org.apache.kafka.common.serialization.StringSerializer; 11 | import org.junit.After; 12 | import org.junit.Before; 13 | import org.junit.Test; 14 | import org.junit.runner.RunWith; 15 | 16 | import java.util.Properties; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | @RunWith(VertxUnitRunner.class) 20 | public class NoClusterTest { 21 | 22 | private Vertx vertx; 23 | 24 | @Before 25 | public void setUpVertx() { 26 | vertx = Vertx.vertx(); 27 | } 28 | 29 | @After 30 | public void tearDownVertx(TestContext ctx) { 31 | vertx.close() 32 | .onFailure(ctx::fail) 33 | .onComplete(ctx.asyncAssertSuccess()); 34 | vertx = null; 35 | } 36 | 37 | @Test 38 | public void partitionsForTimeoutMaxBlockMsHigh(TestContext ctx) { 39 | long maxBlockMs = 2_100; // > the arbitrary hardcoded timeout of 2s 40 | Properties props = new Properties() {{ 41 | put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:1234"); 42 | put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); 43 | put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); 44 | put(ProducerConfig.MAX_BLOCK_MS_CONFIG, maxBlockMs); // this should trigger the timeout 45 | }}; 46 | KafkaProducer producer = KafkaProducer.create(vertx, props); 47 | Async async = ctx.async(); 48 | producer.partitionsFor("doesnotexist") 49 | .onFailure(t -> { 50 | ctx.assertTrue(t instanceof TimeoutException); // used to fail, since the problem 51 | async.complete(); 52 | }); 53 | } 54 | 55 | @Test 56 | public void partitionsForTimeoutMaxBlockMsLow(TestContext ctx) { 57 | long maxBlockMs = 5; // < the arbitrary hardcoded timeout of 2s -> this test always worked, before the timer got removed 58 | Properties props = new Properties() {{ 59 | put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:1234"); 60 | put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); 61 | put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); 62 | put(ProducerConfig.MAX_BLOCK_MS_CONFIG, maxBlockMs); // this should trigger the timeout 63 | }}; 64 | KafkaProducer producer = KafkaProducer.create(vertx, props); 65 | Async async = ctx.async(); 66 | producer.partitionsFor("doesnotexist") 67 | .onFailure(t -> { 68 | ctx.assertTrue(t instanceof TimeoutException); 69 | async.complete(); 70 | }); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/ProducerConsumerContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.AbstractVerticle; 20 | import io.vertx.core.Context; 21 | import io.vertx.core.Vertx; 22 | import io.vertx.core.internal.ContextInternal; 23 | import io.vertx.ext.unit.Async; 24 | import io.vertx.ext.unit.TestContext; 25 | import io.vertx.kafka.client.consumer.KafkaReadStream; 26 | import io.vertx.kafka.client.producer.KafkaWriteStream; 27 | import org.apache.kafka.clients.consumer.ConsumerConfig; 28 | import org.apache.kafka.clients.producer.ProducerConfig; 29 | import org.apache.kafka.clients.producer.ProducerRecord; 30 | import org.apache.kafka.common.serialization.StringDeserializer; 31 | import org.apache.kafka.common.serialization.StringSerializer; 32 | import org.junit.After; 33 | import org.junit.Before; 34 | import org.junit.Test; 35 | 36 | import java.util.Collections; 37 | import java.util.Properties; 38 | 39 | /** 40 | * Producer tests 41 | */ 42 | public class ProducerConsumerContextTest extends KafkaClusterTestBase { 43 | 44 | private Vertx vertx; 45 | private KafkaWriteStream producer; 46 | private KafkaReadStream consumer; 47 | 48 | @Before 49 | public void beforeTest() { 50 | vertx = Vertx.vertx(); 51 | } 52 | 53 | @After 54 | public void afterTest(TestContext ctx) { 55 | close(ctx, producer); 56 | vertx.close().onComplete(ctx.asyncAssertSuccess()); 57 | } 58 | 59 | @Test 60 | public void testStreamProducerConsumerContexts(TestContext ctx) throws Exception { 61 | String topicName = "testStreamProduceContexts"; 62 | Properties config = kafkaCluster.useTo().getProducerProperties("testStreamProduceContexts_producer"); 63 | config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 64 | config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 65 | config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); 66 | config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); 67 | config.put(ConsumerConfig.GROUP_ID_CONFIG, "testStreamProduceContexts_consumer"); 68 | config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); 69 | config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, Boolean.TRUE.toString()); 70 | config.put(ConsumerConfig.CLIENT_ID_CONFIG, "testStreamProduceContexts_client"); 71 | 72 | final int numMessages = 100; 73 | final Async async = ctx.async(numMessages * 2); 74 | 75 | vertx.deployVerticle(new AbstractVerticle() { 76 | @Override 77 | public void start() throws Exception { 78 | producer = producer(vertx, config); 79 | producer.exceptionHandler(ctx::fail); 80 | Context thisProducerCtx = context; 81 | vertx.deployVerticle(new AbstractVerticle() { 82 | @Override 83 | public void start() throws Exception { 84 | for (int i = 0; i < numMessages; i++) { 85 | ProducerRecord record = new ProducerRecord<>(topicName, 0, "key-" + i, "value-" + i); 86 | record.headers().add("header_key", ("header_value-" + i).getBytes()); 87 | producer.write(record).onComplete(h -> { 88 | ctx.assertEquals(context, Vertx.currentContext()); 89 | ctx.assertNotEquals(thisProducerCtx, Vertx.currentContext()); 90 | async.countDown(); 91 | }); 92 | } 93 | } 94 | }); 95 | } 96 | }); 97 | 98 | vertx.deployVerticle(new AbstractVerticle() { 99 | @Override 100 | public void start() { 101 | consumer = KafkaReadStream.create(vertx, config); 102 | consumer.exceptionHandler(ctx::fail); 103 | Context thisConsumerCtx = context; 104 | 105 | vertx.deployVerticle(new AbstractVerticle() { 106 | @Override 107 | public void start() { 108 | consumer.handler(record -> { 109 | ctx.assertNotEquals(thisConsumerCtx, Vertx.currentContext()); 110 | ctx.assertEquals(thisConsumerCtx, ((ContextInternal) Vertx.currentContext()).unwrap()); 111 | ctx.assertNotEquals(context, Vertx.currentContext()); 112 | async.countDown(); 113 | }); 114 | consumer.subscribe(Collections.singleton(topicName)); 115 | consumer.resume(); 116 | } 117 | }); 118 | } 119 | }); 120 | async.await(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/test/java/io/vertx/kafka/client/tests/TopicPartitionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Red Hat Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.vertx.kafka.client.tests; 18 | 19 | import io.vertx.core.json.JsonObject; 20 | import io.vertx.ext.unit.TestContext; 21 | import io.vertx.ext.unit.junit.VertxUnitRunner; 22 | import io.vertx.kafka.client.common.TopicPartition; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | 26 | @RunWith(VertxUnitRunner.class) 27 | public class TopicPartitionTest { 28 | 29 | @Test 30 | public void testEquality(final TestContext context) { 31 | final TopicPartition t1 = new TopicPartition("topic1", 0); 32 | final TopicPartition t2 = new TopicPartition("topic1", 0); 33 | final TopicPartition t3 = new TopicPartition(null, 0); 34 | final TopicPartition t4 = new TopicPartition(null, 0); 35 | 36 | context.assertEquals(t1, t1); 37 | context.assertEquals(t1.hashCode(), t1.hashCode()); 38 | 39 | context.assertEquals(t1, t2); 40 | context.assertEquals(t1.hashCode(), t2.hashCode()); 41 | 42 | context.assertEquals(t3, t4); 43 | context.assertEquals(t3.hashCode(), t4.hashCode()); 44 | } 45 | 46 | @Test 47 | public void testUnequality(final TestContext context) { 48 | final TopicPartition t1 = new TopicPartition("topic1", 0); 49 | final TopicPartition t2 = new TopicPartition("topic1", 1); 50 | final TopicPartition t3 = new TopicPartition("topic2", 0); 51 | final TopicPartition t4 = new TopicPartition("topic2", 1); 52 | final JsonObject t5 = new JsonObject(); 53 | 54 | context.assertNotEquals(t1, t2); 55 | context.assertNotEquals(t1.hashCode(), t2.hashCode()); 56 | 57 | context.assertNotEquals(t3, t4); 58 | context.assertNotEquals(t3.hashCode(), t4.hashCode()); 59 | 60 | context.assertNotEquals(t3, t5); 61 | context.assertNotEquals(t3.hashCode(), t5.hashCode()); 62 | 63 | context.assertFalse(t1.equals(null)); 64 | context.assertFalse(t1.equals(t5)); 65 | } 66 | } 67 | --------------------------------------------------------------------------------