docs(deployment): 更新部署文档并添加自动化部署脚本
- 更新了 DEPLOYMENT.md 文档,增加了更多部署细节和说明 - 添加了 Linux 和 Windows 平台的自动化部署脚本 - 更新了 README.md,增加了部署相关说明 - 调整了 .env 文件配置,以适应新的部署流程 - 移除了部分不必要的代码和配置
This commit is contained in:
36
backend-java/common/pom.xml
Normal file
36
backend-java/common/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.jiebanke</groupId>
|
||||
<artifactId>backend-java</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Validation -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.jiebanke.common.config;
|
||||
|
||||
import feign.Request;
|
||||
import feign.Retryer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
public class FeignConfig {
|
||||
|
||||
@Bean
|
||||
public Request.Options options() {
|
||||
return new Request.Options(5, TimeUnit.SECONDS, 30, TimeUnit.SECONDS, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Retryer retryer() {
|
||||
return new Retryer.Default(100, 1000, 3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.jiebanke.common.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
// 定义队列名称
|
||||
public static final String USER_QUEUE = "user.queue";
|
||||
public static final String TRAVEL_QUEUE = "travel.queue";
|
||||
public static final String ANIMAL_QUEUE = "animal.queue";
|
||||
public static final String ORDER_QUEUE = "order.queue";
|
||||
public static final String PROMOTION_QUEUE = "promotion.queue";
|
||||
|
||||
// 定义交换机名称
|
||||
public static final String EXCHANGE_NAME = "jiebanke.exchange";
|
||||
|
||||
// 定义路由键
|
||||
public static final String USER_ROUTING_KEY = "user.routing.key";
|
||||
public static final String TRAVEL_ROUTING_KEY = "travel.routing.key";
|
||||
public static final String ANIMAL_ROUTING_KEY = "animal.routing.key";
|
||||
public static final String ORDER_ROUTING_KEY = "order.routing.key";
|
||||
public static final String PROMOTION_ROUTING_KEY = "promotion.routing.key";
|
||||
|
||||
// 队列声明
|
||||
@Bean
|
||||
public Queue userQueue() {
|
||||
return new Queue(USER_QUEUE, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue travelQueue() {
|
||||
return new Queue(TRAVEL_QUEUE, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue animalQueue() {
|
||||
return new Queue(ANIMAL_QUEUE, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue orderQueue() {
|
||||
return new Queue(ORDER_QUEUE, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue promotionQueue() {
|
||||
return new Queue(PROMOTION_QUEUE, true);
|
||||
}
|
||||
|
||||
// 交换机声明
|
||||
@Bean
|
||||
public TopicExchange exchange() {
|
||||
return new TopicExchange(EXCHANGE_NAME);
|
||||
}
|
||||
|
||||
// 绑定关系
|
||||
@Bean
|
||||
public Binding userBinding() {
|
||||
return BindingBuilder.bind(userQueue()).to(exchange()).with(USER_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding travelBinding() {
|
||||
return BindingBuilder.bind(travelQueue()).to(exchange()).with(TRAVEL_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding animalBinding() {
|
||||
return BindingBuilder.bind(animalQueue()).to(exchange()).with(ANIMAL_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding orderBinding() {
|
||||
return BindingBuilder.bind(orderQueue()).to(exchange()).with(ORDER_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding promotionBinding() {
|
||||
return BindingBuilder.bind(promotionQueue()).to(exchange()).with(PROMOTION_ROUTING_KEY);
|
||||
}
|
||||
|
||||
// 消息转换器
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
|
||||
// RabbitTemplate配置
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
RabbitTemplate template = new RabbitTemplate(connectionFactory);
|
||||
template.setMessageConverter(messageConverter());
|
||||
return template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jiebanke.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new StringRedisSerializer());
|
||||
return template;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.jiebanke.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class BaseEntity {
|
||||
private Long id;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.jiebanke.common.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BusinessException extends RuntimeException {
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
public BusinessException(String message) {
|
||||
super(message);
|
||||
this.code = 400;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public BusinessException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jiebanke.common.exception;
|
||||
|
||||
import com.jiebanke.common.vo.ApiResponse;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(BusinessException.class)
|
||||
public ApiResponse<Void> handleBusinessException(BusinessException e) {
|
||||
return ApiResponse.error(e.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ApiResponse<Void> handleException(Exception e) {
|
||||
e.printStackTrace();
|
||||
return ApiResponse.error(500, "服务器内部错误");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.jiebanke.common.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApiResponse<T> {
|
||||
private boolean success;
|
||||
private int code;
|
||||
private String message;
|
||||
private T data;
|
||||
private long timestamp;
|
||||
|
||||
public static <T> ApiResponse<T> success(T data) {
|
||||
ApiResponse<T> response = new ApiResponse<>();
|
||||
response.success = true;
|
||||
response.code = 200;
|
||||
response.message = "操作成功";
|
||||
response.data = data;
|
||||
response.timestamp = System.currentTimeMillis();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> success(T data, String message) {
|
||||
ApiResponse<T> response = new ApiResponse<>();
|
||||
response.success = true;
|
||||
response.code = 200;
|
||||
response.message = message;
|
||||
response.data = data;
|
||||
response.timestamp = System.currentTimeMillis();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> error(int code, String message) {
|
||||
ApiResponse<T> response = new ApiResponse<>();
|
||||
response.success = false;
|
||||
response.code = code;
|
||||
response.message = message;
|
||||
response.timestamp = System.currentTimeMillis();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user