Merge remote-tracking branch 'origin/develop' into develop

pull/546/head
chen.ma 2 years ago
commit e26b798f67

@ -17,6 +17,12 @@
package cn.hippo4j.adapter.rabbitmq; package cn.hippo4j.adapter.rabbitmq;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import cn.hippo4j.adapter.base.ThreadPoolAdapter; import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter; import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState; import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
@ -25,16 +31,11 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory; import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER; import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
/** /**
@ -48,12 +49,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
private static final String FiledName = "executorService"; private static final String FiledName = "executorService";
/** private final Map<String, AbstractConnectionFactory> abstractConnectionFactoryMap;
* TODO Configurable name
*/
private static final String RABBITMQ_EXECUTOR_SERVICE = "Rabbitmq_Executor_Service";
private final AbstractConnectionFactory abstractConnectionFactory;
private final Map<String, ThreadPoolExecutor> RABBITMQ_THREAD_POOL_TASK_EXECUTOR = Maps.newHashMap(); private final Map<String, ThreadPoolExecutor> RABBITMQ_THREAD_POOL_TASK_EXECUTOR = Maps.newHashMap();
@ -103,15 +99,19 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override @Override
public void onApplicationEvent(ApplicationStartedEvent event) { public void onApplicationEvent(ApplicationStartedEvent event) {
ExecutorService executor = (ExecutorService) ReflectUtil.getFieldValue(abstractConnectionFactory, FiledName); abstractConnectionFactoryMap.forEach((beanName, abstractConnectionFactor) -> {
ExecutorService executor = (ExecutorService) ReflectUtil.getFieldValue(abstractConnectionFactor, FiledName);
if (Objects.nonNull(executor)) { if (Objects.nonNull(executor)) {
if (executor instanceof ThreadPoolExecutor) { if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolTaskExecutor = (ThreadPoolExecutor) executor; ThreadPoolExecutor threadPoolTaskExecutor = (ThreadPoolExecutor) executor;
RABBITMQ_THREAD_POOL_TASK_EXECUTOR.put(RABBITMQ_EXECUTOR_SERVICE, threadPoolTaskExecutor); RABBITMQ_THREAD_POOL_TASK_EXECUTOR.put(beanName, threadPoolTaskExecutor);
log.info("Rabbitmq executor name {}", RABBITMQ_EXECUTOR_SERVICE); log.info("Rabbitmq executor name {}", beanName);
} else { }
else {
log.warn("Custom thread pools only support ThreadPoolExecutor"); log.warn("Custom thread pools only support ThreadPoolExecutor");
} }
} }
});
} }
} }

@ -40,7 +40,7 @@ import org.springframework.stereotype.Service;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Objects;
/** /**
* Thread pool service impl. * Thread pool service impl.
@ -83,7 +83,7 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
@Override @Override
public void saveOrUpdateThreadPoolConfig(String identify, ThreadPoolSaveOrUpdateReqDTO reqDTO) { public void saveOrUpdateThreadPoolConfig(String identify, ThreadPoolSaveOrUpdateReqDTO reqDTO) {
ConfigAllInfo configAllInfo = BeanUtil.convert(reqDTO, ConfigAllInfo.class); ConfigAllInfo configAllInfo = BeanUtil.convert(reqDTO, ConfigAllInfo.class);
Long executeTimeOut = configAllInfo.getExecuteTimeOut() == 0 ? null : configAllInfo.getExecuteTimeOut(); Long executeTimeOut = Objects.equals(configAllInfo.getExecuteTimeOut(), 0L) ? null : configAllInfo.getExecuteTimeOut();
configAllInfo.setExecuteTimeOut(executeTimeOut); configAllInfo.setExecuteTimeOut(executeTimeOut);
configService.insertOrUpdate(identify, false, configAllInfo); configService.insertOrUpdate(identify, false, configAllInfo);
} }
@ -102,7 +102,7 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
LogRecordInfo logRecordInfo = LogRecordInfo.builder() LogRecordInfo logRecordInfo = LogRecordInfo.builder()
.bizKey(requestParam.getItemId() + "_" + requestParam.getTpId()) .bizKey(requestParam.getItemId() + "_" + requestParam.getTpId())
.bizNo(requestParam.getItemId() + "_" + requestParam.getTpId()) .bizNo(requestParam.getItemId() + "_" + requestParam.getTpId())
.operator(Optional.ofNullable(UserContext.getUserName()).orElse("-")) .operator(UserContext.getUserName())
.action("删除线程池: " + requestParam.getTpId()) .action("删除线程池: " + requestParam.getTpId())
.category("THREAD_POOL_DELETE") .category("THREAD_POOL_DELETE")
.detail(JSONUtil.toJSONString(requestParam)) .detail(JSONUtil.toJSONString(requestParam))

@ -17,9 +17,12 @@
package cn.hippo4j.springboot.starter.adapter.rabbitmq; package cn.hippo4j.springboot.starter.adapter.rabbitmq;
import java.util.Map;
import cn.hippo4j.adapter.rabbitmq.RabbitMQThreadPoolAdapter; import cn.hippo4j.adapter.rabbitmq.RabbitMQThreadPoolAdapter;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory; import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -33,7 +36,7 @@ import org.springframework.context.annotation.Configuration;
@RequiredArgsConstructor @RequiredArgsConstructor
public class RabbitMQAdapterAutoConfiguration { public class RabbitMQAdapterAutoConfiguration {
private final AbstractConnectionFactory abstractConnectionFactories; private final Map<String, AbstractConnectionFactory> stringAbstractConnectionFactoryMap;
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ -45,6 +48,6 @@ public class RabbitMQAdapterAutoConfiguration {
@SuppressWarnings("all") @SuppressWarnings("all")
@ConditionalOnProperty(name = "spring.rabbitmq.host") @ConditionalOnProperty(name = "spring.rabbitmq.host")
public RabbitMQThreadPoolAdapter rabbitMQThreadPoolAdapter(ApplicationContextHolder applicationContextHolder) { public RabbitMQThreadPoolAdapter rabbitMQThreadPoolAdapter(ApplicationContextHolder applicationContextHolder) {
return new RabbitMQThreadPoolAdapter(abstractConnectionFactories); return new RabbitMQThreadPoolAdapter(stringAbstractConnectionFactoryMap);
} }
} }

Loading…
Cancel
Save