淘宝TDDL配置以及使用
此章节具体介绍一下淘宝TDDL具体配置和使用
1. Spring配置文件配置:
================spring-mybatis.xml 中配置=============
<bean id="dataSource" class="com.taobao.tddl.group.jdbc.TGroupDataSource" init-method="init" destroy-method="destroyDataSource">
<!-
appName gome_market_search_index :应用名称 名字随意起 有意义即可
dbGroupKey gome_market_search_index_group_0 :db组 名字随意起有意义即可 主要作用: 可以配置多个数据源 作为一组
->
<property name="appName" value="gome_market_search_index" />
<property name="dbGroupKey" value="gome_market_search_index_group_0" />
</bean>
2.1 用一张图了解TDDL配置
2.2 TDDL需要结合diamond使用,以下是diamond需要的相关配置,必须配置到默认组下 DEFAULT_GROUP
2.3===========配置数据源(ip端口等)===========
##com.taobao.tddl.atom.global.数据源名称 (gome_market_search_index_db_0)
com.taobao.tddl.atom.global.gome_market_search_index_db_0
##数据库ip地址
ip=10.144.43.141
#数据库端口
port=3306
##数据库名称
dbName=gome_market_prod
##数据库类型
dbType=mysql
#数据库状态
dbStatus=RW 2.4===========配置数据源(连接池)==============
##com.taobao.tddl.atom.app.应用名称.数据源名
com.taobao.tddl.atom.app.gome_market_search_index.gome_market_search_index_db_0
#数据库用户
userName=root
#最小连接数
minPoolSize=50
#最大连接数
maxPoolSize=100
#连接的最大空闲时间
idleTimeout=10
#等待连接的最大时间
blockingTimeout=5000
#预处理缓存大小
preparedStatementCacheSize=50
#数据库连接属性
connectionProperties=autoReconnect=true&useUnicode=true&characterEncoding=UTF-8 2.5===========配置数据库(com.taobao.tddl.atom.passwd.数据库名.mysql.用户名)==========
com.taobao.tddl.atom.passwd.gome_market_prod.mysql.root ##数据库密码 root
encPasswd=-64d29910cc13d220ea2e89c490b1e4bf
encKey=f97xK9qh3BSXv5iy 2.6============配置dbGroup=====================
com.taobao.tddl.jdbc.group_V2.4.1_gome_market_search_index_group_0 #w0r1 0个读库连接 1个读库连接
gome_market_search_index_db_0:w0r1
上记2.5章节encPasswd 需要加密操作,根据encKey加密
SecureIdentityLoginModule.java 将代码拷贝到工程运行
package service; import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec; import org.apache.commons.lang.StringUtils; public class SecureIdentityLoginModule { private static byte[] ENC_KEY_BYTES = "This is a finger".getBytes(); private String userName; private String password; public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getDecodedPassword() throws Exception {
return new String(decode(password));
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((userName == null) ? 0 : userName.hashCode());
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SecureIdentityLoginModule other = (SecureIdentityLoginModule) obj;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
return true;
} public static String encode(String encKey, String secret) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] kbytes = SecureIdentityLoginModule.ENC_KEY_BYTES;
if (StringUtils.isNotBlank(encKey)) {
kbytes = encKey.getBytes();
}
SecretKeySpec key = new SecretKeySpec(kbytes, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
} public static String encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
return SecureIdentityLoginModule.encode(null, secret);
} public static String decode(String encKey, String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
byte[] kbytes = SecureIdentityLoginModule.ENC_KEY_BYTES;
if (StringUtils.isNotBlank(encKey)) {
kbytes = encKey.getBytes();
}
SecretKeySpec key = new SecretKeySpec(kbytes, "AES");
BigInteger n = new BigInteger(secret, 16);
byte[] encoding = n.toByteArray();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decode = cipher.doFinal(encoding);
return new String(decode);
} public static char[] decode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
return SecureIdentityLoginModule.decode(null, secret).toCharArray();
} public static void main(String[] args) throws Exception {
System.out.println("Encoded password: " + new String(SecureIdentityLoginModule.encode("f97xK9qh3BSXv5iy","root")));
System.out.println("decoded password: " + new String(SecureIdentityLoginModule.decode("5a826c8121945c969bf9844437e00e28")));
}
}
如果没有配置encKey 需要在diamond配置 一个dms组 dataid:decryptPasswordUrl 需要配置密码验证策略 建议不使用

