-
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 7, 2023
1 parent
ecb80d4
commit f172771
Showing
12 changed files
with
313 additions
and
120 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,37 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
/** | ||
* Kafka Action. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
public interface Action { | ||
|
||
/** | ||
* Apply action. | ||
*/ | ||
void apply(); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/io/github/eocqrs/kafka/act/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,79 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import org.apache.kafka.common.TopicPartition; | ||
import org.cactoos.list.ListOf; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Assign Partitions for Kafka Consumer. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
public final class AssignPartitions implements Action { | ||
|
||
/** | ||
* Consumer. | ||
*/ | ||
private final KafkaConsumer<?, ?> consumer; | ||
/** | ||
* Partitions to assign. | ||
*/ | ||
private final Collection<TopicPartition> partitions; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param cnsmr Kafka Consumer | ||
* @param prts Partitions to assign | ||
*/ | ||
public AssignPartitions( | ||
final KafkaConsumer<?, ?> cnsmr, | ||
final Collection<TopicPartition> prts | ||
) { | ||
this.consumer = cnsmr; | ||
this.partitions = prts; | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param cnsmr Kafka Consumer | ||
* @param prts Partitions to assign. | ||
*/ | ||
public AssignPartitions( | ||
final KafkaConsumer<?, ?> cnsmr, | ||
final TopicPartition... prts | ||
) { | ||
this(cnsmr, 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,46 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* Async Offset Commit. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class CommitAsync implements Action { | ||
|
||
/** | ||
* Consumer. | ||
*/ | ||
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,46 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* Sync Offset Commit. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class CommitSync implements Action { | ||
|
||
/** | ||
* Consumer. | ||
*/ | ||
private final KafkaConsumer<?, ?> consumer; | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.commitSync(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/io/github/eocqrs/kafka/act/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,58 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Shutdown Hook. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class ShutdownHook implements Action { | ||
|
||
/** | ||
* Action. | ||
*/ | ||
private final Action action; | ||
/** | ||
* Main thread. | ||
*/ | ||
private final Thread main; | ||
|
||
@Override | ||
public void apply() { | ||
Runtime.getRuntime().addShutdownHook( | ||
new Thread(() -> { | ||
this.action.apply(); | ||
try { | ||
this.main.join(); | ||
} catch (final InterruptedException ex) { | ||
ex.printStackTrace(); | ||
} | ||
}) | ||
); | ||
} | ||
} |
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,47 @@ | ||
/* | ||
* Copyright (c) 2023 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.act; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* Wakeup of Kafka Consumer. | ||
* | ||
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) | ||
* @see ShutdownHook | ||
* @since 0.2.5 | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class Wakeup implements Action { | ||
|
||
/** | ||
* Consumer. | ||
*/ | ||
private final KafkaConsumer<?, ?> consumer; | ||
|
||
@Override | ||
public void apply() { | ||
this.consumer.wakeup(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/io/github/eocqrs/kafka/ext/AssignPartitions.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.