-
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
Jun 2, 2023
1 parent
42f194c
commit ecb80d4
Showing
6 changed files
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
public interface Action { | ||
|
||
void apply(); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/eocqrs/kafka/ext/AssignPartitions.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,30 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.cactoos.list.ListOf; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
public final class AssignPartitions implements Action { | ||
|
||
private final KafkaConsumer<?, ?> consumer; | ||
private final Collection<TopicPartition> partitions; | ||
|
||
public AssignPartitions( | ||
final KafkaConsumer<?, ?> cnsmr, | ||
TopicPartition... prts | ||
) { | ||
this.consumer = cnsmr; | ||
this.partitions = new ListOf<>(prts); | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.assign(this.partitions); | ||
} | ||
} |
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,19 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class CommitAsync implements Action { | ||
|
||
private final KafkaConsumer<?, ?> consumer; | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.commitAsync(); | ||
} | ||
} |
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,19 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class CommitSync implements Action { | ||
|
||
private final KafkaConsumer<?, ?> consumer; | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.commitSync(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/github/eocqrs/kafka/ext/ShutdownHook.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,23 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class ShutdownHook implements Action { | ||
|
||
/** | ||
* Thread. | ||
*/ | ||
private final Thread thread; | ||
|
||
@Override | ||
public void apply() { | ||
Runtime.getRuntime().addShutdownHook( | ||
this.thread | ||
); | ||
} | ||
} |
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,19 @@ | ||
package io.github.eocqrs.kafka.ext; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class Wakeup implements Action { | ||
|
||
private final KafkaConsumer<?, ?> consumer; | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.wakeup(); | ||
} | ||
} |