Compare commits
No commits in common. 'fa8e64a4ce62328994443ac7fd3b6325f9e6ed8d' and '08b87590cd9d03c805da746fd75c77205ac55e4a' have entirely different histories.
fa8e64a4ce
...
08b87590cd
@ -1,75 +0,0 @@
|
|||||||
package org.example.hystrix;
|
|
||||||
|
|
||||||
import com.netflix.hystrix.HystrixCommand;
|
|
||||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
|
||||||
import com.netflix.hystrix.HystrixCommandKey;
|
|
||||||
import com.netflix.hystrix.HystrixRequestCache;
|
|
||||||
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategyDefault;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.example.service.NacosClientService4HystrixDemo;
|
|
||||||
import org.springframework.cloud.client.ServiceInstance;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h1>带有缓存功能的 Hystrix</h1>
|
|
||||||
* */
|
|
||||||
@Slf4j
|
|
||||||
public class CacheHystrixCommand extends HystrixCommand<List<ServiceInstance>> {
|
|
||||||
|
|
||||||
/** 需要保护的服务 */
|
|
||||||
private final NacosClientService4HystrixDemo nacosClientService;
|
|
||||||
|
|
||||||
/** 方法需要传递的参数 */
|
|
||||||
private final String serviceId;
|
|
||||||
|
|
||||||
private static final HystrixCommandKey CACHED_KEY =
|
|
||||||
HystrixCommandKey.Factory.asKey("CacheHystrixCommand");
|
|
||||||
|
|
||||||
public CacheHystrixCommand(NacosClientService4HystrixDemo nacosClientService, String serviceId) {
|
|
||||||
|
|
||||||
super(
|
|
||||||
HystrixCommand.Setter
|
|
||||||
.withGroupKey(HystrixCommandGroupKey
|
|
||||||
.Factory.asKey("CacheHystrixCommandGroup"))
|
|
||||||
.andCommandKey(CACHED_KEY)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.nacosClientService = nacosClientService;
|
|
||||||
this.serviceId = serviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<ServiceInstance> run() throws Exception {
|
|
||||||
|
|
||||||
log.info("CacheHystrixCommand In Hystrix Command to get service instance:" +
|
|
||||||
" [{}], [{}]", this.serviceId, Thread.currentThread().getName());
|
|
||||||
return this.nacosClientService.getNacosClientInfo(this.serviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getCacheKey() {
|
|
||||||
// fixme 可以进行自定义, 只要保证唯一的请求返回唯一的值即可
|
|
||||||
return serviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<ServiceInstance> getFallback() {
|
|
||||||
// todo 这里可以自己添加一些 warning 日志来进行表示
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h2>根据缓存 key 清理在一次 Hystrix 请求上下文中的缓存</h2>
|
|
||||||
* */
|
|
||||||
public static void flushRequestCache(String serviceId) {
|
|
||||||
|
|
||||||
HystrixRequestCache.getInstance(
|
|
||||||
CACHED_KEY,
|
|
||||||
HystrixConcurrencyStrategyDefault.getInstance()
|
|
||||||
).clear(serviceId);
|
|
||||||
log.info("flush request cache in hystrix command: [{}], [{}]",
|
|
||||||
serviceId, Thread.currentThread().getName());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
target/
|
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
|
||||||
!**/src/main/**/target/
|
|
||||||
!**/src/test/**/target/
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea/modules.xml
|
|
||||||
.idea/jarRepositories.xml
|
|
||||||
.idea/compiler.xml
|
|
||||||
.idea/libraries/
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
|
|
||||||
### Eclipse ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
build/
|
|
||||||
!**/src/main/**/build/
|
|
||||||
!**/src/test/**/build/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
### Mac OS ###
|
|
||||||
.DS_Store
|
|
@ -1,22 +0,0 @@
|
|||||||
package org.example;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <h1>订单微服务启动入口</h1>
|
|
||||||
* */
|
|
||||||
@EnableJpaAuditing
|
|
||||||
@SpringBootApplication
|
|
||||||
@EnableCircuitBreaker
|
|
||||||
@EnableFeignClients
|
|
||||||
@EnableDiscoveryClient
|
|
||||||
public class OrderApplication {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(OrderApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
server:
|
|
||||||
port: 8002
|
|
||||||
servlet:
|
|
||||||
context-path: /dev-protocol-springcloud-project-order-service
|
|
||||||
|
|
||||||
spring:
|
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
application:
|
|
||||||
name: dev-protocol-springcloud-project-order-service
|
|
||||||
cloud:
|
|
||||||
stream:
|
|
||||||
kafka:
|
|
||||||
binder:
|
|
||||||
brokers: 127.0.0.1:9092
|
|
||||||
auto-create-topics: true
|
|
||||||
bindings:
|
|
||||||
logisticsOutput:
|
|
||||||
destination: dev-protocol-topic # kafka topic
|
|
||||||
content-type: text/plain
|
|
||||||
alibaba:
|
|
||||||
seata:
|
|
||||||
tx-service-group: dev-protocol # seata 全局事务分组
|
|
||||||
nacos:
|
|
||||||
discovery:
|
|
||||||
enabled: true # 如果不想使用 Nacos 进行服务注册和发现, 设置为 false 即可
|
|
||||||
server-addr: 127.0.0.1:8848
|
|
||||||
# server-addr: 127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850 # Nacos 服务器地址
|
|
||||||
namespace: 1ccc74ae-9398-4dbe-b9d7-4f9addf9f40c
|
|
||||||
metadata:
|
|
||||||
management:
|
|
||||||
context-path: ${server.servlet.context-path}/actuator
|
|
||||||
# 开启 ribbon 重试机制, 即获取服务失败是否从另外一个节点重试
|
|
||||||
loadbalancer:
|
|
||||||
retry:
|
|
||||||
enabled: true
|
|
||||||
kafka:
|
|
||||||
bootstrap-servers: 127.0.0.1:9092
|
|
||||||
producer:
|
|
||||||
retries: 3
|
|
||||||
consumer:
|
|
||||||
auto-offset-reset: latest
|
|
||||||
sleuth:
|
|
||||||
sampler:
|
|
||||||
probability: 1.0 # 采样比例, 1.0 表示 100%, 默认是 0.1
|
|
||||||
zipkin:
|
|
||||||
sender:
|
|
||||||
type: kafka # 默认是 http
|
|
||||||
base-url: http://localhost:9411/
|
|
||||||
jpa:
|
|
||||||
show-sql: true
|
|
||||||
hibernate:
|
|
||||||
ddl-auto: none
|
|
||||||
properties:
|
|
||||||
hibernate.show_sql: true
|
|
||||||
hibernate.format_sql: true
|
|
||||||
open-in-view: false
|
|
||||||
datasource:
|
|
||||||
# 数据源
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/dev_protocol_springcloud_project?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
|
||||||
username: root
|
|
||||||
password: root
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
# 连接池
|
|
||||||
hikari:
|
|
||||||
maximum-pool-size: 8
|
|
||||||
minimum-idle: 4
|
|
||||||
idle-timeout: 30000
|
|
||||||
connection-timeout: 30000
|
|
||||||
max-lifetime: 45000
|
|
||||||
auto-commit: true
|
|
||||||
pool-name: devProtocolSpringcloudHikariCP
|
|
||||||
|
|
||||||
# feign 相关的配置
|
|
||||||
feign:
|
|
||||||
hystrix:
|
|
||||||
enabled: true # Hystrix 默认是关闭的
|
|
||||||
client:
|
|
||||||
config:
|
|
||||||
default: # 全局的
|
|
||||||
connectTimeout: 2000 # 默认的连接超时时间是 10s
|
|
||||||
readTimeout: 5000
|
|
||||||
|
|
||||||
# 暴露端点
|
|
||||||
management:
|
|
||||||
endpoints:
|
|
||||||
web:
|
|
||||||
exposure:
|
|
||||||
include: '*'
|
|
||||||
endpoint:
|
|
||||||
health:
|
|
||||||
show-details: always
|
|
@ -1,65 +0,0 @@
|
|||||||
## transaction log store, only used in seata-server
|
|
||||||
store {
|
|
||||||
## store mode: file、db、redis
|
|
||||||
mode = "db"
|
|
||||||
|
|
||||||
## file store property
|
|
||||||
file {
|
|
||||||
## store location dir
|
|
||||||
dir = "sessionStore"
|
|
||||||
# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
|
|
||||||
maxBranchSessionSize = 16384
|
|
||||||
# globe session size , if exceeded throws exceptions
|
|
||||||
maxGlobalSessionSize = 512
|
|
||||||
# file buffer size , if exceeded allocate new buffer
|
|
||||||
fileWriteBufferCacheSize = 16384
|
|
||||||
# when recover batch read size
|
|
||||||
sessionReloadReadSize = 100
|
|
||||||
# async, sync
|
|
||||||
flushDiskMode = async
|
|
||||||
}
|
|
||||||
|
|
||||||
## database store property
|
|
||||||
db {
|
|
||||||
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
|
|
||||||
datasource = "druid"
|
|
||||||
## mysql/oracle/postgresql/h2/oceanbase etc.
|
|
||||||
dbType = "mysql"
|
|
||||||
driverClassName = "com.mysql.jdbc.Driver"
|
|
||||||
url = "jdbc:mysql://127.0.0.1:3306/seata?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false"
|
|
||||||
user = "root"
|
|
||||||
password = "root"
|
|
||||||
minConn = 5
|
|
||||||
maxConn = 100
|
|
||||||
globalTable = "global_table"
|
|
||||||
branchTable = "branch_table"
|
|
||||||
lockTable = "lock_table"
|
|
||||||
queryLimit = 100
|
|
||||||
maxWait = 5000
|
|
||||||
}
|
|
||||||
|
|
||||||
## redis store property
|
|
||||||
redis {
|
|
||||||
host = "127.0.0.1"
|
|
||||||
port = "6379"
|
|
||||||
password = ""
|
|
||||||
database = "0"
|
|
||||||
minConn = 1
|
|
||||||
maxConn = 10
|
|
||||||
maxTotal = 100
|
|
||||||
queryLimit = 100
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
service {
|
|
||||||
vgroupMapping.imooc-ecommerce = "default"
|
|
||||||
default.grouplist = "127.0.0.1:8091"
|
|
||||||
}
|
|
||||||
client {
|
|
||||||
async.commit.buffer.limit = 10000
|
|
||||||
lock {
|
|
||||||
retry.internal = 10
|
|
||||||
retry.times = 30
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
### 创建订单
|
|
||||||
POST http://127.0.0.1:9001/dev-protocol-springcloud-gateway/dev-protocol-springcloud-project-order-service/order/create-order
|
|
||||||
Content-Type: application/json
|
|
||||||
Accept: application/json
|
|
||||||
e-commerce-user: eyJhbGciOiJSUzI1NiJ9.eyJlLWNvbW1lcmNlLXVzZXIiOiJ7XCJpZFwiOjEwLFwidXNlcm5hbWVcIjpcIlFpbnlpQGltb29jLmNvbVwifSIsImp0aSI6ImU5OWYzYjdjLTA2YjYtNGQ1Zi1hODY3LWJlMzhjYjlkNDBmZCIsImV4cCI6MTYyODE3OTIwMH0.U9jXZoa9fdQMJQmujN4mkkbtN62cGVy26qhOq_x4QhU8qCqw_NLr2StdAOAAC_FGOF85DHpvDBHCzn9EDCeuq1tBqODjUaLLnWFtTj3oYYSpPZQTG-ZA9OLz8lG8EbcH3URxcaTMElyI8WKoIVccWIHivXTDgNDZOCs6Bir9bBvJJ1Vobgqnb1uV5S7wdHgh89e96-iBy9xCsoQovTcyEOqi8n5cH8cTjMb2XXjT83OhZC1oxhKhkNoTiDOq9VSaYOISQ_tv-XFTICEed4ondW9zfcrbAWdaHb1l8UT5o7nuQOwWkaMckDft9liuTvl6KAe8MjPN9exUqAI5tOC_fA
|
|
||||||
|
|
||||||
{
|
|
||||||
"userAddress": 1,
|
|
||||||
"orderItems": [
|
|
||||||
{
|
|
||||||
"goodsId": 1,
|
|
||||||
"count": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
### 查询订单
|
|
||||||
GET http://127.0.0.1:9001/dev-protocol-springcloud-gateway/dev-protocol-springcloud-project-order-service/order/order-detail?page=2
|
|
||||||
Accept: application/json
|
|
||||||
e-commerce-user: eyJhbGciOiJSUzI1NiJ9.eyJlLWNvbW1lcmNlLXVzZXIiOiJ7XCJpZFwiOjEwLFwidXNlcm5hbWVcIjpcIlFpbnlpQGltb29jLmNvbVwifSIsImp0aSI6ImU5OWYzYjdjLTA2YjYtNGQ1Zi1hODY3LWJlMzhjYjlkNDBmZCIsImV4cCI6MTYyODE3OTIwMH0.U9jXZoa9fdQMJQmujN4mkkbtN62cGVy26qhOq_x4QhU8qCqw_NLr2StdAOAAC_FGOF85DHpvDBHCzn9EDCeuq1tBqODjUaLLnWFtTj3oYYSpPZQTG-ZA9OLz8lG8EbcH3URxcaTMElyI8WKoIVccWIHivXTDgNDZOCs6Bir9bBvJJ1Vobgqnb1uV5S7wdHgh89e96-iBy9xCsoQovTcyEOqi8n5cH8cTjMb2XXjT83OhZC1oxhKhkNoTiDOq9VSaYOISQ_tv-XFTICEed4ondW9zfcrbAWdaHb1l8UT5o7nuQOwWkaMckDft9liuTvl6KAe8MjPN9exUqAI5tOC_fA
|
|
@ -1,17 +0,0 @@
|
|||||||
registry {
|
|
||||||
# file、nacos、eureka、redis、zk、consul
|
|
||||||
type = "file"
|
|
||||||
|
|
||||||
file {
|
|
||||||
name = "file.conf"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
config {
|
|
||||||
type = "file"
|
|
||||||
|
|
||||||
file {
|
|
||||||
name = "file.conf"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
-- 创建 t_ecommerce_order 数据表
|
|
||||||
CREATE TABLE IF NOT EXISTS `dev_protocol_springcloud_project`.`t_dev_protocol_cloud_order` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
|
|
||||||
`user_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '用户 id',
|
|
||||||
`address_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '用户地址记录 id',
|
|
||||||
`order_detail` text NOT NULL COMMENT '订单详情(json 存储, goodsId, count)',
|
|
||||||
`create_time` datetime NOT NULL DEFAULT '0000-01-01 00:00:00' COMMENT '创建时间',
|
|
||||||
`update_time` datetime NOT NULL DEFAULT '0000-01-01 00:00:00' COMMENT '更新时间',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='用户订单表';
|
|
@ -1,13 +0,0 @@
|
|||||||
CREATE TABLE `undo_log` (
|
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
|
||||||
`branch_id` bigint(20) NOT NULL,
|
|
||||||
`xid` varchar(100) NOT NULL,
|
|
||||||
`context` varchar(128) NOT NULL,
|
|
||||||
`rollback_info` longblob NOT NULL,
|
|
||||||
`log_status` int(11) NOT NULL,
|
|
||||||
`log_created` datetime NOT NULL,
|
|
||||||
`log_modified` datetime NOT NULL,
|
|
||||||
`ext` varchar(100) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
|
@ -1,36 +0,0 @@
|
|||||||
## 1. SpringBoot源码/造轮子/面试
|
|
||||||
|
|
||||||
### 1.1 Spring源码概述
|
|
||||||
|
|
||||||
|
|
||||||
### 1.2 Spring Boot架构设计解析
|
|
||||||
|
|
||||||
|
|
||||||
### 1.3 Spring Boot核心源码解析
|
|
||||||
|
|
||||||
|
|
||||||
### 1.4 Spring Boot应用技巧解析
|
|
||||||
|
|
||||||
|
|
||||||
### 1.5 Spring Boot二次改造
|
|
||||||
|
|
||||||
|
|
||||||
### 1.6 Spring Boot造轮子
|
|
||||||
|
|
||||||
|
|
||||||
### 1.7 Spring Boot面试题深度解析
|
|
||||||
|
|
||||||
|
|
||||||
## Spring源码/造轮子/面试
|
|
||||||
|
|
||||||
|
|
||||||
## SpringCould源码/造轮子/面试
|
|
||||||
|
|
||||||
|
|
||||||
## Spring Data源码/造轮子/面试
|
|
||||||
|
|
||||||
|
|
||||||
## Mybatis&Tomcat源码深度解析
|
|
||||||
|
|
||||||
|
|
||||||
## RocketMQ源码/造轮子/面试
|
|
@ -1,19 +0,0 @@
|
|||||||
## 大厂架构师级别的项目管理,沟通和复盘秘籍
|
|
||||||
|
|
||||||
|
|
||||||
### 1. 项目管理
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 2. 沟通技能
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 3. 复盘总结
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### 4. 面试指导
|
|
Loading…
Reference in New Issue