diff --git a/fabudingyuemoshi/.gitignore b/fabudingyuemoshi/.gitignore new file mode 100644 index 0000000..682d4ed --- /dev/null +++ b/fabudingyuemoshi/.gitignore @@ -0,0 +1,27 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +/.idea/ +/target/ diff --git a/fabudingyuemoshi/fanfu-web.iml b/fabudingyuemoshi/fanfu-web.iml new file mode 100644 index 0000000..4fb2f38 --- /dev/null +++ b/fabudingyuemoshi/fanfu-web.iml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fabudingyuemoshi/pom.xml b/fabudingyuemoshi/pom.xml new file mode 100644 index 0000000..7d184ca --- /dev/null +++ b/fabudingyuemoshi/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.9.RELEASE + + + + com.ayi + woniu-web + 0.0.1-SNAPSHOT + woniou-web + create by woniu + + jar + + + 1.8 + + + + + mysql + mysql-connector-java + 8.0.29 + + + com.baomidou + mybatis-plus-boot-starter + 3.5.2 + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + + + org.assertj + assertj-core + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/fabudingyuemoshi/src/main/java/com/woniu/WoNiuApplication.java b/fabudingyuemoshi/src/main/java/com/woniu/WoNiuApplication.java new file mode 100644 index 0000000..7c5f525 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/WoNiuApplication.java @@ -0,0 +1,24 @@ +package com.woniu; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableScheduling +@Slf4j +@EnableAsync +public class WoNiuApplication { + + public static void main(String[] args) { + SpringApplication.run(WoNiuApplication.class, args); + log.info("test_info"); + log.error("test_error"); + log.warn("test_warn"); + } + + + +} diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderLogListener.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderLogListener.java new file mode 100644 index 0000000..f8e902c --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderLogListener.java @@ -0,0 +1,17 @@ +package com.woniu.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class OrderLogListener { + + @EventListener + @Async("asyncExecutor") + public void orderLog(SaveOrderEvent event) { + log.info("[afterSaveOrder] log."); + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderMetricsListener.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderMetricsListener.java new file mode 100644 index 0000000..fea1cf0 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderMetricsListener.java @@ -0,0 +1,17 @@ +package com.woniu.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class OrderMetricsListener { + + @EventListener + @Async("asyncExecutor") + public void metrics(SaveOrderEvent event) { + log.info("[afterSaveOrder] metrics"); + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderNotifyListener.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderNotifyListener.java new file mode 100644 index 0000000..ede1846 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderNotifyListener.java @@ -0,0 +1,18 @@ +package com.woniu.service; + + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class OrderNotifyListener { + + @EventListener + @Async("asyncExecutor") + public void notify(SaveOrderEvent event) { + log.info("[afterSaveOrder] notify."); + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderReqVO.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderReqVO.java new file mode 100644 index 0000000..18ede90 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderReqVO.java @@ -0,0 +1,5 @@ +package com.woniu.service; + + +public class OrderReqVO { +} diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderResVO.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderResVO.java new file mode 100644 index 0000000..75fd756 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderResVO.java @@ -0,0 +1,4 @@ +package com.woniu.service; + +public class OrderResVO { +} diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderService.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderService.java new file mode 100644 index 0000000..a7d4a59 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderService.java @@ -0,0 +1,11 @@ +package com.woniu.service; + +/** + * @className: OrderService + * @author: woniu + * @date: 2023/3/25 + **/ +public interface OrderService { + + public OrderResVO saveOrder(OrderReqVO reqVO); +} diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/OrderServiceImpl.java b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderServiceImpl.java new file mode 100644 index 0000000..4291fd9 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/OrderServiceImpl.java @@ -0,0 +1,32 @@ +package com.woniu.service; + + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; + +/** + * SpringBoot项目实现发布订阅模式,真的很简单! + */ +@Service +@Slf4j +public class OrderServiceImpl implements OrderService { + @Autowired + private ApplicationEventPublisher applicationEventPublisher; + + /** + * 下单 + */ + @Override + public OrderResVO saveOrder(OrderReqVO reqVO) { + log.info("[placeOrder] start."); + OrderResVO resVO = new OrderResVO(); + //消息 + SaveOrderEventMessage eventMessage = new SaveOrderEventMessage(); + //发布事件 + applicationEventPublisher.publishEvent(new SaveOrderEvent(eventMessage)); + log.info("[placeOrder] end."); + return resVO; + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEvent.java b/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEvent.java new file mode 100644 index 0000000..d7a7244 --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEvent.java @@ -0,0 +1,11 @@ +package com.woniu.service; + + +import org.springframework.context.ApplicationEvent; + +public class SaveOrderEvent extends ApplicationEvent { + + public SaveOrderEvent(SaveOrderEventMessage source) { + super(source); + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEventMessage.java b/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEventMessage.java new file mode 100644 index 0000000..9afc82b --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/SaveOrderEventMessage.java @@ -0,0 +1,21 @@ +package com.woniu.service; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SaveOrderEventMessage implements Serializable { + /** + * 订单号 + */ + private String orderId; + /** + * 订单状态 + */ + private Integer orderStatus; + /** + * 下单用户ID + */ + private String userId; +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/java/com/woniu/service/TaskPoolConfig.java b/fabudingyuemoshi/src/main/java/com/woniu/service/TaskPoolConfig.java new file mode 100644 index 0000000..3c55dde --- /dev/null +++ b/fabudingyuemoshi/src/main/java/com/woniu/service/TaskPoolConfig.java @@ -0,0 +1,26 @@ +package com.woniu.service; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +public class TaskPoolConfig { + + @Bean(name = "asyncExecutor") + public Executor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + //随便写的一些配置 + executor.setCorePoolSize(10); + executor.setMaxPoolSize(20); + executor.setQueueCapacity(200); + executor.setKeepAliveSeconds(60); + executor.setThreadNamePrefix("asyncExecutor-"); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; + } +} \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/resources/application.properties b/fabudingyuemoshi/src/main/resources/application.properties new file mode 100644 index 0000000..50fb150 --- /dev/null +++ b/fabudingyuemoshi/src/main/resources/application.properties @@ -0,0 +1,14 @@ + +#mybatis.config-location=classpath:/mybatis-config.xml + +#context.initializer.classes +#context.initializer.classes=com.fanfu.config.MyApplicationContextInitializer + +server.port=8088 +mybatis-plus.mapper-locations=classpath*:/mapper/*.xml + + +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username=root +spring.datasource.password=123456 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/resources/application.yml b/fabudingyuemoshi/src/main/resources/application.yml new file mode 100644 index 0000000..6f09b0d --- /dev/null +++ b/fabudingyuemoshi/src/main/resources/application.yml @@ -0,0 +1,12 @@ +#apiVersion: extensions/v1beta1 +#kind: Ingress +#metadata: +# name: web +#spec: +# rules: +# - host: tomcat6.atguigu.com +# http: +# paths: +# - backend: +# serviceName: tomcat6 +# servicePort: 80 \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/resources/mapper/AuthorsMapper.xml b/fabudingyuemoshi/src/main/resources/mapper/AuthorsMapper.xml new file mode 100644 index 0000000..3b4c2fb --- /dev/null +++ b/fabudingyuemoshi/src/main/resources/mapper/AuthorsMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/fabudingyuemoshi/src/main/resources/sql.sql b/fabudingyuemoshi/src/main/resources/sql.sql new file mode 100644 index 0000000..4a98c46 --- /dev/null +++ b/fabudingyuemoshi/src/main/resources/sql.sql @@ -0,0 +1,9 @@ +CREATE TABLE `authors` ( + `id` int NOT NULL AUTO_INCREMENT, + `first_name` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, + `last_name` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, + `email` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, + `birthdate` date NOT NULL, + `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=10095 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci \ No newline at end of file diff --git a/fabudingyuemoshi/src/test/java/com/woniu/TestA.java b/fabudingyuemoshi/src/test/java/com/woniu/TestA.java new file mode 100644 index 0000000..5311f25 --- /dev/null +++ b/fabudingyuemoshi/src/test/java/com/woniu/TestA.java @@ -0,0 +1,26 @@ +package com.woniu; + +import com.woniu.service.OrderService; +import com.woniu.service.OrderReqVO; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@SpringBootTest +@RunWith(SpringRunner.class) +public class TestA { + + + @Autowired + private OrderService orderService; + + + @Test + public void placeOrder() { + OrderReqVO orderReqVO = new OrderReqVO(); + orderService.saveOrder(orderReqVO); + } +} diff --git a/fabudingyuemoshi/woniu-web.iml b/fabudingyuemoshi/woniu-web.iml new file mode 100644 index 0000000..431c31e --- /dev/null +++ b/fabudingyuemoshi/woniu-web.iml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file