3.工程pom文件中引入依赖 注意:此依赖不作为公共依赖
<dependency>
<groupId>com.taobao.tddl</groupId>
<artifactId>tddl-matrix</artifactId>
<version>5.1.7.g1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>tddl-repo-demo</artifactId>
<groupId>com.taobao.tddl</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.taobao.tddl</groupId>
<artifactId>tddl-config-diamond</artifactId>
<version>5.1.7.g1-SNAPSHOT</version>
</dependency>
4.使用中遇到的问题解决 maven工程排除此版本的依赖即可

淘宝TDDL配置以及使用的更多相关文章
- [转帖]剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)
剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER) 博客分类: 原博客地址: http://qq85609655.iteye.com/blog/2035176 distrib ...
- TDDL-剖析淘宝TDDL
TDDL-剖析淘宝TDDL 学习了:https://blog.csdn.net/sumj7011/article/details/78286741 Taobao Distribute Data Lay ...
- 带你剖析淘宝TDDL——Matrix层的分库分表配置与实现
前言 在开始讲解淘宝的TDDL(Taobao Distribute Data Layer)技术之前,请允许笔者先吐槽一番.首先要开喷的是淘宝的社区支持做的无比的烂,TaoCode开源社区上面,几乎从来 ...
- 笔者带你剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)
注:本文部分内容引用本人博客http://gao-xianglong.iteye.com/blog/1973591 前言 在开始讲解淘宝的TDDL(Taobao Distribute Data L ...
- 淘宝TDDL深入浅出
前言 在开始讲解淘宝的 TDDL(Taobao Distribute Data Layer) 技术之前,请允许笔者先吐槽一番.首先要开喷的是淘宝的社区支持做的无比的烂, TaoCode 开源社区上面, ...
- npm淘宝镜像配置
npm config set registry https://registry.npm.taobao.org
- 淘宝分布式数据层TDDL
剖析淘宝 TDDL ( TAOBAO DISTRIBUTE DATA LAYER ) 注:原文:http://gao-xianglong.iteye.com/blog/1973591 前言 在开始 ...
- TDDL:来自淘宝的分布式数据层
淘宝根据自身业务需求研发了TDDL(Taobao Distributed Data Layer)框架,主要用于解决分库分表场景下的访问路由(持久层与数据访问层的配合)以及异构数据库之间的数据同步,它是 ...
- 淘宝分布式数据层:TDDL[转]
淘宝根据自己的业务特点开发了TDDL(Taobao Distributed Data Layer 外号:头都大了 ©_Ob)框架,主要解决了分库分表对应用的透明化以及异构数据库之间的数据复制,它是一个 ...
随机推荐
- Spring AOP统一异常处理
1.添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- Eclipse+Spark搭建源码分析环境问题分析
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- Javascript中的函数数学运算
1.Math函数与属性使用语法 Math.方法名(参数1,参数2,...); Math.属性; 说明 Math函数可以没有参数,比如Math.random()函数,或有多个参数,比如Math.max( ...
- 【Thinking in Java, 4e】控制流程执行
p46~p75: [迭代] 1.Java不允许将数字作为布尔值用. 1.有点意思的小程序WhileTest. public class WhileTest { static boolean condi ...
- Centos编译安装 LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.5.8)+ Redis
转载地址:http://www.cnblogs.com/whoamme/p/3530056.html 软件源代码包存放位置:/usr/local/src 源码包编译安装位置:/usr/local/软件 ...
- Apache 部署HTTPS
Apache 部署HTTPS 系统:Linux Centos 7.4 x64 应用:Apache 2.4.6 需要安装:mod_ssl 注:确认开启 Include conf/extra/httpd- ...
- Vue数据绑定失效
首先,我们得明白Vue数据响应的原理: 以对象为例:当把一个JavaScript对象传给Vue实例的data选项时,Vue将遍历此对象所有的属性,并使用Object.defineProperty把这些 ...
- windows上面非常好用的辅助软件
1.everything 快速查找本地文件 下载地址:http://www.voidtools.com/
- 正则表达式-RegExp-常用正则表达式
正则表达式-RegExp-常用正则表达式 作者:nuysoft/JS攻城师/高云 QQ:47214707 EMail:nuysoft@gmail.com 声明:本文为原创文章,如需转载,请注明来源 ...
- 【Network Architecture】Feature Pyramid Networks for Object Detection(FPN)论文解析(转)
目录 0. 前言 1. 博客一 2.. 博客二 0. 前言 这篇论文提出了一种新的特征融合方式来解决多尺度问题, 感觉挺有创新性的, 如果需要与其他网络进行拼接,还是需要再回到原文看一下细节.这里 ...

