Skip to content

Commit

Permalink
feat: Update: 1.class version to 3.7.0.1.0; 2.component builders add …
Browse files Browse the repository at this point in the history
…parameter value check.

Signed-off-by: photowey <[email protected]>
  • Loading branch information
photowey committed Apr 13, 2024
1 parent 5d7a1b8 commit a98c803
Show file tree
Hide file tree
Showing 47 changed files with 197 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
@Import(value = {
KafkaEngineSpringAwareBeanPostProcessor.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public interface BeanFactoryGetter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* {@code KafkaPlusProperties}
*
* @author photowey
* @version 1.0.0
* @version 3.7.0.1.0
* @since 2024/04/06
*/
public class KafkaPlusProperties implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public class SpringKafkaEngineImpl implements KafkaEngine, BeanFactoryAware, BeanFactoryGetter, SmartInitializingSingleton {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public abstract class AbstractEngineAwareBeanPostProcessor<E extends Engine, A extends Aware> implements EngineBeanPostProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public interface EngineBeanPostProcessor extends BeanPostProcessor, BeanFactoryPostProcessor {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public interface KafkaEngineSpringAware extends KafkaEngineAware, Aware {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author photowey
* @since 2024/04/06
* @version 1.0.0
* @version 3.7.0.1.0
*/
public class KafkaEngineSpringAwareBeanPostProcessor extends AbstractEngineAwareBeanPostProcessor<KafkaEngine, KafkaEngineSpringAware> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.photowey.kafka.plus.core.checker;

import io.github.photowey.kafka.plus.core.exception.KafkaPlusRuntimeException;

import java.util.Objects;

/**
* {@code ConfigChecker}
*
* @author photowey
* @version 3.7.0.1.4
* @since 2024/04/14
*/
public final class ConfigChecker {

private ConfigChecker() {}

/**
* check not blank
*
* @param key the key
* @param object the object
*/
public static void checkNotBlank(String key, String object) {
if (Objects.isNull(object) || object.isEmpty()) {
throw new KafkaPlusRuntimeException("%s can't be null/empty", key);
}
}

public static <T> void checkNotNull(String key, T object) {
if (Objects.isNull(object)) {
throw new KafkaPlusRuntimeException("%s can't be null/empty", key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author photowey
* @since 2024/04/05
* @version 1.0.0
* @version 3.7.0.1.0
*/
public abstract class AbstractBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
* {@code AdminBuilder}
*
* @author photowey
* @version 3.7.0.1.0
* @since 2024/04/05
* @version 1.0.0
*/
public interface AdminBuilder {

/**
* The {@code bootstrap.servers}.
*
* @param bootstrapServers the bootstrap.servers
* @param bootstrapServers the {@code bootstrap.servers}.
* @return {@link AdminBuilder}
*/
AdminBuilder boostrapServers(String bootstrapServers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Properties;
import java.util.function.Consumer;

import static io.github.photowey.kafka.plus.core.checker.ConfigChecker.checkNotBlank;
import static io.github.photowey.kafka.plus.core.checker.ConfigChecker.checkNotNull;

/**
* {@code AdminBuilderImpl}
* <p>
Expand Down Expand Up @@ -51,13 +54,14 @@
* </pre>
*
* @author photowey
* @version 3.7.0.1.0
* @since 2024/04/05
* @version 1.0.0
*/
public class AdminBuilderImpl extends AbstractBuilder implements AdminBuilder {

@Override
public AdminBuilder boostrapServers(String bootstrapServers) {
checkNotBlank("bootstrap.servers", bootstrapServers);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Bootstrap.Server.ADDRESS.value(), bootstrapServers);

Expand All @@ -68,13 +72,15 @@ public AdminBuilder boostrapServers(String bootstrapServers) {

@Override
public AdminBuilder props(Properties props) {
checkNotNull("props", props);
super.props = props;

return this;
}

@Override
public AdminBuilder configs(Map<String, Object> configs) {
checkNotNull("configs", configs);
super.configs = configs;

return this;
Expand All @@ -84,13 +90,15 @@ public AdminBuilder configs(Map<String, Object> configs) {

@Override
public AdminBuilder checkProps(Consumer<Properties> fx) {
checkNotNull("checkProps.fx", fx);
fx.accept(super.props);

return this;
}

@Override
public AdminBuilder checkConfigs(Consumer<Map<String, Object>> fx) {
checkNotNull("checkConfigs.fx", fx);
fx.accept(super.configs);

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author photowey
* @since 2024/04/05
* @version 1.0.0
* @version 3.7.0.1.0
*/
public interface NewTopicBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author photowey
* @since 2024/04/05
* @version 1.0.0
* @version 3.7.0.1.0
*/
public class NewTopicBuilderImpl implements NewTopicBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
* {@code ConsumerBuilder}
*
* @author photowey
* @version 1.0.0
* @version 3.7.0.1.0
* @since 2024/04/05
*/
public interface ConsumerBuilder {

/**
* The {@code bootstrap.servers}.
*
* @param bootstrapServers the bootstrap.servers
* @param bootstrapServers the {@code bootstrap.servers}.
* @return {@link ConsumerBuilder}
*/
ConsumerBuilder boostrapServers(String bootstrapServers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
import java.util.Properties;
import java.util.function.Consumer;

import static io.github.photowey.kafka.plus.core.checker.ConfigChecker.checkNotBlank;
import static io.github.photowey.kafka.plus.core.checker.ConfigChecker.checkNotNull;

/**
* {@code ConsumerBuilderImpl}
*
* @author photowey
* @version 1.0.0
* @version 3.7.0.1.0
* @since 2024/04/05
*/
public class ConsumerBuilderImpl extends AbstractBuilder implements ConsumerBuilder {
Expand All @@ -41,6 +44,7 @@ public class ConsumerBuilderImpl extends AbstractBuilder implements ConsumerBuil

@Override
public ConsumerBuilder boostrapServers(String bootstrapServers) {
checkNotBlank("bootstrap.servers", bootstrapServers);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Bootstrap.Server.ADDRESS.value(), bootstrapServers);

Expand All @@ -49,6 +53,7 @@ public ConsumerBuilder boostrapServers(String bootstrapServers) {

@Override
public ConsumerBuilder keyDeserializer(String keyDeserializer) {
checkNotBlank("keyDeserializer", keyDeserializer);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.KEY_DESERIALIZER.key(), keyDeserializer);

Expand All @@ -57,6 +62,7 @@ public ConsumerBuilder keyDeserializer(String keyDeserializer) {

@Override
public ConsumerBuilder valueDeserializer(String valueDeserializer) {
checkNotBlank("valueDeserializer", valueDeserializer);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.VALUE_DESERIALIZER.key(), valueDeserializer);

Expand All @@ -65,6 +71,7 @@ public ConsumerBuilder valueDeserializer(String valueDeserializer) {

@Override
public ConsumerBuilder autoOffsetReset(Kafka.Consumer.AutoOffsetReset offsetReset) {
checkNotNull("offsetReset", offsetReset);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.AUTO_OFFSET_RESET.key(), offsetReset.value());

Expand All @@ -73,6 +80,7 @@ public ConsumerBuilder autoOffsetReset(Kafka.Consumer.AutoOffsetReset offsetRese

@Override
public ConsumerBuilder groupId(String groupId) {
checkNotBlank("groupId", groupId);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.GROUP_ID.key(), groupId);

Expand All @@ -83,6 +91,7 @@ public ConsumerBuilder groupId(String groupId) {

@Override
public ConsumerBuilder isolation(Kafka.Consumer.Isolation isolation) {
checkNotNull("isolation.level", isolation);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.ISOLATION_LEVEL.key(), isolation.value());

Expand All @@ -91,6 +100,7 @@ public ConsumerBuilder isolation(Kafka.Consumer.Isolation isolation) {

@Override
public ConsumerBuilder instanceId(String instanceId) {
checkNotBlank("instanceId", instanceId);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.GROUP_INSTANCE_ID.key(), instanceId);

Expand All @@ -99,6 +109,7 @@ public ConsumerBuilder instanceId(String instanceId) {

@Override
public ConsumerBuilder strategy(String strategy) {
checkNotBlank("partition.assignment.strategy", strategy);
super.initConfigsIfNecessary();
super.configs.put(Kafka.Consumer.PARTITION_ASSIGNMENT_STRATEGY.key(), strategy);

Expand All @@ -119,13 +130,15 @@ public ConsumerBuilder autoCommit(boolean enabled) {

@Override
public <K> ConsumerBuilder keyDeserializer(Deserializer<K> keyDeserializer) {
checkNotNull("keyDeserializer", keyDeserializer);
this.keyDeserializer = keyDeserializer;

return this;
}

@Override
public <V> ConsumerBuilder valueDeserializer(Deserializer<V> valueDeserializer) {
checkNotNull("valueDeserializer", valueDeserializer);
this.valueDeserializer = valueDeserializer;

return this;
Expand All @@ -135,13 +148,15 @@ public <V> ConsumerBuilder valueDeserializer(Deserializer<V> valueDeserializer)

@Override
public ConsumerBuilder props(Properties props) {
checkNotNull("props", props);
super.props = props;

return this;
}

@Override
public ConsumerBuilder configs(Map<String, Object> configs) {
checkNotNull("configs", configs);
super.configs = configs;

return this;
Expand All @@ -151,13 +166,15 @@ public ConsumerBuilder configs(Map<String, Object> configs) {

@Override
public ConsumerBuilder checkProps(Consumer<Properties> fx) {
checkNotNull("checkProps.fx", fx);
fx.accept(super.props);

return this;
}

@Override
public ConsumerBuilder checkConfigs(Consumer<Map<String, Object>> fx) {
checkNotNull("checkConfigs.fx", fx);
fx.accept(super.configs);

return this;
Expand All @@ -167,6 +184,7 @@ public ConsumerBuilder checkConfigs(Consumer<Map<String, Object>> fx) {

@Override
public ConsumerBuilder subscribe(Collection<String> topics) {
checkNotNull("subscribe.topics", topics);
this.topics = topics;

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
* {@code ProducerBuilder}
*
* @author photowey
* @version 3.7.0.1.0
* @since 2024/04/05
* @version 1.0.0
*/
public interface ProducerBuilder {

/**
* The {@code bootstrap.servers}.
*
* @param bootstrapServers the bootstrap.servers
* @param bootstrapServers the {@code bootstrap.servers}.
* @return {@link ProducerBuilder}
*/
ProducerBuilder boostrapServers(String bootstrapServers);
Expand Down
Loading

0 comments on commit a98c803

Please sign in to comment.