-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
h1alexbel
committed
May 4, 2023
1 parent
d78f949
commit 5464d25
Showing
4 changed files
with
171 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/io/github/eocqrs/kafka/admin/CreateTopics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2022 Aliaksei Bialiauski, EO-CQRS | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.github.eocqrs.kafka.admin; | ||
|
||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
import org.apache.kafka.common.KafkaFuture; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.list.ListOf; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Create topics. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.1.3 | ||
*/ | ||
public final class CreateTopics implements Scalar<KafkaFuture<Void>> { | ||
|
||
/** | ||
* Admin. | ||
*/ | ||
private final AdminClient admin; | ||
/** | ||
* Topics to create. | ||
*/ | ||
private final List<NewTopic> topics; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param admn Kafka Admin | ||
* @param tpcs Topics to create | ||
* @see AdminClient | ||
* @see NewTopic | ||
*/ | ||
public CreateTopics(final AdminClient admn, final NewTopic... tpcs) { | ||
this.admin = admn; | ||
this.topics = new ListOf<>(tpcs); | ||
} | ||
|
||
@Override | ||
public KafkaFuture<Void> value() throws Exception { | ||
return this.admin.createTopics(this.topics) | ||
.all(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/io/github/eocqrs/kafka/admin/ListTopics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2022 Aliaksei Bialiauski, EO-CQRS | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.github.eocqrs.kafka.admin; | ||
|
||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.cactoos.Scalar; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* List all topics. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.1.3 | ||
*/ | ||
public final class ListTopics implements Scalar<List<String>> { | ||
|
||
/** | ||
* Admin. | ||
*/ | ||
private final AdminClient admin; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param admn Kafka Admin | ||
* @see AdminClient | ||
*/ | ||
public ListTopics(final AdminClient admn) { | ||
this.admin = admn; | ||
} | ||
|
||
@Override | ||
public List<String> value() throws Exception { | ||
return this.admin.listTopics() | ||
.listings() | ||
.get() | ||
.stream() | ||
.map(listing -> | ||
"id: %s, name: %s, internal: %s" | ||
.formatted( | ||
listing.topicId().toString(), | ||
listing.name(), | ||
listing.isInternal() | ||
) | ||
).toList(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/eocqrs/kafka/admin/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2022 Aliaksei Bialiauski, EO-CQRS | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Kafka Admin interactions. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.1.3 | ||
*/ | ||
package io.github.eocqrs.kafka.admin; |