mirror of https://github.com/longtai-cn/hippo4j
feat:Completed the implementation of Nacos Configuration Center plugin and Nacos,Apollo plugins adapted to Spring 1.x , 2.x environment
parent
9800d6c011
commit
1d8d116877
@ -0,0 +1,37 @@
|
||||
<?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-plugin</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hippo4j-agent-nacos-plugin</artifactId>
|
||||
|
||||
<properties>
|
||||
<nacos.version>2.2.1</nacos.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-agent-spring-plugin-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-threadpool-dynamic-mode-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.nacos;
|
||||
|
||||
import cn.hippo4j.agent.plugin.spring.common.conf.SpringBootConfig;
|
||||
import cn.hippo4j.agent.plugin.spring.common.toolkit.SpringPropertyBinder;
|
||||
import cn.hippo4j.common.executor.ThreadFactoryBuilder;
|
||||
import cn.hippo4j.common.logging.api.ILog;
|
||||
import cn.hippo4j.common.logging.api.LogManager;
|
||||
import cn.hippo4j.threadpool.dynamic.mode.config.parser.ConfigParserHandler;
|
||||
import cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties;
|
||||
import cn.hippo4j.threadpool.dynamic.mode.config.refresher.AbstractConfigThreadPoolDynamicRefresh;
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
import static cn.hippo4j.common.constant.Constants.DEFAULT_NAMESPACE_ID;
|
||||
|
||||
/**
|
||||
* NacosDynamicThreadPoolChangeHandler is responsible for handling dynamic thread pool
|
||||
* configuration changes in a Spring environment by listening to configuration updates from Nacos.
|
||||
* <p>
|
||||
* This class extends {@link AbstractConfigThreadPoolDynamicRefresh} and implements the logic
|
||||
* to register a Nacos listener, handle configuration changes, and dynamically refresh the thread pool
|
||||
* properties based on the new configuration.
|
||||
* <p>
|
||||
*/
|
||||
public class NacosDynamicThreadPoolChangeHandler extends AbstractConfigThreadPoolDynamicRefresh {
|
||||
|
||||
private static final ILog LOGGER = LogManager.getLogger(NacosDynamicThreadPoolChangeHandler.class);
|
||||
|
||||
/**
|
||||
* Registers a listener with Nacos to monitor for changes in the thread pool configuration.
|
||||
* <p>
|
||||
* This method sets up the Nacos {@link ConfigService} with the server address and namespace
|
||||
* from the Spring Boot configuration. It then adds a listener that will receive and process
|
||||
* configuration updates, triggering a dynamic refresh of thread pool settings.
|
||||
*/
|
||||
@Override
|
||||
public void registerListener() {
|
||||
// Retrieve necessary configuration properties
|
||||
String configFileType = SpringBootConfig.Spring.Dynamic.Thread_Pool.CONFIG_FILE_TYPE;
|
||||
String serverAddr = SpringBootConfig.Spring.Dynamic.Thread_Pool.Nacos.SERVER_ADDR;
|
||||
String dataId = SpringBootConfig.Spring.Dynamic.Thread_Pool.Nacos.DATA_ID;
|
||||
String group = SpringBootConfig.Spring.Dynamic.Thread_Pool.Nacos.GROUP;
|
||||
String namespace = SpringBootConfig.Spring.Dynamic.Thread_Pool.Nacos.NAMESPACE.get(0);
|
||||
namespace = namespace.equals(DEFAULT_NAMESPACE_ID) ? "" : namespace;
|
||||
try {
|
||||
// Initialize Nacos ConfigService with the provided properties
|
||||
Properties properties = new Properties();
|
||||
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
|
||||
properties.put(PropertyKeyConst.NAMESPACE, namespace);
|
||||
ConfigService configService = NacosFactory.createConfigService(properties);
|
||||
|
||||
// Define the listener to handle configuration changes
|
||||
Listener configChangeListener = new Listener() {
|
||||
|
||||
@Override
|
||||
public void receiveConfigInfo(String configInfo) {
|
||||
LOGGER.debug("Received configuration: " + configInfo);
|
||||
Map<String, Object> changeValueMap = new HashMap<>();
|
||||
try {
|
||||
// Parse the configuration and map the values to the appropriate keys
|
||||
Map<Object, Object> configInfoMap = ConfigParserHandler.getInstance().parseConfig(configInfo, configFileType);
|
||||
configInfoMap.forEach((key, value) -> {
|
||||
if (key instanceof String) {
|
||||
changeValueMap.put((String) key, value);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e, "[Hippo4j-Agent] Dynamic thread pool refresher, Failed to resolve configuration. configFileType: {} configInfo: {} ", configFileType, configInfo);
|
||||
}
|
||||
// Trigger the dynamic refresh with the parsed configuration
|
||||
dynamicRefresh(configFileType, configInfo, changeValueMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getExecutor() {
|
||||
return new ScheduledThreadPoolExecutor(1, ThreadFactoryBuilder.builder().daemon(true).prefix("client.dynamic.refresh.agent").build());
|
||||
}
|
||||
};
|
||||
// Add the listener to the Nacos ConfigService
|
||||
configService.addListener(dataId, group, configChangeListener);
|
||||
LOGGER.info("[Hippo4j-Agent] Dynamic thread pool refresher, add Nacos listener successfully. namespace: {} data-id: {} group: {}", namespace, dataId, group);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e, "[Hippo4j-Agent] Dynamic thread pool refresher, add Nacos listener failure. namespace: {} data-id: {} group: {}", namespace, dataId, group);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and binds the {@link BootstrapConfigProperties} from the given configuration map.
|
||||
* <p>
|
||||
* This method uses Spring's {@link Binder} to bind the configuration values to an instance
|
||||
* of {@link BootstrapConfigProperties}, which can then be used to configure the thread pool
|
||||
* dynamically.
|
||||
*
|
||||
* @param configInfo the configuration map containing properties to bind.
|
||||
* @return the bound {@link BootstrapConfigProperties} instance.
|
||||
*/
|
||||
@Override
|
||||
public BootstrapConfigProperties buildBootstrapProperties(Map<Object, Object> configInfo) {
|
||||
BootstrapConfigProperties bindableBootstrapConfigProperties = SpringPropertyBinder.bindProperties(configInfo, BootstrapConfigProperties.PREFIX, BootstrapConfigProperties.class);
|
||||
return bindableBootstrapConfigProperties;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.nacos.boot;
|
||||
|
||||
import cn.hippo4j.agent.core.boot.BootService;
|
||||
import cn.hippo4j.agent.core.boot.DefaultImplementor;
|
||||
|
||||
/**
|
||||
* Nacos plugin boot service
|
||||
*/
|
||||
@DefaultImplementor
|
||||
public class NacosPluginBootService implements BootService {
|
||||
|
||||
@Override
|
||||
public void prepare() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void boot() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() throws Throwable {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.nacos.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 cn.hippo4j.agent.core.plugin.match.NameMatch;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
public class NacosCloudAdapterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration";
|
||||
|
||||
private static final String INSTANCE_METHODS_INTERCEPT_CLASS = "cn.hippo4j.agent.plugin.nacos.interceptor.NacosCloudAdapterConfigInstanceMethodInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.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("initialize");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INSTANCE_METHODS_INTERCEPT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<WitnessMethod> witnessMethods() {
|
||||
return Collections.singletonList(new WitnessMethod("com.alibaba.cloud.nacos.client.NacosPropertySourceLocator", named("locate")));
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.nacos.define;
|
||||
|
||||
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 cn.hippo4j.agent.core.plugin.match.NameMatch;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
|
||||
/**
|
||||
* Nacos instrumentation
|
||||
*/
|
||||
public class NacosInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "com.alibaba.nacos.client.config.NacosConfigService";
|
||||
|
||||
private static final String CONSTRUCTOR_INTERCEPT_CLASS = "cn.hippo4j.agent.plugin.nacos.interceptor.NacosConfigConstructorInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return NameMatch.byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[]{
|
||||
new ConstructorInterceptPoint() {
|
||||
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return CONSTRUCTOR_INTERCEPT_CLASS;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[0];
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.nacos.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.support.SpringPropertiesLoader;
|
||||
import cn.hippo4j.agent.plugin.spring.common.support.SpringThreadPoolRegisterSupport;
|
||||
import cn.hippo4j.core.config.ApplicationContextHolder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Nacos Cloud config constructor interceptor
|
||||
*/
|
||||
public class NacosCloudAdapterConfigInstanceMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
private static final AtomicBoolean isExecuted = new AtomicBoolean(false);
|
||||
|
||||
@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 {
|
||||
// This logic will only be executed once
|
||||
if (isExecuted.compareAndSet(false, true)) {
|
||||
// Get the configurable Application Context
|
||||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) allArguments[0];
|
||||
ConfigurableEnvironment environment = configurableApplicationContext.getEnvironment();
|
||||
|
||||
// Remote Nacos configuration swiped into SpringPropertiesLoader
|
||||
SpringPropertiesLoader.loadSpringProperties(environment);
|
||||
// Refresh thread pool instances through configuration
|
||||
SpringThreadPoolRegisterSupport.registerThreadPoolInstances(ApplicationContextHolder.getInstance());
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.nacos.interceptor;
|
||||
|
||||
import cn.hippo4j.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import cn.hippo4j.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||
import cn.hippo4j.agent.plugin.nacos.NacosDynamicThreadPoolChangeHandler;
|
||||
import cn.hippo4j.agent.plugin.nacos.listeners.NacosConfigPropertiesLoaderCompletedListener;
|
||||
import cn.hippo4j.agent.plugin.spring.common.support.SpringPropertiesLoader;
|
||||
import cn.hippo4j.common.extension.design.AbstractSubjectCenter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Nacos config constructor interceptor
|
||||
*/
|
||||
public class NacosConfigConstructorInterceptor implements InstanceConstructorInterceptor {
|
||||
|
||||
private static final AtomicBoolean isExecuted = new AtomicBoolean(false);
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
|
||||
// This logic will only be executed once
|
||||
if (isExecuted.compareAndSet(false, true)) {
|
||||
|
||||
// 判断 SpringPropertiesLoader 是否初始化
|
||||
AtomicBoolean active = SpringPropertiesLoader.getActive();
|
||||
|
||||
// For Nacos-Cloud, the SpringPropertiesLoader environment initialization is triggered first, and then the logic to register listeners is triggered
|
||||
// For Nacos-Boot, the listener is registered first, and the SpringPropertiesLoader environment is initialized
|
||||
if (Boolean.TRUE.equals(active.get())) {
|
||||
new NacosDynamicThreadPoolChangeHandler().registerListener();
|
||||
return;
|
||||
}
|
||||
|
||||
// The Nacos plugin triggers before the Spring configuration plug-in.
|
||||
// This means that when the Apollo plug-in executes, Spring's Environment is not yet ready,
|
||||
// so the configuration cannot be read
|
||||
// After listening to the AGENT_SPRING_PROPERTIES_LOADER_COMPLETED event, register the listener for Apollo
|
||||
AbstractSubjectCenter.register(AbstractSubjectCenter.SubjectType.AGENT_SPRING_PROPERTIES_LOADER_COMPLETED, new NacosConfigPropertiesLoaderCompletedListener());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.nacos.listeners;
|
||||
|
||||
import cn.hippo4j.agent.plugin.nacos.NacosDynamicThreadPoolChangeHandler;
|
||||
import cn.hippo4j.common.extension.design.Observer;
|
||||
import cn.hippo4j.common.extension.design.ObserverMessage;
|
||||
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
|
||||
|
||||
/**
|
||||
* Nacos Config Properties Loader Completed Listener
|
||||
*/
|
||||
public class NacosConfigPropertiesLoaderCompletedListener implements Observer<String> {
|
||||
|
||||
@Override
|
||||
public void accept(ObserverMessage<String> observerMessage) {
|
||||
ThreadPoolDynamicRefresh dynamicRefresh = new NacosDynamicThreadPoolChangeHandler();
|
||||
dynamicRefresh.registerListener();
|
||||
}
|
||||
}
|
@ -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.nacos.boot.NacosPluginBootService
|
@ -0,0 +1,18 @@
|
||||
# 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.
|
||||
|
||||
nacos-plugin=cn.hippo4j.agent.plugin.nacos.define.NacosInstrumentation
|
||||
nacos-cloud-adapter-plugin=cn.hippo4j.agent.plugin.nacos.define.NacosCloudAdapterInstrumentation
|
67
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/ApplicationContextInstrumentation.java
67
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/EventPublishingRunListenerInstrumentation.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/define/ApplicationContextInstrumentation.java
34
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/ApplicationContextInterceptor.java
34
agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/EventPublishingFinishedInterceptor.java → agent/hippo4j-agent-plugin/spring-plugins/spring-boot-1x-plugin/src/main/java/cn/hippo4j/agent/plugin/spring/boot/v1/interceptor/ApplicationContextInterceptor.java
@ -0,0 +1,53 @@
|
||||
server.port=8092
|
||||
server.servlet.context-path=/example
|
||||
|
||||
app.id=dynamic-threadpool-example
|
||||
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
|
||||
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
|
||||
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.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.core.config.ThreadPoolConfiguration#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
|
@ -0,0 +1,74 @@
|
||||
<?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>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hippo4j-threadpool-agent-config-nacos-spring-boot-1x</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<spring-boot.version>1.5.22.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<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>1.5.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<version>1.3.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</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.nacos.v1;
|
||||
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Agent config Nacos example application.
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "cn.hippo4j.example.agent.core")
|
||||
public class AgentConfigNacosSpringBoot1xExampleApplication {
|
||||
|
||||
public static void main(String[] args) throws NacosException {
|
||||
SpringApplication.run(AgentConfigNacosSpringBoot1xExampleApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
server.port=8092
|
||||
server.servlet.context-path=/example
|
||||
spring.profiles.active=dev
|
||||
spring.application.name=hippo4j-config-nacos-spring-boot-starter-example
|
||||
|
||||
# The following parameters are used for testing
|
||||
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||
spring.cloud.nacos.config.name=dynamic-threadpool-example-config
|
||||
spring.cloud.nacos.config.file-extension=properties
|
||||
spring.cloud.nacos.config.refresh.enabled=true
|
||||
|
||||
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.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.server-addr=127.0.0.1:8848
|
||||
spring.dynamic.thread-pool.nacos.data-id=dynamic-threadpool-example-config
|
||||
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.core.config.ThreadPoolConfiguration#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
|
Loading…
Reference in new issue