From 910739c090b1fc2a1926195b996b0c1ec85447ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Fri, 8 Mar 2019 21:24:32 +0800 Subject: [PATCH] =?UTF-8?q?:bookmark:=20Releasing=20/=20Version=20tags.=20?= =?UTF-8?q?2.6.0=20.=20=E9=84=99=E8=A7=86=E6=9F=90=E4=BA=9B=E4=BA=BA?= =?UTF-8?q?=E7=9A=84=E5=88=86=E4=BA=AB/=E7=9B=97=E7=AA=83,=E6=8C=81?= =?UTF-8?q?=E7=BB=AD=E5=BC=80=E6=BA=90=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- pigx-auth/pom.xml | 2 +- pigx-common/pigx-common-bom/pom.xml | 2 +- pigx-common/pigx-common-core/pom.xml | 2 +- pigx-common/pigx-common-data/pom.xml | 2 +- pigx-common/pigx-common-gateway/pom.xml | 2 +- pigx-common/pigx-common-job/pom.xml | 2 +- pigx-common/pigx-common-log/pom.xml | 2 +- pigx-common/pigx-common-minio/pom.xml | 2 +- pigx-common/pigx-common-security/pom.xml | 2 +- .../annotation/EnablePigxResourceServer.java | 11 +-- .../PigxResourceServerConfigurerAdapter.java | 55 +---------- .../PigxSecurityBeanDefinitionRegistrar.java | 10 -- .../PigxUserAuthenticationConverter.java | 93 +++++++++++++++++++ pigx-common/pigx-common-swagger/pom.xml | 2 +- pigx-common/pigx-common-transaction/pom.xml | 2 +- pigx-common/pom.xml | 2 +- pigx-config/pom.xml | 2 +- pigx-eureka/pom.xml | 2 +- pigx-gateway/pom.xml | 2 +- pigx-upms/pigx-upms-api/pom.xml | 2 +- pigx-upms/pigx-upms-biz/pom.xml | 2 +- .../pigx/admin/PigxAdminApplication.java | 2 +- pigx-upms/pom.xml | 2 +- pigx-visual/pigx-activiti/pom.xml | 2 +- pigx-visual/pigx-codegen/pom.xml | 2 +- pigx-visual/pigx-daemon/pom.xml | 2 +- pigx-visual/pigx-monitor/pom.xml | 4 +- pigx-visual/pigx-sso-client-demo/pom.xml | 2 +- pigx-visual/pigx-tx-manager/pom.xml | 2 +- .../service/impl/CompensateServiceImpl.java | 5 +- .../pigx/manager/config/ExecutorConfig.java | 53 +++++++++++ .../service/impl/NettyServerServiceImpl.java | 44 ++++----- pigx-visual/pigx-zipkin/pom.xml | 2 +- pigx-visual/pom.xml | 2 +- pom.xml | 2 +- 36 files changed, 201 insertions(+), 130 deletions(-) create mode 100644 pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java create mode 100644 pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/config/ExecutorConfig.java diff --git a/docker-compose.yml b/docker-compose.yml index 3eb10cdbf..cf6092b34 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -# 使用说明 V2.1.0 +# 使用说明 V2.6.0 # 1. 使用docker-compose 宿主机不需要配置host来发现 # 2. 无需修改源码,根目录 docker-compose up 即可 # 3. 静静等待服务启动 diff --git a/pigx-auth/pom.xml b/pigx-auth/pom.xml index a9d86c9f2..974d0f3b6 100644 --- a/pigx-auth/pom.xml +++ b/pigx-auth/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-auth diff --git a/pigx-common/pigx-common-bom/pom.xml b/pigx-common/pigx-common-bom/pom.xml index b80f199ee..ebef66186 100644 --- a/pigx-common/pigx-common-bom/pom.xml +++ b/pigx-common/pigx-common-bom/pom.xml @@ -16,7 +16,7 @@ pigx 公共版本控制 - 2.5.1 + 2.6.0 2.9.6 3.1.0 8.0.13 diff --git a/pigx-common/pigx-common-core/pom.xml b/pigx-common/pigx-common-core/pom.xml index dcb2bf7c1..5376c4662 100644 --- a/pigx-common/pigx-common-core/pom.xml +++ b/pigx-common/pigx-common-core/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-core diff --git a/pigx-common/pigx-common-data/pom.xml b/pigx-common/pigx-common-data/pom.xml index 747e85db0..5ac55303d 100644 --- a/pigx-common/pigx-common-data/pom.xml +++ b/pigx-common/pigx-common-data/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-data diff --git a/pigx-common/pigx-common-gateway/pom.xml b/pigx-common/pigx-common-gateway/pom.xml index c75e4607a..62960bcd0 100644 --- a/pigx-common/pigx-common-gateway/pom.xml +++ b/pigx-common/pigx-common-gateway/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-gateway diff --git a/pigx-common/pigx-common-job/pom.xml b/pigx-common/pigx-common-job/pom.xml index 1833621aa..dfb6ff93b 100644 --- a/pigx-common/pigx-common-job/pom.xml +++ b/pigx-common/pigx-common-job/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-job diff --git a/pigx-common/pigx-common-log/pom.xml b/pigx-common/pigx-common-log/pom.xml index 1ae0fa1eb..8d7044bf0 100644 --- a/pigx-common/pigx-common-log/pom.xml +++ b/pigx-common/pigx-common-log/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-log diff --git a/pigx-common/pigx-common-minio/pom.xml b/pigx-common/pigx-common-minio/pom.xml index 0d4c62146..4bc87e848 100755 --- a/pigx-common/pigx-common-minio/pom.xml +++ b/pigx-common/pigx-common-minio/pom.xml @@ -6,7 +6,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-minio diff --git a/pigx-common/pigx-common-security/pom.xml b/pigx-common/pigx-common-security/pom.xml index 8a8f72089..2650041ea 100644 --- a/pigx-common/pigx-common-security/pom.xml +++ b/pigx-common/pigx-common-security/pom.xml @@ -23,7 +23,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-security diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java index 595eb6f00..fca972cff 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/annotation/EnablePigxResourceServer.java @@ -31,20 +31,13 @@ import java.lang.annotation.*; *

