-
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
Showing
12 changed files
with
433 additions
and
20 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 @@ | ||
lombok.addLombokGeneratedAnnotation = true |
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/io/github/eocqrs/kafka/yaml/KfYamlConsumerSettings.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,48 @@ | ||
/* | ||
* 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.yaml; | ||
|
||
import io.github.eocqrs.kafka.ConsumerSettings; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
/** | ||
* Yaml configuration for consumer. | ||
* | ||
* @param <K> The key type. | ||
* @param <X> The value type. | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class KfYamlConsumerSettings<K, X> | ||
implements ConsumerSettings<K, X> { | ||
|
||
/** | ||
* YAML params. | ||
*/ | ||
private final YamlMapParams<K, X> params; | ||
|
||
@Override | ||
public KafkaConsumer<K, X> consumer() { | ||
return new KafkaConsumer<>(this.params.value()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/github/eocqrs/kafka/yaml/KfYamlProducerSettings.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,48 @@ | ||
/* | ||
* 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.yaml; | ||
|
||
import io.github.eocqrs.kafka.ProducerSettings; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
|
||
/** | ||
* Yaml configuration for producer. | ||
* | ||
* @param <K> The key type. | ||
* @param <X> The value type. | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class KfYamlProducerSettings<K, X> | ||
implements ProducerSettings<K, X> { | ||
|
||
/** | ||
* YAML params. | ||
*/ | ||
private final YamlMapParams<K, X> params; | ||
|
||
@Override | ||
public KafkaProducer<K, X> producer() { | ||
return new KafkaProducer<>(this.params.value()); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/main/java/io/github/eocqrs/kafka/yaml/YamlMapParams.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,92 @@ | ||
/* | ||
* 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.yaml; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.cactoos.Input; | ||
import org.cactoos.Scalar; | ||
import org.cactoos.io.ResourceOf; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.InputStream; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class converts a YAML source from | ||
* kebab case keys into kafka specific keys Map. | ||
* | ||
* @param <K> The key type. | ||
* @param <X> The value type. | ||
*/ | ||
@RequiredArgsConstructor | ||
public class YamlMapParams<K, X> implements Scalar<Map<String, Object>> { | ||
|
||
/** | ||
* The config value. | ||
*/ | ||
private final Map<String, Object> value; | ||
|
||
/** | ||
* Filename ctor. | ||
* | ||
* @param name Config name | ||
* @throws Exception When something went wrong | ||
*/ | ||
public YamlMapParams(final String name) throws Exception { | ||
this(new ResourceOf(name)); | ||
} | ||
|
||
/** | ||
* Input ctor. | ||
* | ||
* @param input Input source | ||
* @throws Exception When something went wrong | ||
*/ | ||
public YamlMapParams(final Input input) throws Exception { | ||
this(input.stream()); | ||
} | ||
|
||
/** | ||
* Primary ctor. | ||
* | ||
* @param stream Input source | ||
*/ | ||
public YamlMapParams(final InputStream stream) { | ||
this.value = new Yaml().load(stream); | ||
} | ||
|
||
@Override | ||
public final Map<String, Object> value() { | ||
final Map<String, Object> accum = new HashMap<>(0); | ||
this.value | ||
.forEach( | ||
(key, val) -> accum.put( | ||
key.replace('-', '.'), | ||
val | ||
) | ||
); | ||
return Collections.unmodifiableMap(accum); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/github/eocqrs/kafka/yaml/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,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* YAML. | ||
*/ | ||
package io.github.eocqrs.kafka.yaml; |
46 changes: 46 additions & 0 deletions
46
src/test/java/io/github/eocqrs/kafka/yaml/KfYamlConsumerSettingsTest.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,46 @@ | ||
/* | ||
* 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.yaml; | ||
|
||
import io.github.eocqrs.kafka.consumer.KfConsumer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
/** | ||
* Test case for {@link KfYamlProducerSettings}. | ||
*/ | ||
class KfYamlConsumerSettingsTest { | ||
|
||
@Test | ||
void createsConsumerFromYamlConfiguration() { | ||
assertDoesNotThrow( | ||
() -> | ||
new KfConsumer<>( | ||
new KfYamlConsumerSettings<>( | ||
new YamlMapParams<String, String>("consumer.yaml") | ||
) | ||
) | ||
); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/io/github/eocqrs/kafka/yaml/KfYamlProducerSettingsTest.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,47 @@ | ||
/* | ||
* 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.yaml; | ||
|
||
import io.github.eocqrs.kafka.producer.KfProducer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
/** | ||
* Test case for {@link KfYamlConsumerSettings}. | ||
*/ | ||
class KfYamlProducerSettingsTest { | ||
|
||
@Test | ||
void createsProducerFromYaml() { | ||
assertDoesNotThrow( | ||
() -> new KfProducer<>( | ||
new KfYamlProducerSettings<>( | ||
new YamlMapParams<String, String>( | ||
"producer.yaml" | ||
) | ||
) | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.