Commit b8a9575f by 共享中心代码生成

Merge branch 'feature_protocol' into 'master'

Feature protocol

See merge request mall/arch/matrix!63
parents 589d5ff3 71b4ac78
...@@ -4,6 +4,7 @@ Matrix (矩阵)是一套组件增强套件,包括redis、rocketmq等中间件 ...@@ -4,6 +4,7 @@ Matrix (矩阵)是一套组件增强套件,包括redis、rocketmq等中间件
# 组件 # 组件
- [common-core](common-core/README.md):提供通用bean,核心注解,定义通用业务异常。 - [common-core](common-core/README.md):提供通用bean,核心注解,定义通用业务异常。
- [common-util](common-util/README.md): 提供BeanUtil,BeanChecker、CollectionUtil等工具类。 - [common-util](common-util/README.md): 提供BeanUtil,BeanChecker、CollectionUtil等工具类。
- [config-starter](config-starter/README.md): 配置中心统一分装 - [config-starter](config-starter/README.md): 配置中心统一分装
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
package com.secoo.mall.common.core.serializer;
public interface MatrixSerializer<T> {
byte[] serialize(T data);
T deserialize(byte[] data);
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -46,6 +46,10 @@ ...@@ -46,6 +46,10 @@
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
...@@ -55,6 +59,7 @@ ...@@ -55,6 +59,7 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
......
package com.secoo.mall.common.serializer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.util.IOUtils;
import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.core.serializer.MatrixSerializer;
import lombok.Setter;
public class FastJsonSerializer<T> implements MatrixSerializer<T> {
@Setter
private FastJsonConfig fastJsonConfig = new FastJsonConfig();
private Class<T> type;
public FastJsonSerializer(Class<T> type) {
this.type = type;
}
private final static ParserConfig defaultRedisConfig = new ParserConfig();
static {
defaultRedisConfig.setAutoTypeSupport(true);
}
public byte[] serialize(T object) {
if (object == null) {
return new byte[0];
}
try {
return JSON.toJSONBytes(object, SerializerFeature.WriteClassName);
} catch (Exception ex) {
throw new SystemInternalException();
}
}
public T deserialize(byte[] bytes) {
if (bytes == null || bytes.length == 0) {
return null;
}
try {
return JSON.parseObject(new String(bytes, IOUtils.UTF8), type, defaultRedisConfig);
} catch (Exception ex) {
throw new SystemInternalException();
}
}
}
package com.secoo.mall.common.serializer;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.secoo.mall.common.core.serializer.MatrixSerializer;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayOutputStream;
@Slf4j
public class KryoSerializer<T> implements MatrixSerializer<T> {
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static final ThreadLocal<Kryo> kryos = ThreadLocal.withInitial(Kryo::new);
private Class<T> clazz;
public KryoSerializer(Class<T> clazz) {
super();
this.clazz = clazz;
}
@Override
public byte[] serialize(T t) {
if (t == null) {
return EMPTY_BYTE_ARRAY;
}
Kryo kryo = kryos.get();
kryo.setReferences(false);
kryo.register(clazz);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos)) {
kryo.writeClassAndObject(output, t);
output.flush();
return baos.toByteArray();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return EMPTY_BYTE_ARRAY;
}
@Override
public T deserialize(byte[] bytes) {
if (bytes == null || bytes.length <= 0) {
return null;
}
Kryo kryo = kryos.get();
kryo.setReferences(false);
kryo.register(clazz);
try (Input input = new Input(bytes)) {
return (T) kryo.readClassAndObject(input);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
# 介绍
elasticsearch-starter。
# 特点
-
# 开始
- 添加依赖
- Maven:需要在自己项目的pom.xml增加,以下配置。
**注意:前置条件需要依赖项目中需要设置matrix的parent**
```xml
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>elasticsearch-starter</artifactId>
</dependency>
```
# 示例
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,11 +5,29 @@ ...@@ -5,11 +5,29 @@
<parent> <parent>
<artifactId>matrix-bigdata</artifactId> <artifactId>matrix-bigdata</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-bigdata-hbase-starter</artifactId> <artifactId>matrix-bigdata-hbase-starter</artifactId>
<dependencies>
<!-- hbase -->
<dependency>
<groupId>com.aliyun.hbase</groupId>
<artifactId>alihbase-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
@org.springframework.context.annotation.Configuration
@ConditionalOnClass({HbaseTemplate.class, Configuration.class})
public class HbaseAutoConfiguration {
// @Bean
// @ConditionalOnMissingBean(Configuration.class)
// public Configuration hBaseConfiguration(Environment env) {
// String zookeeperQuorum = env.getProperty("hbase.zookeeper.quorum");
// String zookeeperClientPort = env.getProperty("hbase.zookeeper.property.clientPort");
// String zookeeperZnodeParent = env.getProperty("hbase.zookeeper.znode.parent");
// String clientRetriesNumber = env.getProperty("hbase.client.retries.number");
// String threadsMax = env.getProperty("hbase.hconnection.threads.max");
// String threadsKeepalivetime = env.getProperty("hbase.hconnection.threads.keepalivetime");
// String clientMaxTotalTasks = env.getProperty("hbase.client.max.total.tasks");
//
// Assert.notNull(zookeeperQuorum, "zk address is null!!!");
// Assert.notNull(zookeeperClientPort, "zk port is null!!!");
//
// Configuration configuration = HBaseConfiguration.create();
// configuration.set(HConstants.ZOOKEEPER_QUORUM, zookeeperQuorum);
// configuration.set(HConstants.ZOOKEEPER_CLIENT_PORT, zookeeperClientPort);
// if (StringUtils.isNotEmpty(zookeeperZnodeParent))
// configuration.set(HConstants.ZOOKEEPER_ZNODE_PARENT, zookeeperZnodeParent);
// if (StringUtils.isNotEmpty(clientRetriesNumber))
// configuration.set(HConstants.HBASE_CLIENT_RETRIES_NUMBER, clientRetriesNumber);
// if (threadsMax != null) configuration.set("hbase.hconnection.threads.max", threadsMax);
// if (threadsKeepalivetime != null)
// configuration.set("hbase.hconnection.threads.keepalivetime", threadsKeepalivetime);
// if (clientMaxTotalTasks != null)
// configuration.set("hbase.config.hbase.client.max.total.tasks", clientMaxTotalTasks);
// return configuration;
// }
@Bean
@ConditionalOnMissingBean(Configuration.class)
public Configuration hBaseConfiguration(Environment env) {
String zookeeperQuorum = env.getProperty("hbase.zookeeper.quorum");
Assert.notNull(zookeeperQuorum, "zk address is null!!!");
Configuration configuration = HBaseConfiguration.create();
configuration.set(HConstants.ZOOKEEPER_QUORUM, zookeeperQuorum);
return configuration;
}
@Bean
@ConditionalOnMissingBean(HbaseTemplate.class)
public HbaseTemplate hbaseTemplate(Configuration configuration) {
return new HbaseTemplate(configuration);
}
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Scan;
import java.util.List;
public interface HbaseOperations {
<T> T execute(String tableName, TableCallback<T> mapper);
/**
* Scans the target table, using the given column family.
* The content is processed row by row by the given action, returning a list of domain objects.
*
* @param tableName target table
* @param family column family
* @param <T> action type
* @return a list of objects mapping the scanned rows
*/
<T> List<T> find(String tableName, String family, final RowMapper<T> mapper);
/**
* Scans the target table, using the given column family.
* The content is processed row by row by the given action, returning a list of domain objects.
*
* @param tableName target table
* @param family column family
* @param qualifier column qualifier
* @param <T> action type
* @return a list of objects mapping the scanned rows
*/
<T> List<T> find(String tableName, String family, String qualifier, final RowMapper<T> mapper);
/**
* Scans the target table using the given {@link Scan} object. Suitable for maximum control over the scanning
* process.
* The content is processed row by row by the given action, returning a list of domain objects.
*
* @param tableName target table
* @param scan table scanner
* @param <T> action type
* @return a list of objects mapping the scanned rows
*/
<T> List<T> find(String tableName, final Scan scan, final RowMapper<T> mapper);
/**
* Gets an individual row from the given table. The content is mapped by the given action.
*
* @param tableName target table
* @param rowName row name
* @param mapper row mapper
* @param <T> mapper type
* @return object mapping the target row
*/
<T> T get(String tableName, String rowName, final RowMapper<T> mapper);
/**
* Gets an individual row from the given table. The content is mapped by the given action.
*
* @param tableName target table
* @param rowName row name
* @param familyName column family
* @param mapper row mapper
* @param <T> mapper type
* @return object mapping the target row
*/
<T> T get(String tableName, String rowName, String familyName, final RowMapper<T> mapper);
/**
* Gets an individual row from the given table. The content is mapped by the given action.
*
* @param tableName target table
* @param rowName row name
* @param familyName family
* @param qualifier column qualifier
* @param mapper row mapper
* @param <T> mapper type
* @return object mapping the target row
*/
<T> T get(String tableName, final String rowName, final String familyName, final String qualifier, final RowMapper<T> mapper);
/**
* 执行put update or delete
*
* @param tableName
* @param action
*/
void execute(String tableName, MutatorCallback action);
/**
* @param tableName
* @param mutation
*/
void saveOrUpdate(String tableName, Mutation mutation);
/**
* @param tableName
* @param mutations
*/
void saveOrUpdates(String tableName, List<Mutation> mutations);
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
public class HbaseSystemException extends RuntimeException {
public HbaseSystemException(Exception cause) {
super(cause.getMessage(), cause);
}
public HbaseSystemException(Throwable throwable) {
super(throwable.getMessage(), throwable);
}
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.BufferedMutator;
import org.apache.hadoop.hbase.client.BufferedMutatorParams;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.util.Assert;
import org.springframework.util.StopWatch;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class HbaseTemplate implements HbaseOperations, DisposableBean {
private static final Logger LOGGER = LoggerFactory.getLogger(HbaseTemplate.class);
private Configuration configuration;
private volatile Connection connection;
public HbaseTemplate(Configuration configuration) {
this.setConfiguration(configuration);
Assert.notNull(configuration, " a valid configuration is required");
}
@Override
public <T> T execute(String tableName, TableCallback<T> action) {
Assert.notNull(action, "Callback object must not be null");
Assert.notNull(tableName, "No table specified");
StopWatch sw = new StopWatch();
sw.start();
Table table = null;
try {
table = this.getConnection().getTable(TableName.valueOf(tableName));
return action.doInTable(table);
} catch (Throwable throwable) {
throw new HbaseSystemException(throwable);
} finally {
if (null != table) {
try {
table.close();
sw.stop();
} catch (IOException e) {
LOGGER.error("hbase资源释放失败");
}
}
}
}
@Override
public <T> List<T> find(String tableName, String family, final RowMapper<T> action) {
Scan scan = new Scan();
scan.setCaching(5000);
scan.addFamily(Bytes.toBytes(family));
return this.find(tableName, scan, action);
}
@Override
public <T> List<T> find(String tableName, String family, String qualifier, final RowMapper<T> action) {
Scan scan = new Scan();
scan.setCaching(5000);
scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
return this.find(tableName, scan, action);
}
@Override
public <T> List<T> find(String tableName, final Scan scan, final RowMapper<T> action) {
return this.execute(tableName, new TableCallback<List<T>>() {
@Override
public List<T> doInTable(Table table) throws Throwable {
int caching = scan.getCaching();
// 如果caching未设置(默认是1),将默认配置成5000
if (caching == 1) {
scan.setCaching(5000);
}
ResultScanner scanner = table.getScanner(scan);
try {
List<T> rs = new ArrayList<>();
int rowNum = 0;
for (Result result : scanner) {
rs.add(action.mapRow(result, rowNum++));
}
return rs;
} finally {
scanner.close();
}
}
});
}
@Override
public <T> T get(String tableName, String rowName, final RowMapper<T> mapper) {
return this.get(tableName, rowName, null, null, mapper);
}
@Override
public <T> T get(String tableName, String rowName, String familyName, final RowMapper<T> mapper) {
return this.get(tableName, rowName, familyName, null, mapper);
}
@Override
public <T> T get(String tableName, final String rowName, final String familyName, final String qualifier, final RowMapper<T> mapper) {
return this.execute(tableName, new TableCallback<T>() {
@Override
public T doInTable(Table table) throws Throwable {
Get get = new Get(Bytes.toBytes(rowName));
if (StringUtils.isNotBlank(familyName)) {
byte[] family = Bytes.toBytes(familyName);
if (StringUtils.isNotBlank(qualifier)) {
get.addColumn(family, Bytes.toBytes(qualifier));
} else {
get.addFamily(family);
}
}
Result result = table.get(get);
return mapper.mapRow(result, 0);
}
});
}
@Override
public void execute(String tableName, MutatorCallback action) {
Assert.notNull(action, "Callback object must not be null");
Assert.notNull(tableName, "No table specified");
StopWatch sw = new StopWatch();
sw.start();
BufferedMutator mutator = null;
try {
BufferedMutatorParams mutatorParams = new BufferedMutatorParams(TableName.valueOf(tableName));
mutator = this.getConnection().getBufferedMutator(mutatorParams.writeBufferSize(3 * 1024 * 1024));
action.doInMutator(mutator);
} catch (Throwable throwable) {
sw.stop();
throw new HbaseSystemException(throwable);
} finally {
if (null != mutator) {
try {
mutator.flush();
mutator.close();
sw.stop();
} catch (IOException e) {
LOGGER.error("hbase mutator资源释放失败");
}
}
}
}
@Override
public void saveOrUpdate(String tableName, final Mutation mutation) {
this.execute(tableName, mutator -> {
mutator.mutate(mutation);
});
}
@Override
public void saveOrUpdates(String tableName, final List<Mutation> mutations) {
this.execute(tableName, mutator -> {
mutator.mutate(mutations);
});
}
public void setConnection(Connection connection) {
this.connection = connection;
}
public Connection getConnection() {
if (null == this.connection) {
synchronized (this) {
if (null == this.connection) {
try {
this.connection = ConnectionFactory.createConnection(configuration);
} catch (IOException e) {
LOGGER.error("hbase connection资源池创建失败");
}
}
}
}
return this.connection;
}
public Configuration getConfiguration() {
return configuration;
}
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
}
@Override
public void destroy() throws Exception {
if (this.getConnection() != null) {
try {
this.getConnection().close();
} catch (IOException e) {
LOGGER.error("hbase connection关闭异常!!!", e);
}
}
}
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.hadoop.hbase.client.BufferedMutator;
public interface MutatorCallback {
/**
* 使用mutator api to update put and delete
*
* @param mutator
* @throws Throwable
*/
void doInMutator(BufferedMutator mutator) throws Throwable;
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.hadoop.hbase.client.Result;
public interface RowMapper<T> {
T mapRow(Result result, int rowNum) throws Exception;
}
package com.secoo.mall.hbase.spring.boot.autoconfigure;
import org.apache.hadoop.hbase.client.Table;
public interface TableCallback<T> {
/**
* Gets called by {@link HbaseTemplate} execute with an active Hbase table. Does need to care about activating or closing down the table.
*
* @param table active Hbase table
* @return a result object, or null if none
* @throws Throwable thrown by the Hbase API
*/
T doInTable(Table table) throws Throwable;
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.mall.hbase.spring.boot.autoconfigure.HbaseAutoConfiguration
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-bigdata</artifactId> <artifactId>matrix-bigdata</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
<module>matrix-bigdata-hbase-starter</module> <module>matrix-bigdata-hbase-starter</module>
<module>matrix-bigdata-spark-starter</module> <module>matrix-bigdata-spark-starter</module>
</modules> </modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aliyun.hbase</groupId>
<artifactId>alihbase-client</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
</dependencyManagement>
</project> </project>
\ No newline at end of file
...@@ -3,55 +3,34 @@ ...@@ -3,55 +3,34 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix-mq</artifactId> <artifactId>matrix-bus</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-rocketmq-starter</artifactId> <artifactId>matrix-bus-canal-starter</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId> <artifactId>matrix-mq-rocketmq-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-core</artifactId> <artifactId>matrix-mq-rocketmq-client</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.otter</groupId>
<artifactId>canal.client</artifactId>
<version>1.1.5-secoo1.2</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>ch.qos.logback</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>logback-core</artifactId> <artifactId>rocketmq-acl</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</dependencies>
</project> </project>
\ No newline at end of file
package com.secoo.mall.rocketmq.consumer; package com.secoo.mall.canal.consumer;
import com.alibaba.otter.canal.protocol.FlatMessage; import com.alibaba.otter.canal.protocol.FlatMessage;
import com.secoo.mall.rocketmq.util.CanalMessageUtil; import com.secoo.mall.canal.util.CanalMessageUtil;
import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.core.RocketMQListener; import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -20,7 +20,7 @@ public abstract class AbsCanalRocketMQConsumer implements RocketMQListener<Messa ...@@ -20,7 +20,7 @@ public abstract class AbsCanalRocketMQConsumer implements RocketMQListener<Messa
public abstract void onCanalMessage(List<FlatMessage> flatMessages); public abstract void onCanalMessage(List<FlatMessage> flatMessages);
public List<FlatMessage> messageConverter(MessageExt messageExt) { public List<FlatMessage> messageConverter(MessageExt messageExt) {
if(messageExt == null){ if (messageExt == null) {
return null; return null;
} }
......
package com.secoo.mall.rocketmq; package com.secoo.mall.canal.consumer;
import com.alibaba.otter.canal.protocol.FlatMessage; import com.alibaba.otter.canal.protocol.FlatMessage;
import com.secoo.mall.rocketmq.util.CanalMessageUtil; import com.secoo.mall.canal.util.CanalMessageUtil;
import com.secoo.mall.rocketmq.PushRocketMQConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageExt;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -16,19 +17,19 @@ public abstract class CanalPushRocketMQConsumer extends PushRocketMQConsumer { ...@@ -16,19 +17,19 @@ public abstract class CanalPushRocketMQConsumer extends PushRocketMQConsumer {
private static Logger logger = LoggerFactory.getLogger(CanalPushRocketMQConsumer.class); private static Logger logger = LoggerFactory.getLogger(CanalPushRocketMQConsumer.class);
@Override @Override
public ConsumeConcurrentlyStatus doService(List<MessageExt> msgs){ public ConsumeConcurrentlyStatus doService(List<MessageExt> msgs) {
return this.doCanalService(messageConverter(msgs)); return this.doCanalService(messageConverter(msgs));
} }
public abstract ConsumeConcurrentlyStatus doCanalService(List<List<FlatMessage>> flatMessageLists); public abstract ConsumeConcurrentlyStatus doCanalService(List<List<FlatMessage>> flatMessageLists);
public List<List<FlatMessage>> messageConverter(List<MessageExt> messageExts) { public List<List<FlatMessage>> messageConverter(List<MessageExt> messageExts) {
if(CollectionUtils.isEmpty(messageExts)){ if (CollectionUtils.isEmpty(messageExts)) {
return null; return null;
} }
List<List<FlatMessage>> flatMessageLists = new ArrayList<List<FlatMessage>>(); List<List<FlatMessage>> flatMessageLists = new ArrayList<List<FlatMessage>>();
for(MessageExt messageExt:messageExts){ for (MessageExt messageExt : messageExts) {
flatMessageLists.add(CanalMessageUtil.messageConverter(messageExt)); flatMessageLists.add(CanalMessageUtil.messageConverter(messageExt));
} }
......
package com.secoo.mall.rocketmq.util; package com.secoo.mall.canal.util;
import com.alibaba.otter.canal.client.CanalMessageDeserializer; import com.alibaba.otter.canal.client.CanalMessageDeserializer;
import com.alibaba.otter.canal.protocol.CanalEntry; import com.alibaba.otter.canal.protocol.CanalEntry;
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-bus</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-bus-canal-starter</module>
</modules>
</project>
\ No newline at end of file
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix-client</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>openfeign-starter</artifactId> <artifactId>matrix-client-openfeign-starter</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
...@@ -33,4 +34,5 @@ ...@@ -33,4 +34,5 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
\ No newline at end of file
...@@ -4,7 +4,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; ...@@ -4,7 +4,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
@EnableFeignClients("com.secoo.mall") @EnableFeignClients("com.secoo")
public class MatrixFeignAutoConfiguration { public class MatrixFeignAutoConfiguration {
} }
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-client</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-client-openfeign-starter</module>
</modules>
</project>
\ No newline at end of file
...@@ -3,30 +3,22 @@ ...@@ -3,30 +3,22 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix-datahelper</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>mongodb-starter</artifactId> <artifactId>matrix-datahelper-redis-core</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
...@@ -12,15 +12,15 @@ import java.util.concurrent.TimeUnit; ...@@ -12,15 +12,15 @@ import java.util.concurrent.TimeUnit;
/** /**
* @author QIANG * @author QIANG
* @since 2.0.1 Deprecated。推荐使用RedisHelper
*/ */
@Deprecated
public class MatrixRedisClusterUtils { public class MatrixRedisClusterUtils {
private static MatrixRedisClusterUtils cacheUtils; private static MatrixRedisClusterUtils cacheUtils;
@Resource
private RedisTemplate<String, String> redisTemplate; private RedisTemplate<String, String> redisTemplate;
public static RedisTemplate<String, String> getRedisTemplate() { public static RedisTemplate<String, String> getRedisTemplate() {
return cacheUtils.redisTemplate; return cacheUtils.redisTemplate;
} }
......
...@@ -3,29 +3,22 @@ ...@@ -3,29 +3,22 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix-datahelper</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>elasticsearch-starter</artifactId> <artifactId>matrix-datahelper-redis-starter</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>common-core</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId> <artifactId>matrix-datahelper-redis-core</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
package com.secoo.mall.redis.config; package com.secoo.mall.redis.spring.boot.autoconfigure;
import com.secoo.mall.redis.helper.RedisHelper;
import com.secoo.mall.redis.utils.MatrixRedisClusterUtils; import com.secoo.mall.redis.utils.MatrixRedisClusterUtils;
import org.springframework.beans.factory.annotation.Qualifier;
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.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.net.UnknownHostException;
/** /**
* Created by QIANG * Created by QIANG
...@@ -16,25 +24,40 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; ...@@ -16,25 +24,40 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author QIANG * @author QIANG
*/ */
@Configuration @Configuration
@ConditionalOnClass({RedisOperations.class})
@AutoConfigureBefore({RedisAutoConfiguration.class})
public class MatrixeRedisAutoConfiguration { public class MatrixeRedisAutoConfiguration {
@Bean @Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) { @ConditionalOnMissingBean(name = {"redisTemplate"})
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
@Bean
@ConditionalOnMissingBean(name = "redisHelper")
public RedisHelper redisHelper(@Qualifier("redisTemplate") RedisTemplate redisTemplate) {
return new RedisHelper(redisTemplate);
}
/**
* @since 2.0.1 Deprecated,请使用RedisHelper
* @param redisTemplate
* @return
*/
@Bean
@ConditionalOnMissingBean(MatrixRedisClusterUtils.class)
@Deprecated
public MatrixRedisClusterUtils jedisClusterUtils(RedisTemplate redisTemplate) {
RedisSerializer stringSerializer = new StringRedisSerializer(); RedisSerializer stringSerializer = new StringRedisSerializer();
RedisTemplate<String, String> redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer); redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer); redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer); redisTemplate.setHashValueSerializer(stringSerializer);
return redisTemplate;
}
@Bean
@ConditionalOnMissingBean(MatrixRedisClusterUtils.class)
public MatrixRedisClusterUtils jedisClusterUtils() {
return new MatrixRedisClusterUtils(); return new MatrixRedisClusterUtils();
} }
} }
# Auto Configure # Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.matrix.monitor.config.MonitorAutoConfiguration com.secoo.mall.redis.spring.boot.autoconfigure.MatrixeRedisAutoConfiguration
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-datahelper</artifactId>
<packaging>pom</packaging>
<modules>
<module>matrix-datahelper-redis-core</module>
<module>matrix-datahelper-redis-starter</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-datasource</artifactId> <artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-datasource</artifactId> <artifactId>matrix-datasource</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-core</artifactId> <artifactId>matrix-datasource-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-job</artifactId> <artifactId>matrix-job</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-job</artifactId> <artifactId>matrix-job</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-job</artifactId> <artifactId>matrix-job</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-job-core</artifactId> <artifactId>matrix-job-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-job-xxl-core</artifactId> <artifactId>matrix-job-xxl-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo</groupId> <groupId>com.secoo</groupId>
......
### 注意事项:
#### 1.本地host需要配置
```
172.17.105.72 NN01.yl.com
172.17.105.74 DN01.yl.com
172.17.105.77 DN02.yl.com
```
#### 1.本地host需要配置
```java
hbase:
zookeeper:
quorum: 172.17.105.72:2181
```
...@@ -3,39 +3,26 @@ ...@@ -3,39 +3,26 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix-mq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>redis-starter</artifactId> <artifactId>matrix-mq-rocketmq-client</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>matrix-mq-rocketmq-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>org.springframework</groupId>
<artifactId>fastjson</artifactId> <artifactId>spring-tx</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>commons-pool2</artifactId> <artifactId>common-util</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
package com.secoo.mall.rocketmq; package com.secoo.mall.rocketmq;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.rocketmq.util.RunTimeUtil; import com.secoo.mall.rocketmq.util.RunTimeUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.rocketmq.acl.common.AclClientRPCHook; import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials; import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
...@@ -64,7 +64,7 @@ public abstract class PushRocketMQConsumer { ...@@ -64,7 +64,7 @@ public abstract class PushRocketMQConsumer {
@Override @Override
public void run() { public void run() {
consumer[0] = new DefaultMQPushConsumer(consumerGroup,getAclRPCHook(),new AllocateMessageQueueAveragely()); consumer[0] = new DefaultMQPushConsumer(consumerGroup, getAclRPCHook(), new AllocateMessageQueueAveragely());
consumer[0].setInstanceName(RunTimeUtil.getRocketMqUniqeInstanceName()); consumer[0].setInstanceName(RunTimeUtil.getRocketMqUniqeInstanceName());
consumer[0].setNamesrvAddr(namesrvAddr); consumer[0].setNamesrvAddr(namesrvAddr);
try { try {
...@@ -197,8 +197,8 @@ public abstract class PushRocketMQConsumer { ...@@ -197,8 +197,8 @@ public abstract class PushRocketMQConsumer {
} }
public RPCHook getAclRPCHook() { public RPCHook getAclRPCHook() {
if (StringUtils.isNotBlank(accessKey) && StringUtils.isNotBlank(secretKey)) { if (StringUtil.isNotBlank(accessKey) && StringUtil.isNotBlank(secretKey)) {
return new AclClientRPCHook(new SessionCredentials(this.getAccessKey(),this.getSecretKey())); return new AclClientRPCHook(new SessionCredentials(this.getAccessKey(), this.getSecretKey()));
} }
return null; return null;
......
package com.secoo.mall.rocketmq; package com.secoo.mall.rocketmq;
import com.secoo.mall.common.core.serializer.MatrixSerializer;
import com.secoo.mall.common.serializer.FastJsonSerializer;
import com.secoo.mall.rocketmq.util.RunTimeUtil; import com.secoo.mall.rocketmq.util.RunTimeUtil;
import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.exception.MQClientException;
...@@ -9,6 +11,8 @@ import org.apache.rocketmq.common.message.Message; ...@@ -9,6 +11,8 @@ import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.remoting.exception.RemotingException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -27,14 +31,19 @@ public class PushRocketMQProducer { ...@@ -27,14 +31,19 @@ public class PushRocketMQProducer {
private String topic; private String topic;
private boolean retryAnotherBrokerWhenNotStoreOK = true; private boolean retryAnotherBrokerWhenNotStoreOK = true;
private int retryTimesWhenSendAsyncFailed = 3; private int retryTimesWhenSendAsyncFailed = 3;
private DefaultMQProducer producer ; private DefaultMQProducer producer;
private int level = 0; private Integer level = 0;
private Logger logger = LoggerFactory.getLogger(PushRocketMQConsumer.class); private Logger logger = LoggerFactory.getLogger(PushRocketMQConsumer.class);
private static final int MASSAGES =1024000; private static final int MASSAGES = 1024000;
/**
* 注入自定义序列化器,如果空则默认JSON
*/
private MatrixSerializer serializer;
@PostConstruct @PostConstruct
public void init() { public void init() {
this.logger.info("初始化RocketMQ消息发送者,namesrvAddr={},producerGroup={},tags={}", new Object[] { this.namesrvAddr, this.producerGroup, this.tags }); this.logger.info("初始化RocketMQ消息发送者,namesrvAddr={},producerGroup={},tags={}", new Object[]{this.namesrvAddr, this.producerGroup, this.tags});
try { try {
DefaultMQProducer producerNew = null; DefaultMQProducer producerNew = null;
producerNew = new DefaultMQProducer(producerGroup); producerNew = new DefaultMQProducer(producerGroup);
...@@ -43,39 +52,99 @@ public class PushRocketMQProducer { ...@@ -43,39 +52,99 @@ public class PushRocketMQProducer {
producerNew.setMaxMessageSize(MASSAGES); producerNew.setMaxMessageSize(MASSAGES);
producerNew.setRetryAnotherBrokerWhenNotStoreOK(retryAnotherBrokerWhenNotStoreOK); producerNew.setRetryAnotherBrokerWhenNotStoreOK(retryAnotherBrokerWhenNotStoreOK);
producerNew.setRetryTimesWhenSendAsyncFailed(retryTimesWhenSendAsyncFailed); producerNew.setRetryTimesWhenSendAsyncFailed(retryTimesWhenSendAsyncFailed);
if (serializer == null) {
serializer = new FastJsonSerializer(Object.class);
}
producerNew.start(); producerNew.start();
this.producer = producerNew; this.producer = producerNew;
} catch (MQClientException e) { } catch (MQClientException e) {
throw new RuntimeException(e.getMessage(),e); throw new RuntimeException(e.getMessage(), e);
} }
} }
public SendResult send(Message msg) public SendResult send(Message msg)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
{
msg.setDelayTimeLevel(this.level); msg.setDelayTimeLevel(this.level);
SendResult result = this.producer.send(msg); SendResult result = this.producer.send(msg);
if(logger.isDebugEnabled()){ if (logger.isDebugEnabled()) {
this.logger.debug("发送RocketMQ消息,topic:{},keys:{},结果:{}",new Object[]{msg.getTopic(),msg.getKeys(),result} ); this.logger.debug("发送RocketMQ消息,topic:{},keys:{},结果:{}", new Object[]{msg.getTopic(), msg.getKeys(), result});
} }
return result; return result;
} }
public SendResult send(String newTags, String keys, byte[] body) public SendResult send(String newTags, String keys, byte[] body)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
{ return send(getTopic(), newTags, keys, body);
}
public SendResult send(String topic, String newTags, String keys, byte[] body)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
Message msg = new Message(getTopic(), newTags, keys, body); Message msg = new Message(getTopic(), newTags, keys, body);
return send(msg); return send(msg);
} }
public SendResult send(String keys, byte[] body) public SendResult send(String keys, byte[] body)
throws MQClientException, RemotingException, MQBrokerException, InterruptedException throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
{
Message msg = new Message(getTopic(), this.tags, keys, body); Message msg = new Message(getTopic(), this.tags, keys, body);
return send(msg); return send(msg);
} }
/**
* from secoo-framework
* 发送消息
*
* @param topic 消息主题
* @param tag 支持一个tag
* @param keys 多个keys逗号隔开
*/
public SendResult send(String topic, String tag, String keys, Object body)
throws RuntimeException {
if (body == null || topic == null) {
return null;
}
byte[] bodyArr = null;
if (body instanceof byte[]) {
bodyArr = (byte[]) body;
} else {
bodyArr = serializer.serialize(body);
}
return send(topic, tag, keys, body);
}
/**
* DB事务同步发送
*
* @param afterFlag true 提交事务后发送,false 提交事务前发送
*/
public void sendTransSynch(final String topic, final String tag, final String keys,
final Object body, boolean afterFlag) {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager
.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void beforeCommit(boolean readOnly) {
if (!afterFlag) {
send(topic, tag, keys, body);
}
}
@Override
public void afterCommit() {
if (afterFlag) {
send(topic, tag, keys, body);
}
}
});
} else {
send(topic, tag, keys, body);
}
}
public String getProducerGroup() { public String getProducerGroup() {
return producerGroup; return producerGroup;
......
/**
* Created by Administrator on 2018/1/19.
*/
package com.secoo.mall.rocketmq.serializer;
/**
* 消息序列化器
*
* @author Administrator
* @create 2018-01-19 14:29
**/
public interface MqSerializer {
/**
* 消息序列化接口
*/
<T> byte[] serialize(T obj);
}
...@@ -5,37 +5,31 @@ ...@@ -5,37 +5,31 @@
<parent> <parent>
<artifactId>matrix-mq</artifactId> <artifactId>matrix-mq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>matrix-rocketmq-core</artifactId> <artifactId>matrix-mq-rocketmq-core</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId> <artifactId>rocketmq-acl</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId> <artifactId>rocketmq-client</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId> <artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba.otter</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>canal.client</artifactId> <artifactId>protobuf-java-util</artifactId>
<version>1.1.5-secoo1.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
......
package com.secoo.mall.rocketmq.converter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.ContentTypeResolver;
import org.springframework.messaging.converter.DefaultContentTypeResolver;
import org.springframework.messaging.converter.SmartMessageConverter;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
/**
* Abstract base class for {@link SmartMessageConverter} implementations including
* support for common properties and a partial implementation of the conversion methods,
* mainly to check if the converter supports the conversion based on the payload class
* and MIME type.
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 4.0
*/
public abstract class AbstractMessageConverter implements SmartMessageConverter {
protected final Log logger = LogFactory.getLog(getClass());
private final List<MimeType> supportedMimeTypes = new ArrayList<>(4);
@Nullable
private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
private boolean strictContentTypeMatch = false;
private Class<?> serializedPayloadClass = byte[].class;
/**
* Constructor with a single MIME type.
* @param supportedMimeType the supported MIME type
*/
protected AbstractMessageConverter(MimeType supportedMimeType) {
this(Collections.singletonList(supportedMimeType));
}
/**
* Constructor with one or more MIME types via vararg.
* @param supportedMimeTypes the supported MIME types
* @since 5.2.2
*/
protected AbstractMessageConverter(MimeType... supportedMimeTypes) {
this(Arrays.asList(supportedMimeTypes));
}
/**
* Constructor with a Collection of MIME types.
* @param supportedMimeTypes the supported MIME types
*/
protected AbstractMessageConverter(Collection<MimeType> supportedMimeTypes) {
this.supportedMimeTypes.addAll(supportedMimeTypes);
}
/**
* Return the supported MIME types.
*/
public List<MimeType> getSupportedMimeTypes() {
return Collections.unmodifiableList(this.supportedMimeTypes);
}
/**
* Allows sub-classes to add more supported mime types.
* @since 5.2.2
*/
protected void addSupportedMimeTypes(MimeType... supportedMimeTypes) {
this.supportedMimeTypes.addAll(Arrays.asList(supportedMimeTypes));
}
/**
* Configure the {@link ContentTypeResolver} to use to resolve the content
* type of an input message.
* <p>Note that if no resolver is configured, then
* {@link #setStrictContentTypeMatch(boolean) strictContentTypeMatch} should
* be left as {@code false} (the default) or otherwise this converter will
* ignore all messages.
* <p>By default, a {@code DefaultContentTypeResolver} instance is used.
*/
public void setContentTypeResolver(@Nullable ContentTypeResolver resolver) {
this.contentTypeResolver = resolver;
}
/**
* Return the configured {@link ContentTypeResolver}.
*/
@Nullable
public ContentTypeResolver getContentTypeResolver() {
return this.contentTypeResolver;
}
/**
* Whether this converter should convert messages for which no content type
* could be resolved through the configured
* {@link org.springframework.messaging.converter.ContentTypeResolver}.
* <p>A converter can configured to be strict only when a
* {@link #setContentTypeResolver contentTypeResolver} is configured and the
* list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty.
* <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)}
* will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver}
* is not defined or if no content-type header is present.
*/
public void setStrictContentTypeMatch(boolean strictContentTypeMatch) {
if (strictContentTypeMatch) {
Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types");
Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver");
}
this.strictContentTypeMatch = strictContentTypeMatch;
}
/**
* Whether content type resolution must produce a value that matches one of
* the supported MIME types.
*/
public boolean isStrictContentTypeMatch() {
return this.strictContentTypeMatch;
}
/**
* Configure the preferred serialization class to use (byte[] or String) when
* converting an Object payload to a {@link Message}.
* <p>The default value is byte[].
* @param payloadClass either byte[] or String
*/
public void setSerializedPayloadClass(Class<?> payloadClass) {
Assert.isTrue(byte[].class == payloadClass || String.class == payloadClass,
() -> "Payload class must be byte[] or String: " + payloadClass);
this.serializedPayloadClass = payloadClass;
}
/**
* Return the configured preferred serialization payload class.
*/
public Class<?> getSerializedPayloadClass() {
return this.serializedPayloadClass;
}
/**
* Returns the default content type for the payload. Called when
* {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or
* without a content type header.
* <p>By default, this returns the first element of the {@link #getSupportedMimeTypes()
* supportedMimeTypes}, if any. Can be overridden in sub-classes.
* @param payload the payload being converted to message
* @return the content type, or {@code null} if not known
*/
@Nullable
protected MimeType getDefaultContentType(Object payload) {
List<MimeType> mimeTypes = getSupportedMimeTypes();
return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null);
}
@Override
@Nullable
public final Object fromMessage(Message<?> message, Class<?> targetClass) {
return fromMessage(message, targetClass, null);
}
@Override
@Nullable
public final Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
if (!canConvertFrom(message, targetClass)) {
return null;
}
return convertFromInternal(message, targetClass, conversionHint);
}
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
return (supports(targetClass) && supportsMimeType(message.getHeaders()));
}
@Override
@Nullable
public final Message<?> toMessage(Object payload, @Nullable MessageHeaders headers) {
return toMessage(payload, headers, null);
}
@Override
@Nullable
public final Message<?> toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
if (!canConvertTo(payload, headers)) {
return null;
}
Object payloadToUse = convertToInternal(payload, headers, conversionHint);
if (payloadToUse == null) {
return null;
}
MimeType mimeType = getDefaultContentType(payloadToUse);
if (headers != null) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
if (mimeType != null) {
accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
}
return MessageBuilder.createMessage(payloadToUse, accessor.getMessageHeaders());
}
}
MessageBuilder<?> builder = MessageBuilder.withPayload(payloadToUse);
if (headers != null) {
builder.copyHeaders(headers);
}
if (mimeType != null) {
builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
}
return builder.build();
}
protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
return (supports(payload.getClass()) && supportsMimeType(headers));
}
protected boolean supportsMimeType(@Nullable MessageHeaders headers) {
if (getSupportedMimeTypes().isEmpty()) {
return true;
}
MimeType mimeType = getMimeType(headers);
if (mimeType == null) {
return !isStrictContentTypeMatch();
}
for (MimeType current : getSupportedMimeTypes()) {
if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) {
return true;
}
}
return false;
}
@Nullable
protected MimeType getMimeType(@Nullable MessageHeaders headers) {
return (headers != null && this.contentTypeResolver != null ? this.contentTypeResolver.resolve(headers) : null);
}
/**
* Whether the given class is supported by this converter.
* @param clazz the class to test for support
* @return {@code true} if supported; {@code false} otherwise
*/
protected abstract boolean supports(Class<?> clazz);
/**
* Convert the message payload from serialized form to an Object.
* @param message the input message
* @param targetClass the target class for the conversion
* @param conversionHint an extra object passed to the {@link org.springframework.messaging.converter.MessageConverter},
* e.g. the associated {@code MethodParameter} (may be {@code null}}
* @return the result of the conversion, or {@code null} if the converter cannot
* perform the conversion
* @since 4.2
*/
@Nullable
protected Object convertFromInternal(
Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
return null;
}
/**
* cannot perform the conversion
* @since 4.2
*/
@Nullable
protected Object convertToInternal(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
return null;
}
\ No newline at end of file
package com.secoo.mall.rocketmq.converter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.util.JsonFormat;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.MimeType;
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON;
import static org.springframework.util.MimeTypeUtils.TEXT_PLAIN;
/**
* An {@code MessageConverter} that reads and writes
* {@link com.google.protobuf.Message com.google.protobuf.Messages} using
* <a href="https://developers.google.com/protocol-buffers/">Google Protocol Buffers</a>.
*
* <p>To generate {@code Message} Java classes, you need to install the {@code protoc} binary.
*
* <p>This converter supports by default {@code "application/x-protobuf"} with the official
* {@code "com.google.protobuf:protobuf-java"} library.
*
* <p>{@code "application/json"} can be supported with the official
* {@code "com.google.protobuf:protobuf-java-util"} 3.x, with 3.3 or higher recommended.
*
* @author Parviz Rozikov
* @author Rossen Stoyanchev
* @since 5.2.2
*/
public class ProtobufMessageConverter extends AbstractMessageConverter {
/**
* The default charset used by the converter.
*/
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
/**
* The mime-type for protobuf {@code application/x-protobuf}.
*/
public static final MimeType PROTOBUF = new MimeType("application", "x-protobuf", DEFAULT_CHARSET);
private static final Map<Class<?>, Method> methodCache = new ConcurrentReferenceHashMap<>();
final ExtensionRegistry extensionRegistry;
@Nullable
private final ProtobufFormatSupport protobufFormatSupport;
/**
* Constructor with a default instance of {@link ExtensionRegistry}.
*/
public ProtobufMessageConverter() {
this(null, null);
}
/**
* Constructor with a given {@code ExtensionRegistry}.
*/
public ProtobufMessageConverter(ExtensionRegistry extensionRegistry) {
this(null, extensionRegistry);
}
ProtobufMessageConverter(@Nullable ProtobufFormatSupport formatSupport,
@Nullable ExtensionRegistry extensionRegistry) {
super(PROTOBUF, TEXT_PLAIN);
if (formatSupport != null) {
this.protobufFormatSupport = formatSupport;
} else if (ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", getClass().getClassLoader())) {
this.protobufFormatSupport = new ProtobufJavaUtilSupport(null, null);
} else {
this.protobufFormatSupport = null;
}
if (this.protobufFormatSupport != null) {
addSupportedMimeTypes(this.protobufFormatSupport.supportedMediaTypes());
}
this.extensionRegistry = (extensionRegistry == null ? ExtensionRegistry.newInstance() : extensionRegistry);
}
@Override
protected boolean supports(Class<?> clazz) {
return Message.class.isAssignableFrom(clazz);
}
@Override
protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
MimeType mimeType = getMimeType(headers);
return (super.canConvertTo(payload, headers) ||
this.protobufFormatSupport != null && this.protobufFormatSupport.supportsWriteOnly(mimeType));
}
@Override
protected Object convertFromInternal(org.springframework.messaging.Message<?> message,
Class<?> targetClass, @Nullable Object conversionHint) {
MimeType contentType = getMimeType(message.getHeaders());
final Object payload = message.getPayload();
if (contentType == null) {
contentType = PROTOBUF;
}
Charset charset = contentType.getCharset();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
Message.Builder builder = getMessageBuilder(targetClass);
try {
if (PROTOBUF.isCompatibleWith(contentType)) {
builder.mergeFrom((byte[]) payload, this.extensionRegistry);
} else if (this.protobufFormatSupport != null) {
this.protobufFormatSupport.merge(message, charset, contentType, this.extensionRegistry, builder);
}
} catch (IOException ex) {
throw new MessageConversionException(message, "Could not read proto message" + ex.getMessage(), ex);
}
return builder.build();
}
@Override
protected Object convertToInternal(
Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) {
final Message message = (Message) payload;
MimeType contentType = getMimeType(headers);
if (contentType == null) {
contentType = PROTOBUF;
}
Charset charset = contentType.getCharset();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
try {
if (PROTOBUF.isCompatibleWith(contentType)) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
message.writeTo(byteArrayOutputStream);
payload = byteArrayOutputStream.toByteArray();
} else if (this.protobufFormatSupport != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
this.protobufFormatSupport.print(message, outputStream, contentType, charset);
payload = outputStream.toString(charset.name());
}
} catch (IOException ex) {
throw new MessageConversionException("Failed to print Protobuf message: " + ex.getMessage(), ex);
}
return payload;
}
/**
* Create a new {@code Message.Builder} instance for the given class.
* <p>This method uses a ConcurrentReferenceHashMap for caching method lookups.
*/
private Message.Builder getMessageBuilder(Class<?> clazz) {
try {
Method method = methodCache.get(clazz);
if (method == null) {
method = clazz.getMethod("newBuilder");
methodCache.put(clazz, method);
}
return (Message.Builder) method.invoke(clazz);
} catch (Exception ex) {
throw new MessageConversionException(
"Invalid Protobuf Message type: no invocable newBuilder() method on " + clazz, ex);
}
}
/**
* Protobuf format support.
*/
interface ProtobufFormatSupport {
MimeType[] supportedMediaTypes();
boolean supportsWriteOnly(@Nullable MimeType mediaType);
void merge(org.springframework.messaging.Message<?> message,
Charset charset, MimeType contentType, ExtensionRegistry extensionRegistry,
Message.Builder builder) throws IOException, MessageConversionException;
void print(Message message, OutputStream output, MimeType contentType, Charset charset)
throws IOException, MessageConversionException;
}
/**
* {@link ProtobufFormatSupport} implementation used when
* {@code com.google.protobuf.util.JsonFormat} is available.
*/
static class ProtobufJavaUtilSupport implements ProtobufFormatSupport {
private final JsonFormat.Parser parser;
private final JsonFormat.Printer printer;
public ProtobufJavaUtilSupport(@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
this.parser = (parser != null ? parser : JsonFormat.parser());
this.printer = (printer != null ? printer : JsonFormat.printer());
}
@Override
public MimeType[] supportedMediaTypes() {
return new MimeType[]{APPLICATION_JSON};
}
@Override
public boolean supportsWriteOnly(@Nullable MimeType mimeType) {
return false;
}
@Override
public void merge(org.springframework.messaging.Message<?> message, Charset charset,
MimeType contentType, ExtensionRegistry extensionRegistry, Message.Builder builder)
throws IOException, MessageConversionException {
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
this.parser.merge(message.getPayload().toString(), builder);
} else {
throw new MessageConversionException(
"protobuf-java-util does not support parsing " + contentType);
}
}
@Override
public void print(Message message, OutputStream output, MimeType contentType, Charset charset)
throws IOException, MessageConversionException {
if (contentType.isCompatibleWith(APPLICATION_JSON)) {
OutputStreamWriter writer = new OutputStreamWriter(output, charset);
this.printer.appendTo(message, writer);
writer.flush();
} else {
throw new MessageConversionException(
"protobuf-java-util does not support printing " + contentType);
}
}
}
}
\ No newline at end of file
...@@ -19,7 +19,7 @@ matrix-rocketmq-starter ...@@ -19,7 +19,7 @@ matrix-rocketmq-starter
```xml ```xml
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-starter</artifactId> <artifactId>matrix-mq-rocketmq-starter</artifactId>
</dependency> </dependency>
``` ```
......
...@@ -3,19 +3,17 @@ ...@@ -3,19 +3,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix-mq</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>rocketmq-starter</artifactId> <artifactId>matrix-mq-rocketmq-starter</artifactId>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId> <artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.3</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.secoo.mall.rocketmq;
import com.secoo.mall.rocketmq.PushRocketMQProducer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Producer extends PushRocketMQProducer {
private static Logger logger = LoggerFactory.getLogger(Producer.class);
public static void main(String[] args) throws MQClientException,
InterruptedException {
/**
* 一个应用创建一个Producer,由应用来维护此对象,可以设置为全局对象或者单例<br>
* 注意:ProducerGroupName需要由应用来保证唯一<br>
* ProducerGroup这个概念发送普通的消息时,作用不大,但是发送分布式事务消息时,比较关键,
* 因为服务器会回查这个Group下的任意一个Producer
*/
PushRocketMQProducer producer = new PushRocketMQProducer();
producer.setNamesrvAddr("localhost:9876");
producer.setTopic("TopicTest");
producer.setProducerGroup("test");
producer.init();
/**
* 下面这段代码表明一个Producer对象可以发送多个topic,多个tag的消息。
* 注意:send方法是同步调用,只要不抛异常就标识成功。但是发送成功也可会有多种状态,<br>
* 例如消息写入Master成功,但是Slave不成功,这种情况消息属于成功,但是对于个别应用如果对消息可靠性要求极高,<br>
* 需要对这种情况做处理。另外,消息可能会存在发送失败的情况,失败重试由应用来处理。
*/
for (int i = 0; i < 100; i++) {
try {
{
Message msg = new Message("TopicTest",// topic
"TagA",// tag
"OrderID001",// key
("Hello MetaQ").getBytes());// body
SendResult sendResult = producer.send(msg);
System.out.println("第 "+i+" 数据"+sendResult.toString());
}
/*{
Message msg = new Message("TopicTest2",// topic
"TagB",// tag
"OrderID0034",// key
("Hello MetaQ").getBytes());// body
SendResult sendResult = producer.send(msg);
logger.info(sendResult.toString());
}
{
Message msg = new Message("TopicTest3",// topic
"TagC",// tag
"OrderID061",// key
("Hello MetaQ").getBytes());// body
SendResult sendResult = producer.send(msg);
logger.info(sendResult.toString());
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
\ No newline at end of file
package com.secoo.mall.rocketmq;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class PushConsumer {
private static Logger logger = LoggerFactory.getLogger(Producer.class);
/**
* 当前例子是PushConsumer用法,使用方式给用户感觉是消息从RocketMQ服务器推到了应用客户端。<br>
* 但是实际PushConsumer内部是使用长轮询Pull方式从MetaQ服务器拉消息,然后再回调用户Listener方法<br>
*/
public static void main(String[] args) throws InterruptedException,
MQClientException {
/**
* 一个应用创建一个Consumer,由应用来维护此对象,可以设置为全局对象或者单例<br>
* 注意:ConsumerGroupName需要由应用来保证唯一
*/
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(
"ConsumerGroupName");
consumer.setNamesrvAddr("10.0.253.3:9876;10.0.253.2:9876");
consumer.setInstanceName("Consumber");
/**
* 订阅指定topic下tags分别等于TagA或TagC或TagD
*/
//consumer.subscribe("TopicTest1", "TagA || TagC || TagD");
/**
* 订阅指定topic下所有消息<br>
* 注意:一个consumer对象可以订阅多个topic
*/
consumer.subscribe("TopicTest", "*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
/**
* 默认msgs里只有一条消息,可以通过设置consumeMessageBatchMaxSize参数来批量接收消息
*/
@Override
public ConsumeConcurrentlyStatus consumeMessage(
List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.println(Thread.currentThread().getName()
+ " Receive New Messages: " + msgs.size());
MessageExt msg = msgs.get(0);
if (msg.getTopic().equals("TopicTest")) {
// 执行TopicTest1的消费逻辑
if (msg.getTags() != null && msg.getTags().equals("TagA")) {
// 执行TagA的消费
System.out.println(new String(msg.getBody()));
} else if (msg.getTags() != null
&& msg.getTags().equals("TagC")) {
// 执行TagC的消费
} else if (msg.getTags() != null
&& msg.getTags().equals("TagD")) {
// 执行TagD的消费
}else {
System.out.println(new String(msg.getBody()));
}
} else if (msg.getTopic().equals("TopicTest2")) {
System.out.println(new String(msg.getBody()));
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
/**
* Consumer对象在使用之前必须要调用start初始化,初始化一次即可<br>
*/
consumer.start();
System.out.println("Consumer Started.");
}
}
\ No newline at end of file
package com.secoo.mall.rocketmq.config;
import com.secoo.mall.rocketmq.hook.MatrixProducerHook;
import com.secoo.mall.rocketmq.producer.MartixProducer;
import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.AccessChannel;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.spring.autoconfigure.RocketMQProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* @author qianglu
*/
@Configuration
@Import(MatrixListenerContainerConfiguration.class)
public class MatrixRocketMQAutoConfiguration {
@Bean
public DefaultMQProducer defaultMQProducer(RocketMQProperties rocketMQProperties) {
RocketMQProperties.Producer producerConfig = rocketMQProperties.getProducer();
String nameServer = rocketMQProperties.getNameServer();
String groupName = producerConfig.getGroup();
Assert.hasText(nameServer, "[rocketmq.name-server] must not be null");
Assert.hasText(groupName, "[rocketmq.producer.group] must not be null");
String accessChannel = rocketMQProperties.getAccessChannel();
MartixProducer producer;
String ak = rocketMQProperties.getProducer().getAccessKey();
String sk = rocketMQProperties.getProducer().getSecretKey();
MatrixProducerHook matrixProducerHook = new MatrixProducerHook();
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
producer = new MartixProducer(groupName, new AclClientRPCHook(new SessionCredentials(ak, sk)),
rocketMQProperties.getProducer().isEnableMsgTrace(),
rocketMQProperties.getProducer().getCustomizedTraceTopic(), matrixProducerHook);
producer.setVipChannelEnabled(false);
} else {
producer = new MartixProducer(groupName, rocketMQProperties.getProducer().isEnableMsgTrace(),
rocketMQProperties.getProducer().getCustomizedTraceTopic(), matrixProducerHook);
}
producer.setNamesrvAddr(nameServer);
if (!StringUtils.isEmpty(accessChannel)) {
producer.setAccessChannel(AccessChannel.valueOf(accessChannel));
}
producer.setSendMsgTimeout(producerConfig.getSendMessageTimeout());
producer.setRetryTimesWhenSendFailed(producerConfig.getRetryTimesWhenSendFailed());
producer.setRetryTimesWhenSendAsyncFailed(producerConfig.getRetryTimesWhenSendAsyncFailed());
producer.setMaxMessageSize(producerConfig.getMaxMessageSize());
producer.setCompressMsgBodyOverHowmuch(producerConfig.getCompressMessageBodyThreshold());
producer.setRetryAnotherBrokerWhenNotStoreOK(producerConfig.isRetryNextServer());
return producer;
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -14,17 +14,22 @@ ...@@ -14,17 +14,22 @@
<properties> <properties>
<rocketmq.version>4.6.0</rocketmq.version> <rocketmq.version>4.6.0</rocketmq.version>
<spring.version>5.2.1.RELEASE</spring.version>
<canal.version>1.1.5-secoo1.2</canal.version>
</properties> </properties>
<modules> <modules>
<module>matrix-rocketmq-core</module> <module>matrix-mq-rocketmq-core</module>
<module>matrix-rocketmq-starter</module> <module>matrix-mq-rocketmq-client</module>
<module>matrix-mq-rocketmq-starter</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-mq-rocketmq-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId> <artifactId>rocketmq-client</artifactId>
<version>${rocketmq.version}</version> <version>${rocketmq.version}</version>
...@@ -38,20 +43,7 @@ ...@@ -38,20 +43,7 @@
<dependency> <dependency>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId> <artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.0.3</version> <version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.otter</groupId>
<artifactId>canal.client</artifactId>
<version>${canal.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-mybatis</artifactId> <artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-mybatis</artifactId> <artifactId>matrix-mybatis</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -25,17 +25,17 @@ ...@@ -25,17 +25,17 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-core</artifactId> <artifactId>matrix-mybatis-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-druid</artifactId> <artifactId>matrix-datasource-druid</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId> <artifactId>matrix-mybatis-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-protocol</artifactId> <artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>
......
...@@ -13,8 +13,9 @@ import org.springframework.context.i18n.LocaleContextHolder; ...@@ -13,8 +13,9 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
public class ProtocolExceptionHandler { public abstract class AbsProtocolExceptionHandler {
@Resource @Resource
private MessageSource messageSource; private MessageSource messageSource;
...@@ -25,6 +26,8 @@ public class ProtocolExceptionHandler { ...@@ -25,6 +26,8 @@ public class ProtocolExceptionHandler {
@ExceptionHandler({Exception.class}) @ExceptionHandler({Exception.class})
public Object exceptionHandler(Exception e) { public Object exceptionHandler(Exception e) {
try { try {
logReqParams();
if (exceptionProcessor == null) { if (exceptionProcessor == null) {
throw e; throw e;
} }
...@@ -57,8 +60,13 @@ public class ProtocolExceptionHandler { ...@@ -57,8 +60,13 @@ public class ProtocolExceptionHandler {
try { try {
return messageSource.getMessage(e.getMsg(), e.getArgs(), LocaleContextHolder.getLocale()); return messageSource.getMessage(e.getMsg(), e.getArgs(), LocaleContextHolder.getLocale());
} catch (Exception ex) { } catch (Exception ex) {
return String.format("[%s] not exsits.Please check config message_%s.properties.",e.getMsg(), LocaleContextHolder.getLocale()); return String.format("[%s] not exsits.Please check config message_%s.properties.", e.getMsg(), LocaleContextHolder.getLocale());
} }
} }
/**
* 打印请求参数包括args和reqbody
*/
protected abstract void logReqParams();
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-protocol</artifactId> <artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -3,7 +3,7 @@ package com.secoo.mall.dubbo.listener; ...@@ -3,7 +3,7 @@ package com.secoo.mall.dubbo.listener;
import com.secoo.mall.common.core.exception.BusinessException; import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.core.exception.ParameterException; import com.secoo.mall.common.core.exception.ParameterException;
import com.secoo.mall.common.core.exception.SystemInternalException; import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.handler.ProtocolExceptionHandler; import com.secoo.mall.common.handler.AbsProtocolExceptionHandler;
import com.secoo.mall.common.util.response.ResponseUtil; import com.secoo.mall.common.util.response.ResponseUtil;
import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Invoker;
...@@ -12,7 +12,7 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver; ...@@ -12,7 +12,7 @@ import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class MatrixResponseExceptionListener extends ProtocolExceptionHandler implements ExceptionListener { public class MatrixResponseExceptionListener extends AbsProtocolExceptionHandler implements ExceptionListener {
private ExceptionHandlerMethodResolver resolver; private ExceptionHandlerMethodResolver resolver;
public MatrixResponseExceptionListener() { public MatrixResponseExceptionListener() {
...@@ -52,4 +52,9 @@ public class MatrixResponseExceptionListener extends ProtocolExceptionHandler im ...@@ -52,4 +52,9 @@ public class MatrixResponseExceptionListener extends ProtocolExceptionHandler im
} }
return exception; return exception;
} }
@Override
protected void logReqParams() {
//unimpimplements
}
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-protocol</artifactId> <artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-protocol</artifactId> <artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
package com.secoo.mall.web.advice; package com.secoo.mall.web.advice;
import com.secoo.mall.common.handler.ProtocolExceptionHandler; import com.alibaba.fastjson.JSON;
import com.secoo.mall.common.handler.AbsProtocolExceptionHandler;
import com.secoo.mall.common.util.file.IOUtil;
import com.secoo.mall.common.util.response.ResponseUtil; import com.secoo.mall.common.util.response.ResponseUtil;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.common.util.web.WebUtil;
import com.secoo.mall.web.annotation.ApiController; import com.secoo.mall.web.annotation.ApiController;
import com.secoo.mall.web.annotation.ApiIgnoreJson; import com.secoo.mall.web.annotation.ApiIgnoreJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Optional;
@RestControllerAdvice(annotations = ApiController.class) @RestControllerAdvice(annotations = ApiController.class)
public class ControllerResponseAdvice extends ProtocolExceptionHandler implements ResponseBodyAdvice<Object> { @Slf4j
public class ControllerResponseAdvice extends AbsProtocolExceptionHandler implements ResponseBodyAdvice<Object>, RequestBodyAdvice {
private final static String REQUEST_BODY = "requestBody";
@Override @Override
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) { public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
...@@ -26,4 +47,66 @@ public class ControllerResponseAdvice extends ProtocolExceptionHandler implement ...@@ -26,4 +47,66 @@ public class ControllerResponseAdvice extends ProtocolExceptionHandler implement
return ResponseUtil.getSuccessResponse(o); return ResponseUtil.getSuccessResponse(o);
} }
@Override
protected void logReqParams() {
HttpServletRequest request = WebUtil.getRequest();
String uri = request.getRequestURI();
String queryString = request.getQueryString();
String params = getParams(request);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("uri:").append(uri).append(",");
if (StringUtil.isNotEmpty(queryString)) {
stringBuilder.append("queryString:").append(queryString).append(",");
}
if (StringUtil.isNotEmpty(params)) {
stringBuilder.append("params:").append(params);
}
log.info("req:{}", stringBuilder);
}
private String getParams(HttpServletRequest request) {
StringBuilder stringBuilder = new StringBuilder();
// 获取内容格式
String contentType = request.getContentType();
if (StringUtil.isNotBlank(contentType)) {
contentType = contentType.split(";")[0];
}
// form表单格式 表单形式可以从 ParameterMap中获取
if (MediaType.APPLICATION_FORM_URLENCODED_VALUE.equalsIgnoreCase(contentType)) {
// 获取参数
Map<String, String[]> parameterMap = request.getParameterMap();
if (parameterMap != null) {
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
stringBuilder.append(entry.getKey()).append(":").append(entry.getValue()[0]);
}
}
}
Optional.ofNullable(WebUtil.getAttribute(REQUEST_BODY)).ifPresent(param -> stringBuilder.append(param));
return stringBuilder.toString();
}
@Override
public boolean supports(MethodParameter methodParameter, Type type, Class<? extends HttpMessageConverter<?>> aClass) {
return methodParameter.getParameterAnnotation(RequestBody.class) != null;
}
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class<? extends HttpMessageConverter<?>> aClass) throws IOException {
return httpInputMessage;
}
@Override
public Object afterBodyRead(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class<? extends HttpMessageConverter<?>> aClass) {
WebUtil.setAttribute(REQUEST_BODY, JSON.toJSONString(o));
return o;
}
@Override
public Object handleEmptyBody(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class<? extends HttpMessageConverter<?>> aClass) {
return o;
}
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix-protocol</artifactId> <artifactId>matrix-protocol</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -29,27 +29,27 @@ ...@@ -29,27 +29,27 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-core</artifactId> <artifactId>matrix-protocol-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-core</artifactId> <artifactId>matrix-protocol-web-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-core</artifactId> <artifactId>matrix-protocol-dubbo-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-starter</artifactId> <artifactId>matrix-protocol-web-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId> <artifactId>matrix-protocol-dubbo-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<!-- Aapche Dubbo --> <!-- Aapche Dubbo -->
......
# 介绍
mongodb-starter
# 特点
-
# 开始
- 添加依赖
- Maven:需要在自己项目的pom.xml增加,以下配置。
**注意:前置条件需要依赖项目中需要设置matrix的parent**
```xml
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>mongodb-starter</artifactId>
</dependency>
```
# 示例
# 介绍
monitor-starter
# 特点
-
# 开始
- 添加依赖
- Maven:需要在自己项目的pom.xml增加,以下配置。
**注意:前置条件需要依赖项目中需要设置matrix的parent**
```xml
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>monitor-starter</artifactId>
</dependency>
```
# 示例
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.3.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>monitor-starter</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<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
package com.secoo.matrix.monitor.config;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MonitorAutoConfiguration {
}
package com.secoo.matrix.monitor.constant;
/**
* @author qianglu
*/
public interface MonitorConstant {
String DEFAULT_PORT = "0000";
String DEFAULT_IP = "127.0.0.1";
String TRACE_ID = "traceId";
String RPC_ID = "rpcId";
String APPLICATION = "application";
String INTERFACE = "interface";
String METHOD = "method";
String GROUP = "group";
String VERSION = "version";
String CONSUMER = "consumer";
String PROVIDER = "provider";
String TIMESTAMP = "timestamp";
String SUCCESS = "success";
String FAILURE = "failure";
String ROLE = "Dubbo-RPC";
String ERROR_MSG = "errorMsg";
}
package com.secoo.matrix.monitor.filter;
import com.secoo.matrix.monitor.utils.TraceIDUtils;
import javax.servlet.*;
import java.io.IOException;
/**
* @author qianglu
*/
public class HttpTraceFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
try {
TraceIDUtils.continueTraceID();
filterChain.doFilter(servletRequest, servletResponse);
} catch (Exception e) {
}
}
@Override
public void destroy() {
}
}
package com.secoo.matrix.monitor.filter;
import com.secoo.matrix.monitor.constant.MonitorConstant;
import com.secoo.matrix.monitor.utils.TraceIDUtils;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
/**
* @author QIANGLU
*/
@Activate(group = {MonitorConstant.CONSUMER, MonitorConstant.PROVIDER}, order = -1)
public class LoggerFilter implements Filter {
private Logger LOG = LoggerFactory.getLogger(getClass());
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
RpcContext rpcContext = RpcContext.getContext();
URL url = rpcContext.getUrl();
try {
String who = url.getParameter("side");
//CONSUMER 从MDC中获取RPCID并增加其序列,传递最新序列唯一ID到下一层
if (MonitorConstant.CONSUMER.equals(who)) {
String traceId = TraceIDUtils.continueTraceID();
rpcContext.setAttachment(MonitorConstant.TRACE_ID, traceId);
} else if (MonitorConstant.PROVIDER.equals(who)) {
MDC.remove(MonitorConstant.TRACE_ID);
MDC.remove("rpcId");
String traceId = rpcContext.getAttachment(MonitorConstant.TRACE_ID);
TraceIDUtils.childTraceID(traceId);
}
} catch (Exception e) {
}
return invoker.invoke(invocation);
}
}
package com.secoo.matrix.monitor.http;
import com.secoo.matrix.monitor.utils.TraceIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author qianglu
* <p>
* 为了在Http请求入口生成TRACE_ID,日志ID
* </p>
*/
public class TraceInterceptor extends HandlerInterceptorAdapter {
private Logger logger = LoggerFactory.getLogger(TraceInterceptor.class);
private final ConcurrentMap<String, AtomicInteger> concurrents = new ConcurrentHashMap<>();
private ThreadLocal<Long> stime = new ThreadLocal<>();
/**
* This implementation always returns {@code true}.
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
try {
TraceIDUtils.continueTraceID();
// Long startTime = System.currentTimeMillis();
// stime.set(startTime);
// // 并发计数
// getConcurrent(request).incrementAndGet();
} catch (Exception e) {//容灾
}
return true;
}
/**
* This implementation is empty.
*/
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}
/**
* This implementation is empty.
*/
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) throws Exception {
try {
MDC.clear();
getConcurrent(request).decrementAndGet();
} catch (Exception e) {
}
}
// 获取并发计数器
private AtomicInteger getConcurrent(HttpServletRequest request) {
String key = request.getRequestURI();
AtomicInteger concurrent = concurrents.get(key);
if (concurrent == null) {
concurrents.putIfAbsent(key, new AtomicInteger());
concurrent = concurrents.get(key);
}
return concurrent;
}
}
package com.secoo.matrix.monitor.utils;
import com.secoo.matrix.monitor.constant.MonitorConstant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import java.math.BigDecimal;
/**
* 服务调用追踪号工具类
* 会使用到MDC
* <p>
* 规则:首层调用开始rpcId为"0.0"(TraceID已经生成),
* 如果有跨应用调用
* 1.调用方consumer会将rpcId追加1,例如0.0->0.1,并随RPCContext传递给下一层
* 2.服务方provider收到RPCContext,取出requestId放到本地MDC中并追加本地rpcId层级
* 例如,0.1->0.1.0
* </p>
*
* @author qianglu
*/
public class TraceIDUtils {
private static Logger log = LoggerFactory.getLogger(TraceIDUtils.class);
private final static String ZERO_DOT_ZERO = "0.0";
private final static String ZERO_DOT_ONE = "0.1";
private final static String ZERO_DOT_ONE_ZERO = "0.1.0";
private final static String H_BAR = "-";//横杠
/**
* 首次创建TraceID为UUID+"0.0",RpcID的初始值为"0.0"
*/
public static String createTraceID() {
StringBuilder sb = new StringBuilder();
String requestId = sb.append(UUIDUtils.randomUUID().toString()).append(H_BAR)
.append(ZERO_DOT_ZERO).toString();
MDC.put(MonitorConstant.TRACE_ID, requestId);
MDC.put(MonitorConstant.RPC_ID, ZERO_DOT_ZERO);
log.debug("Create New TraceID is [{}],RPCID is [{}]", requestId, ZERO_DOT_ZERO);
return requestId;
}
/**
* 追踪ID子层级追加,兼顾生成追踪ID
*
* @return
*/
public static String continueTraceID() {
StringBuilder sb = new StringBuilder();
//直接从本地MDC获取requestId
String traceID = MDC.get(MonitorConstant.TRACE_ID);
/*如果为空就生成一个新的.
* 之所以没有,可能服务消费者本身没有requestId初始化入口,所以这里补足
* requestId为UUID+"0.0"从0开始并赋值到本地MDC中,因为此方法为RPC调用下一级生成ID,所以返回的是UUID+"0.1"
* rpcId从"0.1"开始
* */
if (StringUtils.isEmpty(traceID) || "null".equals(traceID)) {
traceID = UUIDUtils.randomUUID().toString();
MDC.put(MonitorConstant.TRACE_ID, traceID + H_BAR + ZERO_DOT_ZERO);
MDC.put(MonitorConstant.RPC_ID, ZERO_DOT_ONE);
log.debug("There is no [traceID], create new noe![{}] and RPCID is [{}]",
traceID + H_BAR + ZERO_DOT_ZERO, ZERO_DOT_ONE);
return traceID + H_BAR + ZERO_DOT_ONE;
}
String rpcId = MDC.get(MonitorConstant.RPC_ID);
try {
/*正常追踪ID格式应该是 " 唯一字符串(UUID)-传递层次" .*/
String[] temp = traceID.split(H_BAR);
if (temp.length > 2) {
/*其它格式*/
} else if (temp.length == 2) {
if (StringUtils.isEmpty(rpcId)) {
/*如果rpcId为空,就是用requestId后缀层级号*/
MDC.put(MonitorConstant.RPC_ID, temp[1]);
rpcId = temp[1];
}
/*将rpcId,分解,最后一位的层级数值+1*/
String[] nums = rpcId.split("\\.");
for (int i = 0; i < nums.length; i++) {
if (i == (nums.length - 1)) {
sb.append(new BigDecimal(nums[i]).add(new BigDecimal("1")));
} else {
sb.append(nums[i]).append(".");
}
}
rpcId = sb.toString();//新的+1后的rpcId
log.debug("TraceID continued ![{}],and RPCID is [{}]",
temp[0] + "-" + sb.toString(), rpcId);
MDC.put(MonitorConstant.RPC_ID, rpcId);//更新本地MDC中的rpcId
return temp[0] + H_BAR + sb.toString();
} else if (temp.length < 2) {
/*可能不包含行号*/
}
} catch (Exception e) {
log.error("ContinueTraceID is failed!!!", e);
}
return traceID;
}
/**
* RPC调用层级追加
* 子层追加使用".1"来表示
* 例如第一层为0.1,调用一次后下一个应用为0.1.1,
*
* @param traceID
* @return
*/
public static void childTraceID(String traceID) {
StringBuilder sb = new StringBuilder();
if (StringUtils.isEmpty(traceID) || "null".equals(traceID)) {
/*如果为空就生成一个新的.
* 之所以没有,是消费者没有使用相同的requestId机制,所以本地重新生成
* requestId为UUID+"0.1"并赋值到本地MDC中,因为此方法为被调用,所以一定是下一级"
* rpcId从"0.1.0"开始
* */
traceID = sb.append(UUIDUtils.randomUUID().toString()).append(H_BAR)
.append(ZERO_DOT_ONE).toString();
MDC.put(MonitorConstant.TRACE_ID, traceID);
MDC.put(MonitorConstant.RPC_ID, ZERO_DOT_ONE_ZERO);
log.debug("There is no [traceID], create new noe![{}] and RPCID is [{}]", traceID,
ZERO_DOT_ONE_ZERO);
return;
}
String rpcId = MDC.get(MonitorConstant.RPC_ID);
try {
String[] temp = traceID.split(H_BAR);
if (temp.length > 2) {
/*其它格式*/
} else if (temp.length == 2) {
if (StringUtils.isEmpty(rpcId)) {
/*如果rpcId为空,就是用requestId后缀层级号*/
MDC.put(MonitorConstant.RPC_ID, temp[1]);
rpcId = temp[1];
}
rpcId = rpcId + ".0";
//更新本地MDC值,新增TraceID
MDC.put(MonitorConstant.RPC_ID, rpcId);
MDC.put(MonitorConstant.TRACE_ID, traceID);
log.debug("RPC_ID_KEY child is ![{}]", rpcId);
} else if (temp.length < 2) {
/*可能不包含行号*/
}
} catch (Exception e) {
log.error("ChildTraceID is failed!!!", e);
}
}
// public static void main(String[] args) {
//
// Logger log = LoggerFactory.getLogger(TraceIDUtils.class);
//
// TraceIDUtils.createTraceID();
// String s = "e591a82137f04423a4933cb0cff59374-0.2";
// MDC.put("requestId", "e591a82137f04423a4933cb0cff59374-0.0");
// MDC.put("rpcId", "0.2");
// System.out.println(TraceIDUtils.continueTraceID());
// MDC.remove(RPC_ID_KEY);
// TraceIDUtils.childTraceID("");
// }
}
# 介绍
openfeign-starter
# 特点
-
# 开始
- 添加依赖
- Maven:需要在自己项目的pom.xml增加,以下配置。
**注意:前置条件需要依赖项目中需要设置matrix的parent**
```xml
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>openfeign-starter</artifactId>
</dependency>
```
# 示例
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix</artifactId> <artifactId>matrix</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
<packaging>pom</packaging> <packaging>pom</packaging>
...@@ -14,19 +14,16 @@ ...@@ -14,19 +14,16 @@
<module>common-core</module> <module>common-core</module>
<module>common-util</module> <module>common-util</module>
<module>logger-starter</module> <module>logger-starter</module>
<module>redis-starter</module>
<module>matrix-mybatis</module> <module>matrix-mybatis</module>
<module>mongodb-starter</module>
<module>elasticsearch-starter</module>
<module>openfeign-starter</module>
<module>matrix-mq</module> <module>matrix-mq</module>
<module>monitor-starter</module>
<module>config-starter</module> <module>config-starter</module>
<module>matrix-protocol</module> <module>matrix-protocol</module>
<module>matrix-datasource</module> <module>matrix-datasource</module>
<module>rocketmq-starter</module>
<module>matrix-job</module> <module>matrix-job</module>
<module>matrix-bigdata</module> <module>matrix-bigdata</module>
<module>matrix-bus</module>
<module>matrix-datahelper</module>
<module>matrix-client</module>
</modules> </modules>
...@@ -47,7 +44,7 @@ ...@@ -47,7 +44,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId> <artifactId>spring-boot-dependencies</artifactId>
<version>2.1.9.RELEASE</version> <version>2.2.5.RELEASE</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
...@@ -55,116 +52,110 @@ ...@@ -55,116 +52,110 @@
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId> <artifactId>logger-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>monitor-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>config-starter</artifactId> <artifactId>config-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>common-util</artifactId> <artifactId>common-util</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>redis-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-datasource-druid</artifactId> <artifactId>matrix-datasource-druid</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-mybatis-starter</artifactId> <artifactId>matrix-mybatis-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>mongodb-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>elasticsearch-starter</artifactId> <artifactId>matrix-mq-rocketmq-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-core</artifactId> <artifactId>matrix-mq-rocketmq-client</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>rocketmq-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-rocketmq-starter</artifactId>
<version>1.3.2.RELEASE</version>
</dependency> </dependency>
<!--rocketmq-starter废弃,启用matrix-mq-rocketmq-starter-->
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>openfeign-starter</artifactId> <artifactId>matrix-mq-rocketmq-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-core</artifactId> <artifactId>matrix-protocol-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-core</artifactId> <artifactId>matrix-protocol-dubbo-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-dubbo-starter</artifactId> <artifactId>matrix-protocol-dubbo-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-core</artifactId> <artifactId>matrix-protocol-web-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-protocol-web-starter</artifactId> <artifactId>matrix-protocol-web-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-job-xxl-core</artifactId> <artifactId>matrix-job-xxl-core</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-job-xxl-starter</artifactId> <artifactId>matrix-job-xxl-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.secoo.mall</groupId> <groupId>com.secoo.mall</groupId>
<artifactId>matrix-bigdata-hbase-starter</artifactId> <artifactId>matrix-bigdata-hbase-starter</artifactId>
<version>1.3.2.RELEASE</version> <version>2.0.1.RELEASE</version>
</dependency>
<!--redis-->
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-core</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-client-openfeign-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency> </dependency>
<!--普通jar--> <!--普通jar-->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
...@@ -205,8 +196,24 @@ ...@@ -205,8 +196,24 @@
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
<version>2.10</version> <version>2.10</version>
</dependency> </dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>
<!--protobuf-->
<dependency> <dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.11.4</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.11.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>20.0</version> <version>20.0</version>
...@@ -231,6 +238,7 @@ ...@@ -231,6 +238,7 @@
<artifactId>apollo-client</artifactId> <artifactId>apollo-client</artifactId>
<version>1.4.0</version> <version>1.4.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
# 介绍
redis-starter
# 特点
-
# 开始
- 添加依赖
- Maven:需要在自己项目的pom.xml增加,以下配置。
**注意:前置条件需要依赖项目中需要设置matrix的parent**
```xml
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>redis-starter</artifactId>
</dependency>
```
# 示例
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