* 资源服务注解 */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @EnableResourceServer +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) @EnableGlobalMethodSecurity(prePostEnabled = true) @Import({PigxResourceServerAutoConfiguration.class, PigxSecurityBeanDefinitionRegistrar.class}) public @interface EnablePigxResourceServer { - /** - * false:上下文获取用户名 - * true: 上下文获取全部用户信息 - * - * @return - */ - boolean details() default false; } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java index e94390c92..4af07d886 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxResourceServerConfigurerAdapter.java @@ -17,18 +17,16 @@ package com.pig4cloud.pigx.common.security.component; -import lombok.Setter; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; -import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; import org.springframework.security.oauth2.provider.token.RemoteTokenServices; +import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter; import org.springframework.web.client.RestTemplate; /** @@ -45,13 +43,9 @@ public class PigxResourceServerConfigurerAdapter extends ResourceServerConfigure @Autowired protected RemoteTokenServices remoteTokenServices; @Autowired - protected UserDetailsService userDetailsService; - @Autowired private PermitAllUrlProperties permitAllUrlProperties; @Autowired private RestTemplate lbRestTemplate; - @Setter - private boolean details; /** * 默认的配置,对外暴露 @@ -72,58 +66,15 @@ public class PigxResourceServerConfigurerAdapter extends ResourceServerConfigure .and().csrf().disable(); } - /** - * 提供子类重写 - *

- * 1. 不重写,默认支持获取用户名 - * 2. 重写notGetUser,提供性能 - *

- * see codegen ResourceServerConfigurer - * - * @param resources - */ @Override public void configure(ResourceServerSecurityConfigurer resources) { - if (details) { - canGetUser(resources); - } else { - notGetUser(resources); - } - } - - - /** - * 不获取用户详细 只有用户名 - * - * @param resources - */ - protected void notGetUser(ResourceServerSecurityConfigurer resources) { DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); - DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); + UserAuthenticationConverter userTokenConverter = new PigxUserAuthenticationConverter(); accessTokenConverter.setUserTokenConverter(userTokenConverter); remoteTokenServices.setRestTemplate(lbRestTemplate); remoteTokenServices.setAccessTokenConverter(accessTokenConverter); resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .tokenServices(remoteTokenServices); + .tokenServices(remoteTokenServices); } - - - /** - * 上下文中获取用户全部信息,两次调用userDetailsService,影响性能 - * - * @param resources - */ - private void canGetUser(ResourceServerSecurityConfigurer resources) { - DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); - DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter(); - userTokenConverter.setUserDetailsService(userDetailsService); - accessTokenConverter.setUserTokenConverter(userTokenConverter); - - remoteTokenServices.setRestTemplate(lbRestTemplate); - remoteTokenServices.setAccessTokenConverter(accessTokenConverter); - resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint) - .tokenServices(remoteTokenServices); - } - } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java index ad26dd1f4..97fa0547d 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxSecurityBeanDefinitionRegistrar.java @@ -18,16 +18,12 @@ package com.pig4cloud.pigx.common.security.component; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; -import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; -import java.util.Map; - /** * @author lengleng * @date 2018-11-24 @@ -49,12 +45,6 @@ public class PigxSecurityBeanDefinitionRegistrar implements ImportBeanDefinition GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(PigxResourceServerConfigurerAdapter.class); - MutablePropertyValues mpv = new MutablePropertyValues(); - Map annotationAttributes = metadata.getAnnotationAttributes( - EnablePigxResourceServer.class.getName()); - Object details = annotationAttributes.get("details"); - mpv.add("details", details); - beanDefinition.setPropertyValues(mpv); registry.registerBeanDefinition(SecurityConstants.RESOURCE_SERVER_CONFIGURER, beanDefinition); } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java new file mode 100644 index 000000000..16de777b3 --- /dev/null +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.common.security.component; + +import com.pig4cloud.pigx.common.security.service.PigxUser; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter; +import org.springframework.util.StringUtils; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2019-03-07 + *

+ * 根据checktoken 的结果转化用户信息 + */ +public class PigxUserAuthenticationConverter implements UserAuthenticationConverter { + private static final String USER_ID = "user_id"; + private static final String DEPT_ID = "dept_id"; + private static final String TENANT_ID = "tenant_id"; + private static final String N_A = "N/A"; + + /** + * Extract information about the user to be used in an access token (i.e. for resource servers). + * + * @param authentication an authentication representing a user + * @return a map of key values representing the unique information about the user + */ + @Override + public Map convertUserAuthentication(Authentication authentication) { + Map response = new LinkedHashMap<>(); + response.put(USERNAME, authentication.getName()); + if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { + response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities())); + } + return response; + } + + /** + * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map. + * + * @param map a map of user information + * @return an Authentication representing the user or null if there is none + */ + @Override + public Authentication extractAuthentication(Map map) { + if (map.containsKey(USERNAME)) { + Collection authorities = getAuthorities(map); + + String username = (String) map.get(USERNAME); + Integer id = (Integer) map.get(USER_ID); + Integer deptId = (Integer) map.get(DEPT_ID); + Integer tenantId = (Integer) map.get(TENANT_ID); + PigxUser user = new PigxUser(id, deptId, tenantId, username, N_A, true + , true, true, true, authorities); + return new UsernamePasswordAuthenticationToken(user, N_A, authorities); + } + return null; + } + + private Collection getAuthorities(Map map) { + Object authorities = map.get(AUTHORITIES); + if (authorities instanceof String) { + return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities); + } + if (authorities instanceof Collection) { + return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils + .collectionToCommaDelimitedString((Collection) authorities)); + } + throw new IllegalArgumentException("Authorities must be either a String or a Collection"); + } +} diff --git a/pigx-common/pigx-common-swagger/pom.xml b/pigx-common/pigx-common-swagger/pom.xml index e71a4e4c7..eeca5f1f2 100644 --- a/pigx-common/pigx-common-swagger/pom.xml +++ b/pigx-common/pigx-common-swagger/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-swagger diff --git a/pigx-common/pigx-common-transaction/pom.xml b/pigx-common/pigx-common-transaction/pom.xml index 92a72e41f..485ce8bcb 100644 --- a/pigx-common/pigx-common-transaction/pom.xml +++ b/pigx-common/pigx-common-transaction/pom.xml @@ -5,7 +5,7 @@ com.pig4cloud pigx-common - 2.5.1 + 2.6.0 pigx-common-transaction diff --git a/pigx-common/pom.xml b/pigx-common/pom.xml index 2ef383a27..ed0619034 100644 --- a/pigx-common/pom.xml +++ b/pigx-common/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-common diff --git a/pigx-config/pom.xml b/pigx-config/pom.xml index 650c38998..c9a7a386b 100644 --- a/pigx-config/pom.xml +++ b/pigx-config/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-config diff --git a/pigx-eureka/pom.xml b/pigx-eureka/pom.xml index e708848d1..f7bc1d004 100644 --- a/pigx-eureka/pom.xml +++ b/pigx-eureka/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-eureka diff --git a/pigx-gateway/pom.xml b/pigx-gateway/pom.xml index 7029a548f..238672678 100644 --- a/pigx-gateway/pom.xml +++ b/pigx-gateway/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-gateway diff --git a/pigx-upms/pigx-upms-api/pom.xml b/pigx-upms/pigx-upms-api/pom.xml index 3829257b9..45bef3cab 100644 --- a/pigx-upms/pigx-upms-api/pom.xml +++ b/pigx-upms/pigx-upms-api/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-upms - 2.5.1 + 2.6.0 pigx-upms-api diff --git a/pigx-upms/pigx-upms-biz/pom.xml b/pigx-upms/pigx-upms-biz/pom.xml index 5062f4c4e..10ce1e87f 100644 --- a/pigx-upms/pigx-upms-biz/pom.xml +++ b/pigx-upms/pigx-upms-biz/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-upms - 2.5.1 + 2.6.0 pigx-upms-biz diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java index c4d626699..e2c6481c9 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/PigxAdminApplication.java @@ -34,7 +34,7 @@ import org.springframework.cloud.client.SpringCloudApplication; @EnablePigxSwagger2 @SpringCloudApplication @EnablePigxFeignClients -@EnablePigxResourceServer(details = true) +@EnablePigxResourceServer public class PigxAdminApplication { public static void main(String[] args) { SpringApplication.run(PigxAdminApplication.class, args); diff --git a/pigx-upms/pom.xml b/pigx-upms/pom.xml index 105fc148b..54395b99e 100644 --- a/pigx-upms/pom.xml +++ b/pigx-upms/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-upms diff --git a/pigx-visual/pigx-activiti/pom.xml b/pigx-visual/pigx-activiti/pom.xml index bdf22415d..d8b0868b3 100644 --- a/pigx-visual/pigx-activiti/pom.xml +++ b/pigx-visual/pigx-activiti/pom.xml @@ -23,7 +23,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 pigx-activiti diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml index 09a036318..832c0f16a 100755 --- a/pigx-visual/pigx-codegen/pom.xml +++ b/pigx-visual/pigx-codegen/pom.xml @@ -6,7 +6,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 pigx-codegen diff --git a/pigx-visual/pigx-daemon/pom.xml b/pigx-visual/pigx-daemon/pom.xml index d7f482749..f265e270e 100644 --- a/pigx-visual/pigx-daemon/pom.xml +++ b/pigx-visual/pigx-daemon/pom.xml @@ -23,7 +23,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 pigx-daemon diff --git a/pigx-visual/pigx-monitor/pom.xml b/pigx-visual/pigx-monitor/pom.xml index 0e3d1f5a4..5e60a6822 100644 --- a/pigx-visual/pigx-monitor/pom.xml +++ b/pigx-visual/pigx-monitor/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 pigx-monitor @@ -36,7 +36,7 @@ com.pig4cloud pigx-common-core - 2.5.1 + 2.6.0 org.springframework.boot diff --git a/pigx-visual/pigx-sso-client-demo/pom.xml b/pigx-visual/pigx-sso-client-demo/pom.xml index 4b4929e68..f70d4a29a 100644 --- a/pigx-visual/pigx-sso-client-demo/pom.xml +++ b/pigx-visual/pigx-sso-client-demo/pom.xml @@ -29,7 +29,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 diff --git a/pigx-visual/pigx-tx-manager/pom.xml b/pigx-visual/pigx-tx-manager/pom.xml index d3af848a6..3cdfdb20f 100644 --- a/pigx-visual/pigx-tx-manager/pom.xml +++ b/pigx-visual/pigx-tx-manager/pom.xml @@ -5,7 +5,7 @@ com.pig4cloud pigx-visual - 2.5.1 + 2.6.0 pigx-tx-manager diff --git a/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/compensate/service/impl/CompensateServiceImpl.java b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/compensate/service/impl/CompensateServiceImpl.java index 16656b1d1..bfc371360 100644 --- a/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/compensate/service/impl/CompensateServiceImpl.java +++ b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/compensate/service/impl/CompensateServiceImpl.java @@ -45,7 +45,6 @@ import org.springframework.stereotype.Service; import java.util.*; import java.util.concurrent.Executor; -import java.util.concurrent.Executors; /** * @author LCN on 2017/11/11 @@ -68,8 +67,8 @@ public class CompensateServiceImpl implements CompensateService { @Autowired private TxManagerService managerService; - - private Executor threadPool = Executors.newFixedThreadPool(20); + @Autowired + private Executor threadPool; @Override public boolean saveCompensateMsg(final TransactionCompensateMsg transactionCompensateMsg) { diff --git a/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/config/ExecutorConfig.java b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/config/ExecutorConfig.java new file mode 100644 index 000000000..196ecb4fc --- /dev/null +++ b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/config/ExecutorConfig.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.manager.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +/** + * @author lengleng + * @date 2019-03-07 + *

+ * LCN线程池配置 + */ +@Configuration +public class ExecutorConfig { + private static final String LCN_SERVICE = "lcn-service-"; + + @Bean + public Executor threadPoolTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + //配置核心线程数 + executor.setCorePoolSize(10); + //配置最大线程数 + executor.setMaxPoolSize(50); + //配置队列大小 + executor.setQueueCapacity(99999); + //配置线程池中的线程的名称前缀 + executor.setThreadNamePrefix(LCN_SERVICE); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + //执行初始化 + executor.initialize(); + return executor; + } +} diff --git a/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/netty/service/impl/NettyServerServiceImpl.java b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/netty/service/impl/NettyServerServiceImpl.java index 5c3525096..e378b6a39 100644 --- a/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/netty/service/impl/NettyServerServiceImpl.java +++ b/pigx-visual/pigx-tx-manager/src/main/java/com/pig4cloud/pigx/manager/netty/service/impl/NettyServerServiceImpl.java @@ -40,29 +40,22 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; /** - *@author LCN on 2017/6/30. + * @author LCN on 2017/6/30. */ @Service public class NettyServerServiceImpl implements NettyServerService, DisposableBean { - - - @Autowired - private NettyService nettyService; - private Logger logger = LoggerFactory.getLogger(NettyServerServiceImpl.class); - private EventLoopGroup bossGroup; private EventLoopGroup workerGroup; - private TxCoreServerHandler txCoreServerHandler; - - private ExecutorService threadPool = Executors.newFixedThreadPool(100); - + @Autowired + private NettyService nettyService; + @Autowired + private Executor threadPool; @Autowired private ConfigReader configReader; @@ -76,20 +69,20 @@ public class NettyServerServiceImpl implements NettyServerService, DisposableBea try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) - .channel(NioServerSocketChannel.class) - .option(ChannelOption.SO_BACKLOG, 100) - .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new ChannelInitializer() { - @Override - public void initChannel(SocketChannel ch) { - ch.pipeline().addLast("timeout", new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS)); + .channel(NioServerSocketChannel.class) + .option(ChannelOption.SO_BACKLOG, 100) + .handler(new LoggingHandler(LogLevel.INFO)) + .childHandler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) { + ch.pipeline().addLast("timeout", new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS)); - ch.pipeline().addLast(new LengthFieldPrepender(4, false)); - ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)); + ch.pipeline().addLast(new LengthFieldPrepender(4, false)); + ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)); - ch.pipeline().addLast(txCoreServerHandler); - } - }); + ch.pipeline().addLast(txCoreServerHandler); + } + }); // Start the server. b.bind(Constants.socketPort); @@ -115,6 +108,5 @@ public class NettyServerServiceImpl implements NettyServerService, DisposableBea @Override public void destroy() { close(); - threadPool.shutdown(); } } diff --git a/pigx-visual/pigx-zipkin/pom.xml b/pigx-visual/pigx-zipkin/pom.xml index dd09a4889..52e449152 100644 --- a/pigx-visual/pigx-zipkin/pom.xml +++ b/pigx-visual/pigx-zipkin/pom.xml @@ -22,7 +22,7 @@ pigx-visual com.pig4cloud - 2.5.1 + 2.6.0 4.0.0 diff --git a/pigx-visual/pom.xml b/pigx-visual/pom.xml index 0f491321b..ddbc4c553 100644 --- a/pigx-visual/pom.xml +++ b/pigx-visual/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 pigx-visual diff --git a/pom.xml b/pom.xml index b46cc56bd..78ad7cf48 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ com.pig4cloud pigx - 2.5.1 + 2.6.0 ${project.artifactId} pom