Commit bb32ade7 by qiuweili123

数据源优化

parent 6d93b5cb
......@@ -5,11 +5,17 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common-core</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -4,6 +4,7 @@ import java.io.Serializable;
/**
* 基础响应对象
*
* @param <T>
*/
public class Response<T> implements Serializable {
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -67,8 +67,13 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -2,7 +2,6 @@ package com.secoo.mall.common.util.date;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.Days;
import java.text.ParseException;
import java.util.Date;
......
package com.secoo.mall.common.util.sys;
import com.secoo.mall.common.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SystemUtils;
......@@ -17,16 +16,16 @@ public class SystemUtil extends SystemUtils {
/**
* 系统唯一标识
*/
public static final String APP_ID = getSystemProperty(APP_ID_KEY,"");
public static final String APP_ID = getSystemProperty(APP_ID_KEY, "");
/**
* 环境变量
*/
public static final String ENV = getSystemProperty(ENV_KEY,"pro");
public static final String ENV = getSystemProperty(ENV_KEY, "pro");
private static String getSystemProperty(final String property,String defaultValue) {
private static String getSystemProperty(final String property, String defaultValue) {
try {
return System.getProperty(property,defaultValue);
return System.getProperty(property, defaultValue);
} catch (final SecurityException e) {
log.error("Caught a SecurityException reading the system property '" + property
+ "'; the SystemUtils property value will default to null.", e);
......
......@@ -54,5 +54,4 @@ public class WebUtil extends WebUtils {
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -21,5 +21,12 @@
<artifactId>apollo-client</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -22,14 +22,14 @@ public class ApolloContextInitializer implements ApplicationContextInitializer<C
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
String appId = environment.getProperty("spring.application.name");
String cacheDir = environment.getProperty("apollo.cacheDir" , "/data/cacheDir");
String namespaces = environment.getProperty("apollo.bootstrap.namespaces" , "application,arch.pub_logs");
String cacheDir = environment.getProperty("apollo.cacheDir", "/data/cacheDir");
String namespaces = environment.getProperty("apollo.bootstrap.namespaces", "application,arch.pub_logs");
if (!StringUtils.isEmpty(appId)) {
System.setProperty("app.id" , appId);
System.setProperty("apollo.cacheDir" , cacheDir);
System.setProperty("apollo.bootstrap.enabled" , "true");
System.setProperty("apollo.bootstrap.eagerLoad.enabled" , "true");
System.setProperty("apollo.bootstrap.namespaces" , namespaces);
System.setProperty("app.id", appId);
System.setProperty("apollo.cacheDir", cacheDir);
System.setProperty("apollo.bootstrap.enabled", "true");
System.setProperty("apollo.bootstrap.eagerLoad.enabled", "true");
System.setProperty("apollo.bootstrap.namespaces", namespaces);
}
}
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -20,5 +20,12 @@
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -49,4 +49,11 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -6,6 +6,7 @@ import org.springframework.util.StringUtils;
/**
* 用于启动后数据加载
*
* @author qianglu
*/
public class MatrixApplicationRunner implements ApplicationRunner {
......@@ -13,7 +14,7 @@ public class MatrixApplicationRunner implements ApplicationRunner {
private String url;
public MatrixApplicationRunner(String url) {
if(!StringUtils.isEmpty(url)){
if (!StringUtils.isEmpty(url)) {
this.url = url;
}
}
......
......@@ -53,7 +53,7 @@ public class MatrixLogListenerConfiguration implements InitializingBean {
String strLevel = config.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("update class {} logger level to {}" , key, strLevel);
logger.info("update class {} logger level to {}", key, strLevel);
}
}
}
......
......@@ -5,7 +5,8 @@
<springProperty scope="context" name="LOG_PATH" source="log.path" defaultValue="/data/logs"/>
<springProperty scope="context" name="MAX_FILE_SIZE" source="log.max_file_size" defaultValue="128MB"/>
<springProperty scope="context" name="MAX_HISTORY" source="log.max_history" defaultValue="7"/>
<springProperty scope="context" name="PATTERN" source="log.pattern" defaultValue="-|%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%X{tid}|%thread|%logger{36}.%M:%L-%msg%n"/>
<springProperty scope="context" name="PATTERN" source="log.pattern"
defaultValue="-|%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%X{tid}|%thread|%logger{36}.%M:%L-%msg%n"/>
<property name="LOG_DIR" value="${LOG_PATH}/${LOG_NAME}/%d{yyyyMMdd}"/>
<property name="CHARSET" value="UTF-8"/>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -49,5 +49,12 @@
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.secoo.mall.datasource.bean;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.datasource.errorcode.DataSourceError;
import com.secoo.mall.datasource.provider.DataSourceProvider;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.AbstractDataSource;
import javax.sql.DataSource;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public abstract class AbsDataSource extends AbstractDataSource implements InitializingBean, DisposableBean {
@Getter
private Map<String, DataSource> dataSourceMap = new HashMap<>();
private static Lock lock = new ReentrantLock();
public AbsDataSource(DataSourceProvider dataSourceProvider) {
this.dataSourceProvider = dataSourceProvider;
}
private DataSourceProvider dataSourceProvider;
@Override
public Connection getConnection() throws SQLException {
return getDataSource().getConnection();
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return getDataSource().getConnection(username, password);
}
/**
* 获取目的数据原
*
* @param dsName
* @return
*/
public DataSource getTargetDataSource(String dsName) {
//如果数据源名字为空默认取一个,此种情况可以允许不使用@SelectDataSource指定数据源
if (getDataSourceMap().containsKey(dsName)) {
return getDataSourceMap().get(dsName);
}
throw new BusinessException(DataSourceError.DATA_SOURCE_NOT_EXIST, dsName);
}
/**
* bean销毁
*
* @throws Exception
*/
@Override
public void destroy() throws Exception {
log.info("datasource start closing ....");
for (Map.Entry<String, DataSource> item : dataSourceMap.entrySet()) {
DataSource dataSource = item.getValue();
Class<? extends DataSource> clazz = dataSource.getClass();
try {
Method closeMethod = clazz.getDeclaredMethod("close");
closeMethod.invoke(dataSource);
} catch (NoSuchMethodException e) {
log.warn("datasource close the datasource named [{}] failed,", item.getKey());
}
}
log.info("datasource all closed success");
}
/**
* 数据加载
*
* @throws Exception
*/
@Override
public void afterPropertiesSet() throws Exception {
Map<String, DataSource> dataSourceMap = dataSourceProvider.loadDataSources();
for (Map.Entry<String, DataSource> dataSourceEntry : dataSourceMap.entrySet()) {
addDataSource(dataSourceEntry.getKey(), dataSourceEntry.getValue());
}
}
public void addDataSource(String dsName, DataSource dataSource) {
lock.lock();
log.info("load dataSources lock {}", dsName);
if (!dataSourceMap.containsKey(dsName)) {
dataSourceMap.put(dsName, dataSource);
}
log.info("load dataSources unlock {}", dsName);
lock.unlock();
}
/**
* todo:动态更新数据源
*
* @param dsName
*/
public void removeDataSource(String dsName) {
lock.lock();
log.info("remove dataSources lock {}", dsName);
if (dataSourceMap.containsKey(dsName)) {
dataSourceMap.remove(dsName);
}
log.info("remove dataSources unlock {}", dsName);
lock.unlock();
}
protected abstract DataSource getDataSource();
}
package com.secoo.mall.datasource.bean;
import org.springframework.jdbc.datasource.AbstractDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public abstract class AbsDynamicDataSource extends AbstractDataSource {
private String dsName;
public AbsDynamicDataSource(String dsName) {
this.dsName = dsName;
}
public String getDsName() {
return dsName;
}
@Override
public Connection getConnection() throws SQLException {
return getDataSource().getConnection();
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return getDataSource().getConnection(username, password);
}
protected abstract DataSource getDataSource();
}
package com.secoo.mall.datasource.bean;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import lombok.Setter;
import com.secoo.mall.datasource.provider.DataSourceProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.MethodUtils;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
/**
* 此数据源为指定数据源,支持xml进行定义
*/
@Slf4j
public class MatrixDataSource implements DataSource, Closeable {
public class MatrixDataSource extends AbsDataSource {
private DataSource dataSource;
public MatrixDataSource() {
private String dsName;
public MatrixDataSource(DataSourceProvider dataSourceProvider) {
super(dataSourceProvider);
}
public MatrixDataSource(DataSourceFactory dataSourceFactory,MatrixDataSourceConfig config) {
dataSource = dataSourceFactory.createDataSouce(config);
}
@Override
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
@Override
public Connection getConnection(String username, String password) throws SQLException {
return dataSource.getConnection(username, password);
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
return dataSource.unwrap(iface);
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return dataSource.isWrapperFor(iface);
}
@Override
public PrintWriter getLogWriter() throws SQLException {
return dataSource.getLogWriter();
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
dataSource.setLogWriter(out);
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
dataSource.setLoginTimeout(seconds);
public MatrixDataSource(String dsName, DataSourceProvider dataSourceProvider) {
super(dataSourceProvider);
this.dsName = dsName;
}
@Override
public int getLoginTimeout() throws SQLException {
return dataSource.getLoginTimeout();
protected DataSource getDataSource() {
return getTargetDataSource(this.dsName);
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return dataSource.getParentLogger();
}
@Override
public void close() throws IOException {
try {
MethodUtils.invokeExactMethod(dataSource, "close");
} catch (Exception e) {
log.error("datasource close error ", e);
}
}
}
package com.secoo.mall.datasource.bean;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.datasource.errorcode.DataSourceError;
import com.secoo.mall.datasource.holder.DataSourceContextHolder;
import com.secoo.mall.datasource.provider.DataSourceProvider;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 此数据源为支持@selectDataSource注解的多数据源使用
*/
@Slf4j
@Data
public class MatrixDynamicDataSource extends AbsDynamicDataSource implements InitializingBean, DisposableBean {
public class MatrixDynamicDataSource extends AbsDataSource {
private Map<String, DataSource> dataSourceMap = new HashMap<>();
private static Lock lock = new ReentrantLock();
@Resource
private DataSourceProvider provider;
public MatrixDynamicDataSource(String dsName) {
super(dsName);
public MatrixDynamicDataSource(DataSourceProvider dataSourceProvider) {
super(dataSourceProvider);
}
@Override
......@@ -40,93 +24,12 @@ public class MatrixDynamicDataSource extends AbsDynamicDataSource implements Ini
* 2.使用了selectDataSource注解
*/
protected DataSource getDataSource() {
String dsName = StringUtil.isEmpty(getDsName()) ? DataSourceContextHolder.getDs() : getDsName();
String dsName = DataSourceContextHolder.getDs();
if (log.isDebugEnabled()) {
log.debug("cur ds is {}", dsName);
}
return getTargetDataSource(dsName);
}
/**
* 获取目的数据原
*
* @param dsName
* @return
*/
private DataSource getTargetDataSource(String dsName) {
//如果数据源名字为空默认取一个,此种情况可以允许不使用@SelectDataSource指定数据源
if (dataSourceMap.containsKey(dsName)) {
return dataSourceMap.get(dsName);
}
throw new BusinessException(DataSourceError.DATA_SOURCE_NOT_EXIST, dsName);
}
/**
* bean销毁
*
* @throws Exception
*/
@Override
public void destroy() throws Exception {
log.info("datasource start closing ....");
for (Map.Entry<String, DataSource> item : dataSourceMap.entrySet()) {
DataSource dataSource = item.getValue();
Class<? extends DataSource> clazz = dataSource.getClass();
try {
Method closeMethod = clazz.getDeclaredMethod("close");
closeMethod.invoke(dataSource);
} catch (NoSuchMethodException e) {
log.warn("datasource close the datasource named [{}] failed,", item.getKey());
}
}
log.info("datasource all closed success");
}
/**
* 数据加载
*
* @throws Exception
*/
@Override
public void afterPropertiesSet() throws Exception {
Map<String, DataSource> dataSourceMap = this.provider.loadDataSources();
for (Map.Entry<String, DataSource> dataSourceEntry : dataSourceMap.entrySet()) {
addDataSource(dataSourceEntry.getKey(), dataSourceEntry.getValue());
}
}
public void addDataSource(String dsName, DataSource dataSource) {
lock.lock();
log.info("load dataSources lock {}", dsName);
if (!dataSourceMap.containsKey(dsName)) {
dataSourceMap.put(dsName, dataSource);
}
log.info("load dataSources unlock {}", dsName);
lock.unlock();
}
/**
* todo:动态更新数据源
*
* @param dsName
*/
public void removeDataSource(String dsName) {
lock.lock();
log.info("remove dataSources lock {}", dsName);
if (dataSourceMap.containsKey(dsName)) {
dataSourceMap.remove(dsName);
}
log.info("remove dataSources unlock {}", dsName);
lock.unlock();
}
}
package com.secoo.mall.datasource.config;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import lombok.Data;
@Data
......
......@@ -18,7 +18,7 @@ public interface DataSourceConstant {
/**
* 阿波罗数据库的配置命名空间
*/
String DB_NAMESPACE = "db.config";
String DB_NAMESPACE = "arch.db_config";
/**
* 属性配置分割符
*/
......
......@@ -4,8 +4,8 @@ import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import javax.sql.DataSource;
public interface DataSourceFactory<T extends DataSource,CONFIG extends MatrixDataSourceConfig> {
public interface DataSourceFactory<T extends DataSource, CONFIG extends MatrixDataSourceConfig> {
T createDataSouce( CONFIG config);
T createDataSouce(CONFIG config);
}
......@@ -10,4 +10,4 @@ public class MatrixDataSourceProperties extends MatrixDataSourceConfig {
public MatrixDataSourceProperties() {
}
}
}
......@@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.MethodUtils;
import javax.sql.DataSource;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -25,7 +24,7 @@ import java.util.stream.Collectors;
* 从Apollo配置中心进行加载
*/
@Slf4j
public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends AbsDataSourceProvider<T> {
public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends AbsDataSourceProvider<T> {
/*
*/
......@@ -37,6 +36,7 @@ public class ApolloDataSourceProvider<T extends MatrixDataSourceConfig> extends
*/
@Override
protected List<T> getDataSourceProperties() {
log.info("load config from apollo...");
Config appConfig = ConfigService.getConfig(DataSourceConstant.DB_NAMESPACE);
Set<String> propertyNames = appConfig.getPropertyNames();
List<T> list = Lists.newArrayList();
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -20,6 +20,12 @@
<artifactId>druid</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.secoo.mall.datasource.factory;
import com.alibaba.druid.pool.DruidDataSource;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import com.secoo.mall.datasource.properties.MatrixDruidDataSourceProperties;
import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;
......@@ -14,7 +12,7 @@ public class DruidDataSourceFactory extends AbsDataSourceFactory<DruidDataSource
private final String duridPreFix = "druid.";
@Override
protected DruidDataSource convertAndCreate(MatrixDruidDataSourceProperties config) {
protected DruidDataSource convertAndCreate(MatrixDruidDataSourceProperties config) {
Properties properties = new Properties();
properties.setProperty(duridPreFix + "name", config.getName());
......
package com.secoo.mall.datasource.properties;
import com.secoo.mall.datasource.config.MatrixDataSourceConfig;
import lombok.Data;
@Data
public class MatrixDruidDataSourceProperties extends MatrixDataSourceProperties {
public static final String PREFIX = MatrixDataSourceProperties.PREFIX+".druid";
public static final String PREFIX = MatrixDataSourceProperties.PREFIX + ".druid";
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -21,7 +21,7 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -22,5 +22,11 @@
<artifactId>matrix-datasource-druid</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.secoo.mall.mybatis.bean;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.mybatis.config.MatrixMybatisConfig;
import com.secoo.mall.mybatis.config.MatrixMybatisGlobalConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import java.io.IOException;
@Slf4j
public class MatrixMybatisSqlSessionFactoryBean extends MybatisSqlSessionFactoryBean {
public MatrixMybatisSqlSessionFactoryBean(){
public MatrixMybatisSqlSessionFactoryBean() {
}
......@@ -16,11 +20,24 @@ public class MatrixMybatisSqlSessionFactoryBean extends MybatisSqlSessionFactory
this.setConfiguration(matrixMybatisConfig);
this.setGlobalConfig(matrixMybatisGlobalConfig);
this.setTypeAliasesPackage(matrixMybatisConfig.getBeanAliasPackages());
try {
this.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(matrixMybatisConfig.getResourceClassPath()));
} catch (IOException e) {
e.printStackTrace();
String resourceClassPath = matrixMybatisConfig.getResourceClassPath();
/**
* 存在此配置
*/
if (StringUtil.isNotEmpty(resourceClassPath)) {
/**
* 仅仅判断根classpath是否存在
*/
String rootPath = resourceClassPath.split("/")[1];
ClassPathResource resource = new ClassPathResource(rootPath);
if (resource.exists()) {
try {
this.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(resourceClassPath));
} catch (IOException e) {
log.error("load resourceClassPath error ", e);
}
}
}
}
}
}
......@@ -2,37 +2,38 @@ package com.secoo.mall.mybatis.config;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.baomidou.mybatisplus.extension.toolkit.PackageHelper;
import com.secoo.mall.common.constant.CommonConstant;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.common.util.sys.SystemUtil;
import com.secoo.mall.mybatis.interceptor.MatrixPerformanceInterceptor;
import lombok.Data;
import org.apache.ibatis.type.JdbcType;
@Data
public class MatrixMybatisConfig extends MybatisConfiguration {
private static final String DEFAULT_BEAN_ALIAS_PACKAGES = StringUtil.join(PackageHelper.convertTypeAliasesPackage("com.secoo.mall.**.bean.domain"), ",");
private static final String DEFAULT_RESOURCE_CLASSPATH = "/mybatis/*.xml";
private String beanAliasPackages = StringUtil.join(PackageHelper.convertTypeAliasesPackage("com.secoo.mall.**.bean.domain"), ",");
private String resourceClassPath = "classpath:mybatis/*.xml";
private String beanAliasPackages = DEFAULT_BEAN_ALIAS_PACKAGES;
private String resourceClassPath = DEFAULT_RESOURCE_CLASSPATH;
public MatrixMybatisConfig() {
if (!SystemUtil.ENV.equals(CommonConstant.Env.PRO)) {
this.addInterceptor(new PerformanceInterceptor());
this.addInterceptor(new MatrixPerformanceInterceptor());
}
//空值转为null
this.setJdbcTypeForNull(JdbcType.NULL);
// 驼峰转下划线
this.setMapUnderscoreToCamelCase(true);
//分页插件
//分页插件
this.addInterceptor(new PaginationInterceptor());
this.setBeanAliasPackages(beanAliasPackages);
this.setResourceClassPath(resourceClassPath);
}
public MatrixMybatisConfig(String beanAliasPackages,String resourceClassPath) {
this();
public MatrixMybatisConfig(String beanAliasPackages, String resourceClassPath) {
this.setBeanAliasPackages(beanAliasPackages);
this.setResourceClassPath(resourceClassPath);
}
......
......@@ -2,7 +2,6 @@ package com.secoo.mall.mybatis.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
......
/*
* Copyright (c) 2011-2014, hubin (jobob@qq.com).
* <p>
* Licensed 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 com.secoo.mall.mybatis.interceptor;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
import com.mysql.cj.jdbc.ClientPreparedStatement;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.ResultHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Statement;
import java.util.*;
/**
* 性能分析拦截器,用于输出每条 SQL 语句及其执行时间
*/
@Intercepts({
@Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
@Signature(type = StatementHandler.class, method = "update", args = {Statement.class}),
@Signature(type = StatementHandler.class, method = "batch", args = {Statement.class})
})
public class MatrixPerformanceInterceptor implements Interceptor {
private static final Log logger = LogFactory.getLog(MatrixPerformanceInterceptor.class);
private static final String DruidPooledPreparedStatement = "com.alibaba.druid.pool.DruidPooledPreparedStatement";
private static final String T4CPreparedStatement = "oracle.jdbc.driver.T4CPreparedStatement";
private static final String OraclePreparedStatementWrapper = "oracle.jdbc.driver.OraclePreparedStatementWrapper";
/**
* SQL 执行最大时长,超过自动停止运行,有助于发现问题。
*/
@Setter
@Getter
@Accessors(chain = true)
private long maxTime = 0;
/**
* SQL 是否格式化
*/
@Setter
@Getter
@Accessors(chain = true)
private boolean format = false;
/**
* 是否写入日志文件
* <p>true 写入日志文件,不阻断程序执行!</p>
* <p>超过设定的最大执行时长异常提示!</p>
*/
@Setter
@Getter
@Accessors(chain = true)
private boolean writeInLog = false;
private Method oracleGetOriginalSqlMethod;
private Method druidGetSQLMethod;
@Override
public Object intercept(Invocation invocation) throws Throwable {
Statement statement;
Object firstArg = invocation.getArgs()[0];
if (Proxy.isProxyClass(firstArg.getClass())) {
statement = (Statement) SystemMetaObject.forObject(firstArg).getValue("h.statement");
} else {
statement = (Statement) firstArg;
}
MetaObject stmtMetaObj = SystemMetaObject.forObject(statement);
try {
statement = (Statement) stmtMetaObj.getValue("stmt.statement");
} catch (Exception e) {
// do nothing
}
if (stmtMetaObj.hasGetter("delegate")) {
//Hikari
try {
statement = (Statement) stmtMetaObj.getValue("delegate");
} catch (Exception ignored) {
}
}
String originalSql = null;
String stmtClassName = statement.getClass().getName();
if (DruidPooledPreparedStatement.equals(stmtClassName)) {
try {
if (statement instanceof ClientPreparedStatement) {
originalSql = ClientPreparedStatement.class.cast(Statement.class).asSql();
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (T4CPreparedStatement.equals(stmtClassName)
|| OraclePreparedStatementWrapper.equals(stmtClassName)) {
try {
if (oracleGetOriginalSqlMethod != null) {
Object stmtSql = oracleGetOriginalSqlMethod.invoke(statement);
if (stmtSql instanceof String) {
originalSql = (String) stmtSql;
}
} else {
Class<?> clazz = Class.forName(stmtClassName);
oracleGetOriginalSqlMethod = getMethodRegular(clazz, "getOriginalSql");
if (oracleGetOriginalSqlMethod != null) {
//OraclePreparedStatementWrapper is not a public class, need set this.
oracleGetOriginalSqlMethod.setAccessible(true);
if (null != oracleGetOriginalSqlMethod) {
Object stmtSql = oracleGetOriginalSqlMethod.invoke(statement);
if (stmtSql instanceof String) {
originalSql = (String) stmtSql;
}
}
}
}
} catch (Exception e) {
//ignore
}
}
if (originalSql == null) {
originalSql = statement.toString();
}
originalSql = originalSql.replaceAll("[\\s]+", StringPool.SPACE);
int index = indexOfSqlStart(originalSql);
if (index > 0) {
originalSql = originalSql.substring(index);
}
// 计算执行 SQL 耗时
long start = SystemClock.now();
Object result = invocation.proceed();
long timing = SystemClock.now() - start;
// 格式化 SQL 打印执行结果
Object target = PluginUtils.realTarget(invocation.getTarget());
MetaObject metaObject = SystemMetaObject.forObject(target);
MappedStatement ms = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
StringBuilder formatSql = new StringBuilder()
.append(" Time:").append(timing)
.append(" ms - ID:").append(ms.getId())
.append(StringPool.NEWLINE).append("Execute SQL:")
.append(SqlUtils.sqlFormat(originalSql, format)).append(StringPool.NEWLINE);
if (this.isWriteInLog()) {
if (this.getMaxTime() >= 1 && timing > this.getMaxTime()) {
logger.error(formatSql.toString());
} else {
logger.debug(formatSql.toString());
}
} else {
System.err.println(formatSql.toString());
Assert.isFalse(this.getMaxTime() >= 1 && timing > this.getMaxTime(),
" The SQL execution time is too large, please optimize ! ");
}
return result;
}
@Override
public Object plugin(Object target) {
if (target instanceof StatementHandler) {
return Plugin.wrap(target, this);
}
return target;
}
@Override
public void setProperties(Properties prop) {
String maxTime = prop.getProperty("maxTime");
String format = prop.getProperty("format");
if (StringUtils.isNotEmpty(maxTime)) {
this.maxTime = Long.parseLong(maxTime);
}
if (StringUtils.isNotEmpty(format)) {
this.format = Boolean.valueOf(format);
}
}
/**
* 获取此方法名的具体 Method
*
* @param clazz class 对象
* @param methodName 方法名
* @return 方法
*/
public Method getMethodRegular(Class<?> clazz, String methodName) {
if (Object.class.equals(clazz)) {
return null;
}
for (Method method : clazz.getDeclaredMethods()) {
if (method.getName().equals(methodName)) {
return method;
}
}
return getMethodRegular(clazz.getSuperclass(), methodName);
}
/**
* 获取sql语句开头部分
*
* @param sql ignore
* @return ignore
*/
private int indexOfSqlStart(String sql) {
String upperCaseSql = sql.toUpperCase();
Set<Integer> set = new HashSet<>();
set.add(upperCaseSql.indexOf("SELECT "));
set.add(upperCaseSql.indexOf("UPDATE "));
set.add(upperCaseSql.indexOf("INSERT "));
set.add(upperCaseSql.indexOf("DELETE "));
set.remove(-1);
if (CollectionUtils.isEmpty(set)) {
return -1;
}
List<Integer> list = new ArrayList<>(set);
list.sort(Comparator.naturalOrder());
return list.get(0);
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -35,4 +35,12 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.secoo.mall.mybatis.spring.boot.autoconfigure;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration;
import com.secoo.mall.datasource.bean.MatrixDataSource;
import com.secoo.mall.datasource.bean.MatrixDynamicDataSource;
import com.secoo.mall.datasource.factory.DataSourceFactory;
import com.secoo.mall.datasource.factory.DruidDataSourceFactory;
import com.secoo.mall.datasource.provider.ApolloDruidDataSourceProvider;
......@@ -22,11 +20,9 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
......@@ -44,7 +40,7 @@ public class MatrixMybatisAutoConfiguration {
log.info("Init MatrixDataSouceAutoConfiguration");
}
@Value("${config.app.security.accessToken}")
@Value("${config.app.security.accessToken:jp32mbwQkxrygEAjNRsi}")
private String acccessToken;
......@@ -62,8 +58,8 @@ public class MatrixMybatisAutoConfiguration {
*/
@Bean
@ConditionalOnMissingBean(DataSource.class)
public DataSource dataSource() {
return new MatrixDynamicDataSource("default");
public DataSource dataSource(DataSourceProvider dataSourceProvider) {
return new MatrixDataSource("default", dataSourceProvider);
}
@Bean
......
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.mall.mybatis.spring.boot.autoconfigure.MatrixMybatisAutoConfiguration
\ No newline at end of file
com.secoo.mall.mybatis.spring.boot.autoconfigure.MatrixMybatisAutoConfiguration
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
\ No newline at end of file
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -25,12 +25,12 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-core</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
......@@ -46,7 +46,7 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-druid</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -21,4 +21,12 @@
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -44,4 +44,11 @@
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -26,5 +26,11 @@
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -6,7 +6,7 @@
<groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
<packaging>pom</packaging>
......@@ -48,62 +48,62 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>monitor-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>config-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>redis-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>mongodb-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>elasticsearch-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>protocol-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>rocketmq-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>openfeign-starter</artifactId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
<dependency>
......@@ -290,6 +290,20 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -65,5 +65,11 @@
<targetPath>META-INF/resources/</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -7,7 +7,6 @@ import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.processor.ExceptionProcessor;
import com.secoo.mall.common.util.log.LoggerUtil;
import com.secoo.mall.common.util.response.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
......@@ -37,13 +36,13 @@ public class ProtocolExceptionHandler {
LoggerUtil.info(msg);
return ResponseUtil.getFailResponse(ex.getCode(), msg);
} catch (SystemInternalException ex) {
LoggerUtil.warn("WarnError",ex);
LoggerUtil.warn("WarnError", ex);
return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg());
} catch (BusinessException ex) {
LoggerUtil.warn("BizError:"+getMsg(ex),ex);
LoggerUtil.warn("BizError:" + getMsg(ex), ex);
return ResponseUtil.getFailResponse(ex.getCode(), getMsg(ex));
} catch (Exception ex) {
LoggerUtil.error("Error:",ex);
LoggerUtil.error("Error:", ex);
return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg());
}
......
package com.secoo.mall.common.processor;
import com.secoo.mall.common.core.errorcode.ErrorCode;
import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.util.spring.SpringUtil;
import java.util.Map;
public interface ExceptionProcessor {
/**
* 处理异常
*
* @param e
* @return
*/
......
......@@ -2,7 +2,7 @@
<html>
<head>
<title>appms</title>
<meta charset="utf-8" />
<meta charset="utf-8"/>
<style>@charset "UTF-8";
html,
body,
......@@ -222,6 +222,7 @@
page-break-inside: avoid;
}
}
html,
body {
height: 100%;
......@@ -268,6 +269,7 @@
padding-left: 70px;
flex-grow: 1;
}
.content-right h2:target {
padding-top: 80px;
}
......@@ -319,6 +321,7 @@
left: 0;
right: 0;
}
.m-header .title {
font-size: 22px;
color: #fff;
......@@ -330,6 +333,7 @@
line-height: 56px;
border: none;
}
.m-header .nav {
color: #fff;
font-size: 16px;
......@@ -337,12 +341,14 @@
right: 32px;
top: 0;
}
.m-header .nav a {
color: #fff;
margin-left: 16px;
padding: 8px;
transition: color .2s;
}
.m-header .nav a:hover {
color: #59d69d;
}
......@@ -358,26 +364,43 @@
</head>
<body>
<div class="m-header">
<a href="#" style="display: inherit;"><svg class="svg" width="32px" height="32px" viewBox="0 0 64 64" version="1.1"><title>Icon</title><desc>Created with Sketch.</desc><defs><linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"><stop stop-color="#FFFFFF" offset="0%"></stop><stop stop-color="#F2F2F2" offset="100%"></stop>
</linearGradient>
<a href="#" style="display: inherit;">
<svg class="svg" width="32px" height="32px" viewBox="0 0 64 64" version="1.1"><title>Icon</title>
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
<stop stop-color="#FFFFFF" offset="0%"></stop>
<stop stop-color="#F2F2F2" offset="100%"></stop>
</linearGradient>
</a>
<a href="#"><h1 class="title">接口文档管理说明</h1></a>
</div>
<div class="g-doc">
<div class="table-of-contents"><ul><li><a href="#">功能列表</a><ul><li><a href="#20u6839u636eidu5220u96640a3ca20id3d20u6839u636eidu5220u96643e203ca3e"> 介绍
</a><a id="介绍"> </a></li>
<li><a href="#u521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb0a3ca20id3du521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb3e203ca3e">导出数据
</a><a id="导出数据"> </a></li><li><a href="#u6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f0a3ca20id3du6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f3e203ca3e">导入数据
</a><a id="导入数据"> </a></li>
</ul></li></ul></div>
<div class="table-of-contents">
<ul>
<li><a href="#">功能列表</a>
<ul>
<li><a href="#20u6839u636eidu5220u96640a3ca20id3d20u6839u636eidu5220u96643e203ca3e"> 介绍
</a><a id="介绍"> </a></li>
<li>
<a href="#u521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb0a3ca20id3du521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb3e203ca3e">导出数据
</a><a id="导出数据"> </a></li>
<li>
<a href="#u6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f0a3ca20id3du6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f3e203ca3e">导入数据
</a><a id="导入数据"> </a></li>
</ul>
</li>
</ul>
</div>
<div id="right" class="content-right">
<h2 id="20u6839u636eidu5220u96640a3ca20id3d20u6839u636eidu5220u96643e203ca3e">介绍
<a id="介绍"> </a></h2>
<p></p>
<h3 id="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;为方便大家管理接口,提高接口编写、团队开发效率,通过封装swagger,支持web、dubbo接口的导出。导出后,为方便大家集中管理,
请登录<a href="https://apims.siku.cn" target="_blank">http://apims.siku.cn</a>,进行导入!</h3>
<h2 id="u521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb0a3ca20id3du521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb3e203ca3e">导出数据
<h2 id="u521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb0a3ca20id3du521bu5efau9879u76eeu7528u6237u5bf9u5e94u5173u7cfb3e203ca3e">
导出数据
<a id="导出数据"> </a></h2>
<p></p>
<h3 id="-4">导出web接口</h3>
......@@ -387,7 +410,8 @@
<p><strong>说明:</strong> 由Dubbbo生成的接口</p>
<p>点击<strong><a href="../swagger-dubbo/api-docs">此处</a></strong> 导出
<h2 id="u6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f0a3ca20id3du6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f3e203ca3e">导入数据
<h2 id="u6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f0a3ca20id3du6839u636eu5e94u7528idu67e5u8be2u7528u6237u4fe1u606f3e203ca3e">
导入数据
<a id="导入数据"> </a></h2>
<p></p>
<h3 id="-7">登录接口管理平台,选择项目后,依次选择数据管理>swagger。</h3>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -31,4 +31,11 @@
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -19,7 +19,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
public class MatrixeRedisAutoConfiguration {
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisSerializer stringSerializer = new StringRedisSerializer();
RedisTemplate<String, String> redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
......
......@@ -6,7 +6,8 @@ import org.springframework.data.redis.core.*;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
......@@ -170,8 +171,6 @@ public class MatrixRedisClusterUtils {
}
/**
* 为哈希表 key 中的域 field 的值加上增量 increment
*
......@@ -196,8 +195,6 @@ public class MatrixRedisClusterUtils {
}
/**
* 从缓存中取得字符串数据
*
......@@ -237,6 +234,7 @@ public class MatrixRedisClusterUtils {
/**
* 返回集合 key 中的所有成员
* opsForSet().members(key)
*
* @param key set名
*/
public static Set<String> members(String key) {
......@@ -251,7 +249,7 @@ public class MatrixRedisClusterUtils {
*/
public static Long srem(String key, String... member) {
return cacheUtils.redisTemplate.opsForSet().remove(key,member);
return cacheUtils.redisTemplate.opsForSet().remove(key, member);
}
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.1.11.RELEASE</version>
<version>1.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......@@ -16,5 +16,13 @@
<artifactId>rocketmq-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class MatrixListenerContainerConfiguration implements BeanPostProcessor {
if (bean instanceof DefaultRocketMQListenerContainer) {
DefaultRocketMQListenerContainer container = (DefaultRocketMQListenerContainer) bean;
if (log.isDebugEnabled()) {
log.debug("MatrixListenerContainerConfiguration config setDelayLevelWhenNextConsume value:{}" , delayLevel);
log.debug("MatrixListenerContainerConfiguration config setDelayLevelWhenNextConsume value:{}", delayLevel);
}
container.setDelayLevelWhenNextConsume(delayLevel);
container.getConsumer().getDefaultMQPushConsumerImpl().registerConsumeMessageHook(matrixConsumeHook());
......
......@@ -37,11 +37,11 @@ public class MatrixRocketMQAutoConfiguration {
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
producer = new MartixProducer(groupName, new AclClientRPCHook(new SessionCredentials(ak, sk)),
rocketMQProperties.getProducer().isEnableMsgTrace(),
rocketMQProperties.getProducer().getCustomizedTraceTopic(),matrixProducerHook);
rocketMQProperties.getProducer().getCustomizedTraceTopic(), matrixProducerHook);
producer.setVipChannelEnabled(false);
} else {
producer = new MartixProducer(groupName, rocketMQProperties.getProducer().isEnableMsgTrace(),
rocketMQProperties.getProducer().getCustomizedTraceTopic(),matrixProducerHook);
rocketMQProperties.getProducer().getCustomizedTraceTopic(), matrixProducerHook);
}
producer.setNamesrvAddr(nameServer);
if (!StringUtils.isEmpty(accessChannel)) {
......@@ -57,5 +57,4 @@ public class MatrixRocketMQAutoConfiguration {
}
}
......@@ -25,7 +25,7 @@ public class MatrixConsumeHook implements ConsumeMessageHook {
@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
try {
log.info("consumeMessageAfter,Succ:{} Topic:{},TraceContext:{},ConsumerGroup:{}",context.isSuccess(),context.getMq().getTopic(),context.getMqTraceContext(),context.getConsumerGroup());
log.info("consumeMessageAfter,Succ:{} Topic:{},TraceContext:{},ConsumerGroup:{}", context.isSuccess(), context.getMq().getTopic(), context.getMqTraceContext(), context.getConsumerGroup());
} catch (Exception e) {//防灾冗余
}
}
......
......@@ -25,7 +25,7 @@ public class MatrixProducerHook implements SendMessageHook {
@Override
public void sendMessageAfter(SendMessageContext context) {
try {
log.info("sendMessageAfter,TraceContext:{},Mode:{},Topic:{},Targs:{},ProducerGroup:{},BrokerAddr:{},Namespace:{},Exception:{}",context.getMqTraceContext(), context.getCommunicationMode().name(), context.getMessage().getTopic(), context.getMessage().getTags(), context.getProducerGroup(), context.getBrokerAddr(), context.getNamespace(), context.getException()==null?null:context.getException().getMessage());
log.info("sendMessageAfter,TraceContext:{},Mode:{},Topic:{},Targs:{},ProducerGroup:{},BrokerAddr:{},Namespace:{},Exception:{}", context.getMqTraceContext(), context.getCommunicationMode().name(), context.getMessage().getTopic(), context.getMessage().getTags(), context.getProducerGroup(), context.getBrokerAddr(), context.getNamespace(), context.getException() == null ? null : context.getException().getMessage());
} catch (Exception e) {//防灾冗余}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment