Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
loit-shardingsphere-seata-nacos-feign-provider
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure-example
loit-shardingsphere-seata-nacos-feign-provider
Commits
c1e67cb2
提交
c1e67cb2
authored
2月 13, 2020
作者:
陈世营
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
分表测试
上级
f61c8030
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
140 行增加
和
6 行删除
+140
-6
DemoController.java
...ngsphere/seata/nacos/feign/controller/DemoController.java
+5
-2
IBusinessService.java
...e/seata/nacos/feign/modules/service/IBusinessService.java
+6
-0
BusinessServiceImpl.java
...nacos/feign/modules/service/impl/BusinessServiceImpl.java
+30
-4
application-sharding-tables.yml
...r-main/src/main/resources/application-sharding-tables.yml
+99
-0
没有找到文件。
loit-shardingsphere-seata-nacos-feign-provider-main/src/main/java/com/loit/shardingsphere/seata/nacos/feign/controller/DemoController.java
浏览文件 @
c1e67cb2
...
...
@@ -5,7 +5,6 @@ import com.loit.shardingsphere.seata.nacos.feign.modules.entity.OrderEntity;
import
com.loit.shardingsphere.seata.nacos.feign.modules.service.IBusinessService
;
import
com.loit.shardingsphere.seata.nacos.feign.modules.service.IOrderService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -30,7 +29,11 @@ public class DemoController {
@GetMapping
(
"purchase"
)
public
void
purchase
()
{
for
(
long
i
=
1
;
i
<
20
;
i
++)
{
businessService
.
purchase
(
i
);
try
{
businessService
.
purchase
(
i
);
}
catch
(
Exception
e
)
{
log
.
info
(
e
.
getMessage
(),
e
);
}
}
log
.
info
(
"success"
);
}
...
...
loit-shardingsphere-seata-nacos-feign-provider-main/src/main/java/com/loit/shardingsphere/seata/nacos/feign/modules/service/IBusinessService.java
浏览文件 @
c1e67cb2
...
...
@@ -2,5 +2,11 @@ package com.loit.shardingsphere.seata.nacos.feign.modules.service;
public
interface
IBusinessService
{
/**
* 分库分表
*/
void
purchase
(
Long
userId
);
}
loit-shardingsphere-seata-nacos-feign-provider-main/src/main/java/com/loit/shardingsphere/seata/nacos/feign/modules/service/impl/BusinessServiceImpl.java
浏览文件 @
c1e67cb2
...
...
@@ -3,12 +3,12 @@ package com.loit.shardingsphere.seata.nacos.feign.modules.service.impl;
import
com.loit.shardingsphere.seata.nacos.feign.modules.entity.OrderEntity
;
import
com.loit.shardingsphere.seata.nacos.feign.modules.service.IBusinessService
;
import
com.loit.shardingsphere.seata.nacos.feign.modules.service.IOrderService
;
import
io.seata.spring.annotation.GlobalTransactional
;
import
org.apache.shardingsphere.transaction.annotation.ShardingTransactionType
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.apache.shardingsphere.transaction.core.TransactionTypeHolder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
@Service
(
"businessService"
)
public
class
BusinessServiceImpl
implements
IBusinessService
{
...
...
@@ -16,14 +16,20 @@ public class BusinessServiceImpl implements IBusinessService {
@Autowired
IOrderService
orderService
;
/**
* 分库分表 使用全局事务
*
* @param userId
*/
@Override
@ShardingTransactionType
(
TransactionType
.
BASE
)
@GlobalTransactional
@ShardingTransactionType
(
TransactionType
.
LOCAL
)
//@GlobalTransactional
@Transactional
public
void
purchase
(
Long
userId
)
{
if
(
userId
==
null
)
{
return
;
}
TransactionTypeHolder
.
set
(
TransactionType
.
BASE
);
TransactionTypeHolder
.
set
(
TransactionType
.
LOCAL
);
OrderEntity
orderEntity
=
new
OrderEntity
();
orderEntity
.
setOrderId
(
userId
);
orderEntity
.
setStatus
(
"seata"
);
...
...
@@ -32,4 +38,24 @@ public class BusinessServiceImpl implements IBusinessService {
//throw new RuntimeException("回滚测试");
}
/**
* 分表 使用本地事务
* @param userId
*/
// @Override
// @ShardingTransactionType(TransactionType.LOCAL)
// @Transactional
// public void purchase(Long userId) {
// if (userId == null) {
// return;
// }
// TransactionTypeHolder.set(TransactionType.LOCAL);
// OrderEntity orderEntity = new OrderEntity();
// orderEntity.setOrderId(userId);
// orderEntity.setStatus("seata");
// orderEntity.setUserId(userId.intValue());
// orderService.insertOrder(orderEntity);
// throw new RuntimeException("回滚测试");
// }
}
loit-shardingsphere-seata-nacos-feign-provider-main/src/main/resources/application-sharding-tables.yml
0 → 100644
浏览文件 @
c1e67cb2
server
:
port
:
8090
spring
:
application
:
name
:
loit-shardingshere
cloud
:
nacos
:
discovery
:
# Nacos 注册中心地址
server-addr
:
39.100.254.140:8103
namespace
:
3ac84119-5558-4bf8-b309-034dd0e458e0
aop
:
#使用CGLIB来实现AOP的时候
proxy-target-class
:
true
shardingsphere
:
datasource
:
names
:
ds
ds
:
type
:
com.alibaba.druid.pool.DruidDataSource
# type: com.zaxxer.hikari.HikariDataSource
driver-class-name
:
com.mysql.jdbc.Driver
username
:
root
password
:
abcd1234A!
jdbc-url
:
jdbc:mysql://39.98.202.173:3306/demo_ds?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
url
:
jdbc:mysql://39.98.202.173:3306/demo_ds?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
filters
:
stat,wall,log4j
maxActive
:
20
initialSize
:
1
maxWait
:
60000
minIdle
:
1
timeBetweenEvictionRunsMillis
:
60000
minEvictableIdleTimeMillis
:
300000
validationQuery
:
select 'x'
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
poolPreparedStatements
:
true
maxOpenPreparedStatements
:
20
connection-properties
:
druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000
sharding
:
tables
:
t_order
:
actual-data-nodes
:
ds.t_order_$->{0..1}
table-strategy
:
inline
:
sharding-column
:
order_id
algorithm-expression
:
t_order_$->{order_id % 2}
key-generator
:
column
:
order_id
type
:
SNOWFLAKE
props
:
worker.id
:
123
t_order_item
:
actual-data-nodes
:
ds.t_order_item_$->{0..1}
table-strategy
:
inline
:
sharding-column
:
order_id
algorithm-expression
:
t_order_item_$->{order_id % 2}
key-generator
:
column
:
order_item_id
type
:
SNOWFLAKE
props
:
worker.id
:
123
#mybatis:
# mapper-locations: classpath:/mapper/**/*.xml #把xml文件放在com.XX.mapper.*中可能会出现找到的问题,这里把他放在resource下的mapper中
# #实体扫描,多个package用逗号或者分号分隔
# typeAliasesPackage: com.company.spring.boot.shardingsphere.seata.modules.entity #这里是实体类的位置
# configuration:
# map-underscore-to-camel-case: true
# cache-enabled: false
mybatis-plus
:
# datasource: dataSource
mapper-locations
:
classpath:/mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
type-aliases-package
:
com.loit.shardingsphere.seata.modules.entity
#typeEnumsPackage: com.baomidou.springboot.entity.enums
global-config
:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID", 4:"该类型为未设置主键类型", 5:"字符串全局唯一ID";
id-type
:
2
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy
:
1
#驼峰下划线转换
db-column-underline
:
true
#刷新mapper 调试神器
refresh-mapper
:
true
#数据库大写下划线转换
#capital-mode: true
#逻辑删除配置(下面3个配置)
logic-delete-value
:
0
logic-not-delete-value
:
1
# SQL 解析缓存,开启后多租户 @SqlParser 注解生效
sql-parser-cache
:
true
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
configuration-properties
:
dbType
:
mysql
#设置全局属性用于控制数据库的类型
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论