1:删除37与149对14:APP_SUBSCRIBE_ID表的支持

2:为日志查询的url字段做左匹配处理
3:修改测试程序打印表达式
4:加配置同步到集群库的定时任务
This commit is contained in:
RenKaiGe-Office
2018-09-11 18:18:56 +08:00
parent a8b1c53d76
commit 50211f4ea7
10 changed files with 349 additions and 434 deletions

View File

@@ -0,0 +1,103 @@
package com.nis.util;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
public class JedisClusterFactory implements FactoryBean<JedisCluster>, InitializingBean {
private Resource addressConfig;
private String addressKeyPrefix;
private JedisCluster jedisCluster;
private Integer timeout;
private Integer maxRedirections;
private GenericObjectPoolConfig genericObjectPoolConfig;
private Pattern p = Pattern.compile("^.+[:]\\d{1,5}\\s*$");
@Override
public JedisCluster getObject() throws Exception {
return jedisCluster;
}
@Override
public Class<? extends JedisCluster> getObjectType() {
return (this.jedisCluster != null ? this.jedisCluster.getClass() : JedisCluster.class);
}
@Override
public boolean isSingleton() {
return true;
}
private Set<HostAndPort> parseHostAndPort() throws Exception {
try {
Properties prop = new Properties();
prop.load(this.addressConfig.getInputStream());
Set<HostAndPort> haps = new HashSet<HostAndPort>();
for (Object key : prop.keySet()) {
if (!((String) key).startsWith(addressKeyPrefix)) {
continue;
}
String val = (String) prop.get(key);
boolean isIpPort = p.matcher(val).matches();
if (!isIpPort) {
throw new IllegalArgumentException("ip 或 port 不合法");
}
String[] ipAndPort = val.split(":");
HostAndPort hap = new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
haps.add(hap);
}
return haps;
} catch (IllegalArgumentException ex) {
throw ex;
} catch (Exception ex) {
throw new Exception("解析 jedis 配置文件失败", ex);
}
}
@Override
public void afterPropertiesSet() throws Exception {
Set<HostAndPort> haps = this.parseHostAndPort();
jedisCluster = new JedisCluster(haps, timeout, maxRedirections, genericObjectPoolConfig);
}
public void setAddressConfig(Resource addressConfig) {
this.addressConfig = addressConfig;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public void setMaxRedirections(int maxRedirections) {
this.maxRedirections = maxRedirections;
}
public void setAddressKeyPrefix(String addressKeyPrefix) {
this.addressKeyPrefix = addressKeyPrefix;
}
public void setGenericObjectPoolConfig(GenericObjectPoolConfig genericObjectPoolConfig) {
this.genericObjectPoolConfig = genericObjectPoolConfig;
}
}

View File

@@ -153,7 +153,8 @@ public class MaatTestController {
configCompileList.add(getConfigCompile(ser)); configCompileList.add(getConfigCompile(ser));
} }
String jsonString = JsonMapper.toJsonString(configCompileList); String jsonString = JsonMapper.toJsonString(configCompileList);
System.out.println(jsonString); FileUtils.addStrToFile("下发的json串是"+jsonString+"\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
// 保存测试配置 // 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb); configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
for (ConfigCompile configCompile : configCompileList) { for (ConfigCompile configCompile : configCompileList) {
@@ -179,7 +180,8 @@ public class MaatTestController {
configCompileList.add(getConfigCompile(service)); configCompileList.add(getConfigCompile(service));
} }
String jsonString = JsonMapper.toJsonString(configCompileList); String jsonString = JsonMapper.toJsonString(configCompileList);
System.out.println(jsonString); FileUtils.addStrToFile("下发的json串是"+jsonString+"\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
// 保存测试配置 // 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb); configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
for (ConfigCompile configCompile : configCompileList) { for (ConfigCompile configCompile : configCompileList) {

View File

@@ -129,8 +129,13 @@ public class HiveSqlService {
} }
if (!Constants.ISUSECLICKHOUSE) {// hive写法 if (!Constants.ISUSECLICKHOUSE) {// hive写法
if (typeName.equals("java.lang.String")) { if (typeName.equals("java.lang.String")) {
whereSB.append(" and " + filedAndColumnMap.get(key) + "='" String field = filedAndColumnMap.get(key);
+ value.toString().trim() + "'"); if (field.equals("url")) {
whereSB.append(
" and " + field + " like '" + value.toString().trim() + "%'");
} else {
whereSB.append(" and " + field + "='" + value.toString().trim() + "'");
}
} else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) { } else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) {
whereSB.append( whereSB.append(
" and " + filedAndColumnMap.get(key) + "=" + value.toString().trim()); " and " + filedAndColumnMap.get(key) + "=" + value.toString().trim());
@@ -142,8 +147,13 @@ public class HiveSqlService {
} else {// clickhouse写法 } else {// clickhouse写法
String type = filedsType.get(key).trim(); String type = filedsType.get(key).trim();
if (type.equals("java.lang.String")) { if (type.equals("java.lang.String")) {
whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "='" String field = filedAndColumnMap.get(key).toLowerCase();
+ value.toString().trim() + "'"); if (field.equals("url")) {
whereSB.append(
" and " + field + " like '" + value.toString().trim() + "%'");
} else {
whereSB.append(" and " + field + "='" + value.toString().trim() + "'");
}
} else if (type.equals("java.lang.Integer") || type.equals("int") } else if (type.equals("java.lang.Integer") || type.equals("int")
|| type.equals("java.lang.Long") || type.equals("long")) { || type.equals("java.lang.Long") || type.equals("long")) {
whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "=" whereSB.append(" and " + filedAndColumnMap.get(key).toLowerCase() + "="

View File

@@ -159,6 +159,13 @@ public class MaatTestServiceimpl {
} }
} }
String val = JedisUtils.get(key, redisDb); String val = JedisUtils.get(key, redisDb);
FileUtils.addStrToFile("\t\t入库的key=" + key + "\n", Configurations.getStringProperty("maatTestLogPath", ""),
true);
FileUtils.addStrToFile("\t\t入库的val=" + val, Configurations.getStringProperty("maatTestLogPath", ""),
true);
FileUtils.addStrToFile("\t\t表达式" + maatXmlExpr.getValueExpression() + "\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
valArr = val.split("\\t"); valArr = val.split("\\t");
break; break;
} }

View File

@@ -0,0 +1,173 @@
package com.nis.web.task;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.nis.util.Configurations;
import com.nis.util.ExceptionUtil;
import com.nis.util.JedisUtils;
import com.nis.web.service.restful.ConfigJedisServiceimpl;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Tuple;
import redis.clients.util.JedisClusterCRC16;
@Component
@PropertySource(value = { "classpath:nis.properties", "classpath:jdbc.properties" })
public class SyncRedisToCluster {
private static Logger logger = LoggerFactory.getLogger(ConfigJedisServiceimpl.class);
private static int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14);
@Autowired
private JedisCluster jedisCluster;
// @Scheduled(cron = "0/3 * * * * ?")
@Scheduled(cron = "${syncRedisToClusterCron}")
public void syncRedisToCluster() {
try {
// keys("EFFECTIVE_RULE*");
// keys("OBSOLETE_RULE*");
String clusterMaatVersionStr = jedisCluster.get("MAAT_VERSION");
String redisMaatVersionStr = JedisUtils.get("MAAT_VERSION", redisStatisticsRealDBIndex);
if (clusterMaatVersionStr != null && !clusterMaatVersionStr.trim().equals("")) {
Integer clusterMaatVersion = Integer.valueOf(clusterMaatVersionStr);
Integer redisMaatVersion = Integer.valueOf(redisMaatVersionStr);
if (redisMaatVersion < clusterMaatVersion) {// 如果主从库比集群库的版本号小则下发全量
logger.info("redis集群中的MAAT_VERSION为大于配置库中的MAAT_VERSION,开始执行全量同步");
syncAllData(redisMaatVersionStr);
} else if (redisMaatVersion > clusterMaatVersion) {// 获取增量的数据
logger.info("redis集群中的MAAT_VERSION为小于配置库中的MAAT_VERSION,开始执行增量同步,score是" + clusterMaatVersion + "-"
+ redisMaatVersion);
syncData(clusterMaatVersion.doubleValue(), redisMaatVersion.doubleValue(), redisMaatVersionStr);
} else {
logger.info("redis集群中的MAAT_VERSION与配置库中的MAAT_VERSION相等,暂不执行配置同步操作");
}
} else {
logger.info("redis集群中的MAAT_VERSION为null,开始执行全量同步");
syncAllData(redisMaatVersionStr);
}
} catch (Exception e) {
logger.error("同步配置库配置到3A-redisCluster失败,失败原因:" + ExceptionUtil.getExceptionMsg(e));
}
}
public void deleteRedisKeyStartWith(String redisKeyStartWith) {
try {
Map<String, JedisPool> clusterNodes = jedisCluster.getClusterNodes();
for (Map.Entry<String, JedisPool> entry : clusterNodes.entrySet()) {
Jedis jedis = entry.getValue().getResource();
// 判断非从节点(因为若主从复制,从节点会跟随主节点的变化而变化)
if (!jedis.info("replication").contains("role:slave")) {
Set<String> keys = jedis.keys(redisKeyStartWith + "*");
if (keys.size() > 0) {
Map<Integer, List<String>> map = new HashMap<>();
for (String key : keys) {
// cluster模式执行多key操作的时候这些key必须在同一个slot上不然会报:JedisDataException:
// CROSSSLOT Keys in request don't hash to the same slot
int slot = JedisClusterCRC16.getSlot(key);
// 按slot将key分组相同slot的key一起提交
if (map.containsKey(slot)) {
map.get(slot).add(key);
} else {
ArrayList<String> list = new ArrayList<String>();
list.add(key);
map.put(slot, list);
}
}
for (Map.Entry<Integer, List<String>> integerListEntry : map.entrySet()) {
jedis.del(integerListEntry.getValue()
.toArray(new String[integerListEntry.getValue().size()]));
// jedisCluster.del(integerListEntry.getValue()
// .toArray(new String[integerListEntry.getValue().size()]));
}
}
}
}
} finally {
}
}
public TreeSet<String> keys(String pattern) {
TreeSet<String> keys = new TreeSet<>();
// 获取所有的节点
Map<String, JedisPool> clusterNodes = jedisCluster.getClusterNodes();
// 遍历节点 获取所有符合条件的KEY
for (String k : clusterNodes.keySet()) {
logger.info("Getting keys from: {}", k);
JedisPool jp = clusterNodes.get(k);
Jedis connection = jp.getResource();
try {
keys.addAll(connection.keys(pattern));
} catch (Exception e) {
logger.error("从{}获取{}失败,失败原因{}", k, pattern, e);
} finally {
connection.close();// 用完一定要close这个链接
}
}
// for (String string : keys) {
// System.out.println(string);
// }
logger.debug("Keys gotten!");
return keys;
}
public void syncAllData(String version) {
// 先清空集群库配置数据
if (jedisCluster.exists("MAAT_UPDATE_STATUS")) {
jedisCluster.del("MAAT_UPDATE_STATUS");
logger.info("删除MAAT_UPDATE_STATUS成功");
}
if (jedisCluster.exists("MAAT_VERSION")) {
jedisCluster.del("MAAT_VERSION");
logger.info("删除MAAT_VERSION成功");
}
deleteRedisKeyStartWith("EFFECTIVE_RULE*");
logger.info("删除EFFECTIVE_RULE*成功");
deleteRedisKeyStartWith("OBSOLETE_RULE*");
logger.info("删除OBSOLETE_RULE*成功");
syncData(null, null, version);
}
public void syncData(Double min, Double max, String verion) {
Jedis resource = JedisUtils.getResource(redisStatisticsRealDBIndex);
Set<Tuple> zrangeByScoreWithScores = null;
if (min == null && max == null) {
zrangeByScoreWithScores = resource.zrangeByScoreWithScores("MAAT_UPDATE_STATUS", "-inf", "+inf");// 获取所有的maat_update_status
} else {
zrangeByScoreWithScores = resource.zrangeByScoreWithScores("MAAT_UPDATE_STATUS", min, max);// 获取增量的数据
}
for (Tuple tuple : zrangeByScoreWithScores) {
String key = tuple.getElement();
String zset = key;
double score = tuple.getScore();
if (key.contains("ADD")) {
key = key.replace("ADD,", "EFFECTIVE_RULE:");
} else if (key.contains("DEL")) {
key = key.replace("DEL,", "OBSOLETE_RULE:");
}
String val = JedisUtils.get(key, redisStatisticsRealDBIndex);
if (val != null && !val.trim().equals("")) {
jedisCluster.set(key, val);
}
jedisCluster.zadd("MAAT_UPDATE_STATUS", score, zset);
// jedisCluster.incr("MAAT_VERSION");
}
jedisCluster.set("MAAT_VERSION", verion);
logger.info("向redis集群同步数据成功");
}
}

View File

@@ -66,7 +66,7 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16;
#0x24 隧道行为阻断 #0x24 隧道行为阻断
36=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 36=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE
#0x25 ASN IP阻断 #0x25 ASN IP阻断
37=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 37=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;18:NTC_IP_RANGE
#0x80 IP地址监测 #0x80 IP地址监测
128=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_IP;14:NTC_SUBSCRIBE_ID;18:NTC_IP_RANGE 128=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_IP;14:NTC_SUBSCRIBE_ID;18:NTC_IP_RANGE
@@ -107,7 +107,7 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16;
#0x94 隧道行为监测 #0x94 隧道行为监测
148=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 148=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE
#0x95 ASN IP监测 #0x95 ASN IP监测
149=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 149=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;18:NTC_IP_RANGE
#0xA0 通联关系监测 monit 无配置 #0xA0 通联关系监测 monit 无配置
#0xA1 邮件泛收 monit 无配置 #0xA1 邮件泛收 monit 无配置

View File

@@ -26,430 +26,24 @@
<property name="testOnReturn" value="${redis.testOnReturn}" /> <property name="testOnReturn" value="${redis.testOnReturn}" />
</bean> </bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool"> <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor-arg name="poolConfig" ref="poolConfig" /> <constructor-arg name="poolConfig" ref="poolConfig" />
<constructor-arg name="host" value="${redis.host}" /> <constructor-arg name="host" value="${redis.host}" />
<constructor-arg name="port" value="${redis.port}" type="int" /> <constructor-arg name="port" value="${redis.port}"
</bean> type="int" />
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
<bean id="connectionFactory0"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="0" />
<!-- p:password="" scope="prototype" -->
<bean id="connectionFactory1"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="1" />
<bean id="connectionFactory2"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="2" />
<!-- p:password="" scope="prototype" -->
<bean id="connectionFactory3"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="3" />
<bean id="connectionFactory4"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="4" />
<bean id="connectionFactory5"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="5" />
<bean id="connectionFactory6"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="6" />
<bean id="connectionFactory7"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="7" />
<bean id="connectionFactory8"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="8" />
<bean id="connectionFactory9"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="9" />
<bean id="connectionFactory10"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="10" />
<bean id="connectionFactory14"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="14" />
<bean id="connectionFactory15"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="15" />
<bean id="stringRedisSerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplate0" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory0" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate1" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory1" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate2" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory2" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate3" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory3" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate4" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory4" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate5" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory5" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate6" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory6" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate7" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory7" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate8" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory8" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate9" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory9" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate10" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory10" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate14" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory14" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate15" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory15" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<!--设置没有事务的redistemplate,用于判断key是否存在 -->
<!-- 默认使用数据库0,设置connectionFactory为非单例模式,方便选择redis数据库 -->
<bean id="conn0"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="0" />
<!-- p:password="" scope="prototype" -->
<bean id="conn1"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="1" />
<bean id="conn2"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="2" />
<!-- p:password="" scope="prototype" -->
<bean id="conn3"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="3" />
<bean id="conn4"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="4" />
<bean id="conn5"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="5" />
<bean id="conn6"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="6" />
<bean id="conn7"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="7" />
<bean id="conn8"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="8" />
<bean id="conn9"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="9" />
<bean id="conn10"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="10" />
<bean id="conn15"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="15" />
<bean id="conn14"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="14" />
<bean id="redisTemplateNoTrans0" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn0" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans1" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn1" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans2" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn2" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans3" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn3" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans4" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn4" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans5" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn5" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans6" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn6" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans7" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn7" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans8" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn8" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans9" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn9" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans10" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn10" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans15" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn15" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans14" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn14" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean> </bean>
<bean id="jedisCluster" class="com.nis.util.JedisClusterFactory">
<property name="addressConfig">
<value>classpath:jdbc.properties</value>
</property>
<property name="addressKeyPrefix" value="cluster" /> <!-- 属性文件里 key的前缀 -->
<property name="timeout" value="${redis.timeout}" />
<property name="maxRedirections" value="${redis.maxRedirects}" />
<property name="genericObjectPoolConfig" ref="poolConfig" />
</bean>
</beans> </beans>

View File

@@ -136,10 +136,23 @@ redis.host=10.0.6.249
#redis.host=192.168.10.215 #redis.host=192.168.10.215
#亦庄演示环境 #亦庄演示环境
#redis.host=10.3.34.1 #redis.host=10.3.34.1
redis.port=6379 redis.port=6381
redis.pass= redis.pass=
redis.maxIdle=5 redis.maxIdle=5
redis.maxTotal=250 redis.maxTotal=250
redis.maxWaitMillis=100000 redis.maxWaitMillis=100000
redis.testOnBorrow=true redis.testOnBorrow=true
redis.testOnReturn=true redis.testOnReturn=true
#客户端超时时间单位是毫秒
redis.timeout=100000
#用于 redis.clients.jedis.JedisCluster.JedisCluster(Set<HostAndPort>, int, int, GenericObjectPoolConfig) 第三个参数 maxRedirections
#默认值是5
#一般当此值设置过大时容易报Too many Cluster redirections
redis.maxRedirects=3
cluster1.host.port=192.168.10.205:7031
cluster2.host.port=192.168.10.205:7032
cluster3.host.port=192.168.10.205:7033
cluster4.host.port=192.168.10.205:7034
cluster5.host.port=192.168.10.205:7035

View File

@@ -207,3 +207,6 @@ redisStatisticsRealDBIndex=14
maatTestLogPath=c:/maat/mmat.log maatTestLogPath=c:/maat/mmat.log
#样例文件存放目录,{tableType}和{fileName}会替换成具体内容 #样例文件存放目录,{tableType}和{fileName}会替换成具体内容
mmSampleDstPath=/home/mesasoft/{tableType}/full/{fileName} mmSampleDstPath=/home/mesasoft/{tableType}/full/{fileName}
##定时将redis主从库的实时统计数据同步到redis集群中
syncRedisToClusterCron=0/10 * * * * ?

View File

@@ -19,7 +19,9 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd"> http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 加载配置属性文件 --> <!-- 加载配置属性文件 -->
@@ -44,6 +46,14 @@
<!-- 默认注解映射支持 --> <!-- 默认注解映射支持 -->
<mvc:annotation-driven /> <mvc:annotation-driven />
<!-- 配置任务线性池 -->
<task:executor id="executor" pool-size="5"></task:executor>
<task:scheduler id="scheduler" pool-size="5"></task:scheduler>
<!-- 开启定时任务注解 -->
<task:annotation-driven scheduler="scheduler"
executor="executor" />
<bean class="com.nis.restful.SwaggerConfig" /> <bean class="com.nis.restful.SwaggerConfig" />
<!-- redis 工具类 --> <!-- redis 工具类 -->