From 23d5d366a2fefbe8120b7d7ec25bb75f0de47550 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Wed, 18 May 2022 21:07:27 +0800 Subject: [PATCH] Add springcloud stream kafka thread pool module --- hippo4j-adapter/hippo4j-adapter-kafka/pom.xml | 50 ++++++++++++++++++ .../adapter/kafka/KafkaThreadPoolAdapter.java | 52 +++++++++++++++++++ hippo4j-adapter/pom.xml | 1 + .../pom.xml | 50 ++++++++++++++++++ .../kafka/KafkaAdapterAutoConfiguration.java | 45 ++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + .../pom.xml | 1 + pom.xml | 6 +++ 8 files changed, 206 insertions(+) create mode 100644 hippo4j-adapter/hippo4j-adapter-kafka/pom.xml create mode 100644 hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java create mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/pom.xml create mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/KafkaAdapterAutoConfiguration.java create mode 100644 hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/resources/META-INF/spring.factories diff --git a/hippo4j-adapter/hippo4j-adapter-kafka/pom.xml b/hippo4j-adapter/hippo4j-adapter-kafka/pom.xml new file mode 100644 index 00000000..71f8f766 --- /dev/null +++ b/hippo4j-adapter/hippo4j-adapter-kafka/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-adapter + ${revision} + + hippo4j-adapter-kafka + + + + cn.hippo4j + hippo4j-adapter-base + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java new file mode 100644 index 00000000..e27ced8a --- /dev/null +++ b/hippo4j-adapter/hippo4j-adapter-kafka/src/main/java/cn/hippo4j/adapter/kafka/KafkaThreadPoolAdapter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cn.hippo4j.adapter.kafka; + +import cn.hippo4j.adapter.base.ThreadPoolAdapter; +import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; +import cn.hippo4j.adapter.base.ThreadPoolAdapterState; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.ApplicationListener; + +/** + * Kafka thread-pool adapter. + */ +@Slf4j +public class KafkaThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener { + + @Override + public String mark() { + return "Kafka"; + } + + @Override + public ThreadPoolAdapterState getThreadPoolState(String identify) { + return null; + } + + @Override + public boolean updateThreadPool(ThreadPoolAdapterParameter threadPoolAdapterParameter) { + return false; + } + + @Override + public void onApplicationEvent(ApplicationStartedEvent event) { + + } +} diff --git a/hippo4j-adapter/pom.xml b/hippo4j-adapter/pom.xml index 9d1c9d46..77d7159b 100644 --- a/hippo4j-adapter/pom.xml +++ b/hippo4j-adapter/pom.xml @@ -17,6 +17,7 @@ hippo4j-adapter-base hippo4j-adapter-dubbo + hippo4j-adapter-kafka hippo4j-adapter-rocketmq hippo4j-adapter-spring-cloud-stream-rocketmq diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/pom.xml b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/pom.xml new file mode 100644 index 00000000..7e249a93 --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + cn.hippo4j + hippo4j-spring-boot-starter-adapter + ${revision} + + hippo4j-spring-boot-starter-adapter-kafka + + + + cn.hippo4j + hippo4j-adapter-kafka + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${project.artifactId} + ${project.version} + ${maven.build.timestamp} + chen.ma + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + + + jar + + + + + + + diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/KafkaAdapterAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/KafkaAdapterAutoConfiguration.java new file mode 100644 index 00000000..b362f0b4 --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/KafkaAdapterAutoConfiguration.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 cn.hippo4j.springboot.starter.adapter.kafka; + +import cn.hippo4j.adapter.kafka.KafkaThreadPoolAdapter; +import cn.hippo4j.common.config.ApplicationContextHolder; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Kafka adapter auto configuration. + */ +@Configuration +public class KafkaAdapterAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public ApplicationContextHolder simpleApplicationContextHolder() { + return new ApplicationContextHolder(); + } + + @Bean + @SuppressWarnings("all") + @ConditionalOnProperty(name = "spring.kafka.bootstrap-servers") + public KafkaThreadPoolAdapter kafkaMQThreadPoolAdapter(ApplicationContextHolder applicationContextHolder) { + return new KafkaThreadPoolAdapter(); + } +} diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/resources/META-INF/spring.factories b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..592fba93 --- /dev/null +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/hippo4j-spring-boot-starter-adapter-kafka/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.hippo4j.springboot.starter.adapter.kafka.KafkaAdapterAutoConfiguration diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/pom.xml b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/pom.xml index 3fae0bdd..4559e5ef 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/pom.xml +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter-adapter/pom.xml @@ -15,6 +15,7 @@ hippo4j-spring-boot-starter-adapter-all hippo4j-spring-boot-starter-adapter-dubbo + hippo4j-spring-boot-starter-adapter-kafka hippo4j-spring-boot-starter-adapter-rocketmq hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq diff --git a/pom.xml b/pom.xml index 1dce2d7c..71569bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -158,6 +158,12 @@ ${revision} + + cn.hippo4j + hippo4j-adapter-kafka + ${revision} + + com.baomidou mybatis-plus-boot-starter