diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java index 2cb39f27..c4caf35c 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/config/DynamicThreadPoolAutoConfiguration.java @@ -33,6 +33,7 @@ import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.message.api.NotifyConfigBuilder; import cn.hippo4j.message.config.MessageConfiguration; import cn.hippo4j.message.service.AlarmControlHandler; +import cn.hippo4j.message.service.Hippo4jBaseSendMessageService; import cn.hippo4j.message.service.Hippo4jSendMessageService; import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController; import cn.hippo4j.springboot.starter.controller.WebThreadPoolController; @@ -101,8 +102,10 @@ public class DynamicThreadPoolAutoConfiguration { public DynamicThreadPoolService dynamicThreadPoolConfigService(HttpAgent httpAgent, ClientWorker clientWorker, ServerHealthCheck serverHealthCheck, + ServerNotifyConfigBuilder notifyConfigBuilder, + Hippo4jBaseSendMessageService hippo4jBaseSendMessageService, DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig) { - return new DynamicThreadPoolConfigService(httpAgent, clientWorker, properties, dynamicThreadPoolSubscribeConfig); + return new DynamicThreadPoolConfigService(httpAgent, clientWorker, properties, notifyConfigBuilder, hippo4jBaseSendMessageService, dynamicThreadPoolSubscribeConfig); } @Bean diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java index 9b51cc2d..4065b27c 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/notify/ServerNotifyConfigBuilder.java @@ -55,12 +55,16 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder { @Override public Map> buildNotify() { - Map> resultMap = Maps.newHashMap(); List threadPoolIds = GlobalThreadPoolManage.listThreadPoolId(); if (CollUtil.isEmpty(threadPoolIds)) { log.warn("The client does not have a dynamic thread pool instance configured."); - return resultMap; + return Maps.newHashMap(); } + return getAndInitNotify(threadPoolIds); + } + + public Map> getAndInitNotify(List threadPoolIds) { + Map> resultMap = Maps.newHashMap(); List groupKeys = Lists.newArrayList(); threadPoolIds.forEach(each -> { String groupKey = GroupKey.getKeyTenant(each, properties.getItemId(), properties.getNamespace()); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java index 22898ab5..64e86112 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolConfigService.java @@ -29,16 +29,22 @@ import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.support.service.AbstractDynamicThreadPoolService; +import cn.hippo4j.message.dto.NotifyConfigDTO; +import cn.hippo4j.message.service.Hippo4jBaseSendMessageService; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.core.ClientWorker; import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig; import cn.hippo4j.springboot.starter.event.ApplicationCompleteEvent; +import cn.hippo4j.springboot.starter.notify.ServerNotifyConfigBuilder; import cn.hippo4j.springboot.starter.remote.HttpAgent; +import com.google.common.collect.Lists; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationListener; +import java.util.List; +import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; import static cn.hippo4j.common.constant.Constants.REGISTER_DYNAMIC_THREAD_POOL_PATH; @@ -56,6 +62,10 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer private final BootstrapProperties properties; + private final ServerNotifyConfigBuilder notifyConfigBuilder; + + private final Hippo4jBaseSendMessageService hippo4jBaseSendMessageService; + private final DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig; @Override @@ -106,6 +116,8 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer registerParameter.getActiveAlarm(), registerParameter.getCapacityAlarm()); GlobalNotifyAlarmManage.put(registerParameter.getThreadPoolId(), threadPoolNotifyAlarm); + Map> builderNotify = notifyConfigBuilder.getAndInitNotify(Lists.newArrayList(registerParameter.getThreadPoolId())); + hippo4jBaseSendMessageService.putPlatform(builderNotify); } private void checkThreadPoolParameter(DynamicThreadPoolRegisterParameter registerParameter) {