mirror of https://github.com/longtai-cn/hippo4j
Feat: Agent mode Adapte SpringBoot 1.x , 2.x , 3.x And Adapte Nacos , Apollo Config-Center Agent Plugin (#1573)
* fix: Fixed jar package mounting and startup problem in Agent mode * Feat: Agent mode adapte SpringBoot 1.x 2.x 3.x And adapte Nacos、Apollo Config-Center * Fix: Fix build boot3.x moudle jdk17 project error * Fix: Fix build moudle error * Fix: Fix build moudle error * Fix: Fix build moudle error,Upgrade lombok dependency versions and add jaxb dependencies * Fix: Fix build moudle error,Upgrade maven.compiler.plugin version * Fix: Fix build moudle error,Upgrade lombok versionpull/1580/head
parent
a34539f28b
commit
b45ff94c40
@ -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.agent.plugin.spring.boot.v1.boot;
|
||||||
|
|
||||||
|
import cn.hippo4j.agent.core.boot.BootService;
|
||||||
|
import cn.hippo4j.agent.core.boot.DefaultImplementor;
|
||||||
|
import cn.hippo4j.common.logging.api.ILog;
|
||||||
|
import cn.hippo4j.common.logging.api.LogManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringBoot v1 plugin boot service
|
||||||
|
*/
|
||||||
|
@DefaultImplementor
|
||||||
|
public class SpringBootV1PluginBootService implements BootService {
|
||||||
|
|
||||||
|
private static final ILog LOGGER = LogManager.getLogger(SpringBootV1PluginBootService.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void boot() throws Throwable {
|
||||||
|
LOGGER.info("Loader SpringBootV1PluginBootService...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
12
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/ApplicationContextInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentationV1.java
12
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/ApplicationContextInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentationV1.java
17
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/ApplicationContextInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingRunListenerFinishedInterceptorV1.java
17
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/ApplicationContextInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingRunListenerFinishedInterceptorV1.java
@ -0,0 +1,17 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
cn.hippo4j.agent.plugin.spring.boot.v1.boot.SpringBootV1PluginBootService
|
25
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentationV2.java
25
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/define/EventPublishingRunListenerInstrumentationV2.java
8
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptorV2.java
8
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-2x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v2/interceptor/EventPublishingStartedInterceptorV2.java
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-agent-spring-plugins</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>hippo4j-agent-spring-boot-3x-plugin</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-boot.version>3.0.2</spring-boot.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-agent-spring-plugin-common</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -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.agent.plugin.spring.boot.v3.boot;
|
||||||
|
|
||||||
|
import cn.hippo4j.agent.core.boot.BootService;
|
||||||
|
import cn.hippo4j.agent.core.boot.DefaultImplementor;
|
||||||
|
import cn.hippo4j.common.logging.api.ILog;
|
||||||
|
import cn.hippo4j.common.logging.api.LogManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringBoot v3 plugin boot service
|
||||||
|
*/
|
||||||
|
@DefaultImplementor
|
||||||
|
public class SpringBootV3PluginBootService implements BootService {
|
||||||
|
|
||||||
|
private static final ILog LOGGER = LogManager.getLogger(SpringBootV3PluginBootService.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void boot() throws Throwable {
|
||||||
|
LOGGER.info("Loader SpringBootV3PluginBootService...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.agent.plugin.spring.boot.v3.define;
|
||||||
|
|
||||||
|
import cn.hippo4j.agent.core.plugin.WitnessMethod;
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.ConstructorInterceptPoint;
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||||
|
import cn.hippo4j.agent.core.plugin.match.ClassMatch;
|
||||||
|
import net.bytebuddy.description.method.MethodDescription;
|
||||||
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.hippo4j.agent.core.plugin.match.NameMatch.byName;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringBoot v3 Event publishing run listener instrumentation
|
||||||
|
*/
|
||||||
|
public class EventPublishingRunListenerInstrumentationV3 extends ClassInstanceMethodsEnhancePluginDefine {
|
||||||
|
|
||||||
|
private static final String ENHANCE_CLASS = "org.springframework.boot.context.event.EventPublishingRunListener";
|
||||||
|
|
||||||
|
private static final String EVENT_PUBLISHING_STARTED_INTERCEPTOR_V3 = "cn.hippo4j.agent.plugin.spring.boot.v3.interceptor.EventPublishingStartedInterceptorV3";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ClassMatch enhanceClass() {
|
||||||
|
return byName(ENHANCE_CLASS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||||
|
return new ConstructorInterceptPoint[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||||
|
return new InstanceMethodsInterceptPoint[]{
|
||||||
|
new InstanceMethodsInterceptPoint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||||
|
return named("ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethodsInterceptor() {
|
||||||
|
return EVENT_PUBLISHING_STARTED_INTERCEPTOR_V3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOverrideArgs() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<WitnessMethod> witnessMethods() {
|
||||||
|
return Collections.singletonList(new WitnessMethod("org.springframework.boot.context.event.EventPublishingRunListener",
|
||||||
|
named("ready")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] witnessClasses() {
|
||||||
|
return new String[]{"org.springframework.boot.context.properties.bind.ConstructorBinding"};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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.agent.plugin.spring.boot.v3.interceptor;
|
||||||
|
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||||
|
import cn.hippo4j.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||||
|
import cn.hippo4j.agent.plugin.spring.common.event.DynamicThreadPoolRefreshListener;
|
||||||
|
import cn.hippo4j.agent.plugin.spring.common.support.SpringPropertiesLoader;
|
||||||
|
import cn.hippo4j.agent.plugin.spring.common.support.SpringThreadPoolRegisterSupport;
|
||||||
|
import cn.hippo4j.common.extension.design.AbstractSubjectCenter;
|
||||||
|
import cn.hippo4j.common.logging.api.ILog;
|
||||||
|
import cn.hippo4j.common.logging.api.LogManager;
|
||||||
|
import cn.hippo4j.core.config.ApplicationContextHolder;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event publishing started interceptor
|
||||||
|
*/
|
||||||
|
public class EventPublishingStartedInterceptorV3 implements InstanceMethodsAroundInterceptor {
|
||||||
|
|
||||||
|
private static final AtomicBoolean isExecuted = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
private static final ILog LOGGER = LogManager.getLogger(EventPublishingStartedInterceptorV3.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||||
|
ConfigurableApplicationContext context = (ConfigurableApplicationContext) allArguments[0];
|
||||||
|
// This logic will only be executed once
|
||||||
|
if (isExecuted.compareAndSet(false, true)) {
|
||||||
|
ApplicationContextHolder contextHolder = new ApplicationContextHolder();
|
||||||
|
contextHolder.setApplicationContext(context);
|
||||||
|
// Load Spring Properties
|
||||||
|
SpringPropertiesLoader.loadSpringProperties(context.getEnvironment());
|
||||||
|
// the thread pool registration will be carried out
|
||||||
|
SpringThreadPoolRegisterSupport.registerThreadPoolInstances(context);
|
||||||
|
// register Dynamic ThreadPool Refresh Listener
|
||||||
|
if (AbstractSubjectCenter.get(AbstractSubjectCenter.SubjectType.THREAD_POOL_DYNAMIC_REFRESH) == null) {
|
||||||
|
AbstractSubjectCenter.register(AbstractSubjectCenter.SubjectType.THREAD_POOL_DYNAMIC_REFRESH, new DynamicThreadPoolRefreshListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
cn.hippo4j.agent.plugin.spring.boot.v3.boot.SpringBootV3PluginBootService
|
@ -0,0 +1,17 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
spring-boot-3.x=cn.hippo4j.agent.plugin.spring.boot.v3.define.EventPublishingRunListenerInstrumentationV3
|
@ -0,0 +1,92 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-threadpool-agent-example</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>hippo4j-threadpool-agent-config-apollo-spring-boot-3x</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
<spring-boot.version>3.0.2</spring-boot.version>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-agent-example-core</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ctrip.framework.apollo</groupId>
|
||||||
|
<artifactId>apollo-client</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-context</artifactId>
|
||||||
|
<version>4.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>3.3.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.example.agent.config.apollo.v3;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent config Apollo boot3 example application.
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.agent.config.apollo.v3")
|
||||||
|
public class AgentConfigApolloSpringBoot3xExampleApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AgentConfigApolloSpringBoot3xExampleApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.example.agent.config.apollo.v3;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
|
||||||
|
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test alarm send message.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AlarmSendMessageBootV3Test {
|
||||||
|
|
||||||
|
private static final int SLEEP_TIME = 10240124;
|
||||||
|
|
||||||
|
private static final int INITIAL_DELAY = 3;
|
||||||
|
|
||||||
|
private static final String RUN_MESSAGE_SEND_TASK_EXECUTOR = "runMessageSendTaskExecutor";
|
||||||
|
|
||||||
|
private static final String AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR = "cn.hippo4j.example.agent.config.apollo.v3.ThreadPoolConfigurationBootV3#AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test alarm notification.
|
||||||
|
* If you need to run this single test, add @PostConstruct to the method.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
// @PostConstruct
|
||||||
|
public void alarmSendMessageTest() {
|
||||||
|
ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
scheduledThreadPool.scheduleWithFixedDelay(() -> {
|
||||||
|
ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR);
|
||||||
|
ThreadPoolExecutor poolExecutor = executorHolder.getExecutor();
|
||||||
|
try {
|
||||||
|
poolExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Throw reject policy.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}, INITIAL_DELAY, 2, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
scheduledThreadPool.scheduleWithFixedDelay(() -> {
|
||||||
|
ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(RUN_MESSAGE_SEND_TASK_EXECUTOR);
|
||||||
|
ThreadPoolExecutor poolExecutor = executorHolder.getExecutor();
|
||||||
|
try {
|
||||||
|
poolExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Throw reject policy.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}, INITIAL_DELAY, 2, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
server.port=8092
|
||||||
|
server.servlet.context-path=/example
|
||||||
|
|
||||||
|
app.id=dynamic-threadpool-example-springboot3-test
|
||||||
|
apollo.meta=http://127.0.0.1:8080
|
||||||
|
apollo.autoUpdateInjectedSpringProperties=true
|
||||||
|
apollo.bootstrap.enabled=true
|
||||||
|
apollo.bootstrap.namespaces=application
|
||||||
|
apollo.bootstrap.eagerLoad.enabled=true
|
||||||
|
|
||||||
|
# The following parameters are used for testing
|
||||||
|
env=dev
|
||||||
|
apollo.configService=http://127.0.0.1:8080
|
||||||
|
spring.profiles.active=dev
|
||||||
|
spring.application.name=hippo4j-config-apollo-spring-boot-starter-example
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.enable=true
|
||||||
|
spring.dynamic.thread-pool.banner=true
|
||||||
|
spring.dynamic.thread-pool.check-state-interval=10
|
||||||
|
spring.dynamic.thread-pool.monitor.enable=true
|
||||||
|
spring.dynamic.thread-pool.monitor.collect-types=micrometer
|
||||||
|
spring.dynamic.thread-pool.monitor.thread-pool-types=dynamic
|
||||||
|
spring.dynamic.thread-pool.monitor.initial-delay=3000
|
||||||
|
spring.dynamic.thread-pool.monitor.collect-interval=3000
|
||||||
|
spring.dynamic.thread-pool.monitor.agent-micrometer-port=29999
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.notify-platforms[0].platform=LARK
|
||||||
|
spring.dynamic.thread-pool.notify-platforms[0].token=6de41bdc-0799-45be-b128-7cddb9e777f0
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[1].platform=WECHAT
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[1].token=ac0426a5-c712-474c-9bff-72b8b8f5caff
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[2].platform=DING
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[2].token=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.apollo.namespace=application
|
||||||
|
spring.dynamic.thread-pool.config-file-type=properties
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.executors[0].thread-name-prefix = DynamicThreadPoolConfig#FIELD1
|
||||||
|
spring.dynamic.thread-pool.executors[0].core-pool-size = 2
|
||||||
|
spring.dynamic.thread-pool.executors[0].thread-pool-id = cn.hippo4j.example.agent.config.apollo.v3.ThreadPoolConfigurationBootV3#AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR
|
||||||
|
spring.dynamic.thread-pool.executors[0].maximum-pool-size = 20
|
||||||
|
spring.dynamic.thread-pool.executors[0].queue-capacity = 1024
|
||||||
|
spring.dynamic.thread-pool.executors[0].blocking-queue = ResizableCapacityLinkedBlockingQueue
|
||||||
|
spring.dynamic.thread-pool.executors[0].execute-time-out = 800
|
||||||
|
spring.dynamic.thread-pool.executors[0].rejected-handler = AbortPolicy
|
||||||
|
spring.dynamic.thread-pool.executors[0].keep-alive-time = 6691
|
||||||
|
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true
|
||||||
|
spring.dynamic.thread-pool.executors[0].alarm = true
|
||||||
|
spring.dynamic.thread-pool.executors[0].active-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[0].capacity-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[0].notify.interval = 8
|
||||||
|
spring.dynamic.thread-pool.executors[0].notify.receives = nobodyiam
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.executors[1].thread-pool-id = runMessageSendTaskExecutor
|
||||||
|
spring.dynamic.thread-pool.executors[1].thread-name-prefix = runMessageSendTaskExecutor
|
||||||
|
spring.dynamic.thread-pool.executors[1].core-pool-size = 3
|
||||||
|
spring.dynamic.thread-pool.executors[1].maximum-pool-size = 4
|
||||||
|
spring.dynamic.thread-pool.executors[1].queue-capacity = 1024
|
||||||
|
spring.dynamic.thread-pool.executors[1].blocking-queue = ResizableCapacityLinkedBlockingQueue
|
||||||
|
spring.dynamic.thread-pool.executors[1].execute-time-out = 800
|
||||||
|
spring.dynamic.thread-pool.executors[1].rejected-handler = AbortPolicy
|
||||||
|
spring.dynamic.thread-pool.executors[1].keep-alive-time = 6691
|
||||||
|
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out = true
|
||||||
|
spring.dynamic.thread-pool.executors[1].active-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[1].capacity-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[1].notify.interval = 8
|
||||||
|
spring.dynamic.thread-pool.executors[1].notify.receives = nobodyiam
|
@ -0,0 +1,98 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-threadpool-agent-example</artifactId>
|
||||||
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>hippo4j-threadpool-agent-config-nacos-spring-boot-3x</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
|
<spring-boot.version>3.0.2</spring-boot.version>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hippo4j</groupId>
|
||||||
|
<artifactId>hippo4j-agent-example-core</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
<version>2022.0.0.0-RC2</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>com.alibaba.boot</groupId>
|
||||||
|
<artifactId>nacos-config-spring-boot-starter</artifactId>
|
||||||
|
<version>0.3.0-RC</version>
|
||||||
|
</dependency>-->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
<version>6.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>3.3.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.example.agent.config.nacos.v3;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent config Nacos boot3 example application.
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.agent.config.nacos.v3")
|
||||||
|
public class AgentConfigNacosSpringBoot3xExampleApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AgentConfigNacosSpringBoot3xExampleApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.example.agent.config.nacos.v3;
|
||||||
|
|
||||||
|
import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
|
||||||
|
import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test alarm send message.
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class AlarmSendMessageBootV3Test {
|
||||||
|
|
||||||
|
private static final int SLEEP_TIME = 10240124;
|
||||||
|
|
||||||
|
private static final int INITIAL_DELAY = 3;
|
||||||
|
|
||||||
|
private static final String RUN_MESSAGE_SEND_TASK_EXECUTOR = "runMessageSendTaskExecutor";
|
||||||
|
|
||||||
|
private static final String AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR = "cn.hippo4j.example.agent.config.nacos.v3.ThreadPoolConfigurationBootV3#AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test alarm notification.
|
||||||
|
* If you need to run this single test, add @PostConstruct to the method.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
//@PostConstruct
|
||||||
|
public void alarmSendMessageTest() {
|
||||||
|
ScheduledExecutorService scheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
scheduledThreadPool.scheduleWithFixedDelay(() -> {
|
||||||
|
ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR);
|
||||||
|
ThreadPoolExecutor poolExecutor = executorHolder.getExecutor();
|
||||||
|
try {
|
||||||
|
poolExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Throw reject policy.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}, INITIAL_DELAY, 2, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
scheduledThreadPool.scheduleWithFixedDelay(() -> {
|
||||||
|
ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(RUN_MESSAGE_SEND_TASK_EXECUTOR);
|
||||||
|
ThreadPoolExecutor poolExecutor = executorHolder.getExecutor();
|
||||||
|
try {
|
||||||
|
poolExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP_TIME);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("Throw reject policy.", ex.getMessage());
|
||||||
|
}
|
||||||
|
}, INITIAL_DELAY, 2, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
server.port=8093
|
||||||
|
server.servlet.context-path=/example
|
||||||
|
|
||||||
|
# The following parameters are used for testing
|
||||||
|
|
||||||
|
# NacosCloud properties
|
||||||
|
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||||
|
# boot3 version nacosCloud must add , In order to refresh configuration to Env
|
||||||
|
spring.config.import=nacos:dynamic-threadpool-example-config-boot3?refreshEnabled=true
|
||||||
|
|
||||||
|
# NacosBoot properties
|
||||||
|
#nacos.config.auto-refresh=true
|
||||||
|
#nacos.config.bootstrap.enable=true
|
||||||
|
#nacos.config.server-addr=127.0.0.1:8848
|
||||||
|
#nacos.config.data-id=dynamic-threadpool-example-config-boot3
|
||||||
|
#nacos.config.group=DEFAULT_GROUP
|
||||||
|
#nacos.config.type=properties
|
||||||
|
|
||||||
|
spring.profiles.active=dev
|
||||||
|
spring.application.name=hippo4j-config-nacos-spring-boot-starter-example
|
||||||
|
management.metrics.export.prometheus.enabled=true
|
||||||
|
management.server.port=29998
|
||||||
|
management.endpoints.web.exposure.include=*
|
||||||
|
spring.dynamic.thread-pool.enable=true
|
||||||
|
spring.dynamic.thread-pool.banner=true
|
||||||
|
spring.dynamic.thread-pool.check-state-interval=10
|
||||||
|
#spring.dynamic.thread-pool.monitor.enable=true
|
||||||
|
#spring.dynamic.thread-pool.monitor.collect-types=micrometer
|
||||||
|
#spring.dynamic.thread-pool.monitor.thread-pool-types=dynamic,web
|
||||||
|
spring.dynamic.thread-pool.monitor.agent-micrometer-port=29999
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.monitor.initial-delay=3000
|
||||||
|
spring.dynamic.thread-pool.monitor.collect-interval=3000
|
||||||
|
spring.dynamic.thread-pool.notify-platforms[0].platform=LARK
|
||||||
|
spring.dynamic.thread-pool.notify-platforms[0].token=6de41bdc-0799-45be-b128-7cddb9e777f0
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[1].platform=WECHAT
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[1].token=ac0426a5-c712-474c-9bff-72b8b8f5caff
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[2].platform=DING
|
||||||
|
#spring.dynamic.thread-pool.notify-platforms[2].token=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.nacos.data-id=dynamic-threadpool-example-config-boot3
|
||||||
|
spring.dynamic.thread-pool.nacos.group=DEFAULT_GROUP
|
||||||
|
spring.dynamic.thread-pool.nacos.namespace=public
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.config-file-type=properties
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.executors[0].thread-name-prefix = DynamicThreadPoolConfig#FIELD1
|
||||||
|
spring.dynamic.thread-pool.executors[0].core-pool-size = 2
|
||||||
|
spring.dynamic.thread-pool.executors[0].thread-pool-id =cn.hippo4j.example.agent.config.nacos.v3.ThreadPoolConfigurationBootV3#AGENT_RUN_MESSAGE_SEND_TASK_EXECUTOR
|
||||||
|
spring.dynamic.thread-pool.executors[0].maximum-pool-size = 20
|
||||||
|
spring.dynamic.thread-pool.executors[0].queue-capacity = 1024
|
||||||
|
spring.dynamic.thread-pool.executors[0].blocking-queue = ResizableCapacityLinkedBlockingQueue
|
||||||
|
spring.dynamic.thread-pool.executors[0].execute-time-out = 800
|
||||||
|
spring.dynamic.thread-pool.executors[0].rejected-handler = AbortPolicy
|
||||||
|
spring.dynamic.thread-pool.executors[0].keep-alive-time = 6691
|
||||||
|
spring.dynamic.thread-pool.executors[0].allow-core-thread-time-out = true
|
||||||
|
spring.dynamic.thread-pool.executors[0].alarm = true
|
||||||
|
spring.dynamic.thread-pool.executors[0].active-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[0].capacity-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[0].notify.interval = 8
|
||||||
|
spring.dynamic.thread-pool.executors[0].notify.receives = nobodyiam
|
||||||
|
|
||||||
|
spring.dynamic.thread-pool.executors[1].thread-pool-id = runMessageSendTaskExecutor
|
||||||
|
spring.dynamic.thread-pool.executors[1].thread-name-prefix = runMessageSendTaskExecutor
|
||||||
|
spring.dynamic.thread-pool.executors[1].core-pool-size = 3
|
||||||
|
spring.dynamic.thread-pool.executors[1].maximum-pool-size = 4
|
||||||
|
spring.dynamic.thread-pool.executors[1].queue-capacity = 1024
|
||||||
|
spring.dynamic.thread-pool.executors[1].blocking-queue = ResizableCapacityLinkedBlockingQueue
|
||||||
|
spring.dynamic.thread-pool.executors[1].execute-time-out = 800
|
||||||
|
spring.dynamic.thread-pool.executors[1].rejected-handler = AbortPolicy
|
||||||
|
spring.dynamic.thread-pool.executors[1].keep-alive-time = 6691
|
||||||
|
spring.dynamic.thread-pool.executors[1].allow-core-thread-time-out = true
|
||||||
|
spring.dynamic.thread-pool.executors[1].active-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[1].capacity-alarm = 80
|
||||||
|
spring.dynamic.thread-pool.executors[1].notify.interval = 8
|
||||||
|
spring.dynamic.thread-pool.executors[1].notify.receives = nobodyiam
|
Loading…
Reference in new issue