├── 初探CQRS新.pptx └── cqrs-axon-demo ├── cqrs-demo ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── lyqf │ │ │ ├── event │ │ │ ├── package-info.java │ │ │ └── CustomerCreatedEvent.java │ │ │ ├── hanndler │ │ │ ├── package-info.java │ │ │ ├── event │ │ │ │ ├── package-info.java │ │ │ │ └── CustomerEventHanndler.java │ │ │ └── CustomerCommandHanndler.java │ │ │ ├── replay │ │ │ ├── package-info.java │ │ │ └── CustomerReplay.java │ │ │ ├── infrastructure │ │ │ ├── package-info.java │ │ │ └── CQRSContext.java │ │ │ ├── reposity │ │ │ └── CustomerDtoReposity.java │ │ │ ├── SpringApplicationRun.java │ │ │ ├── command │ │ │ └── CreateCustomerCommand.java │ │ │ ├── dto │ │ │ └── CustomerDto.java │ │ │ ├── web │ │ │ └── CustomerController.java │ │ │ └── domain │ │ │ └── Customer.java │ │ ├── resources │ │ ├── application.properties │ │ └── META-INF │ │ │ └── spring │ │ │ ├── customer-context.xml │ │ │ └── cqrs-infrastructure-context.xml │ │ └── webapp │ │ └── WEB-INF │ │ └── web.xml └── pom.xml └── .gitignore /初探CQRS新.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waterlang/DDD-CQRS/HEAD/初探CQRS新.pptx -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author water 6 | * 7 | */ 8 | package com.lyqf.event; -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/hanndler/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author water 6 | * 7 | */ 8 | package com.lyqf.hanndler; -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/replay/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author water 6 | * 7 | */ 8 | package com.lyqf.replay; -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/hanndler/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author water 6 | * 7 | */ 8 | package com.lyqf.hanndler.event; -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/infrastructure/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author water 6 | * 7 | */ 8 | package com.lyqf.infrastructure; -------------------------------------------------------------------------------- /cqrs-axon-demo/.gitignore: -------------------------------------------------------------------------------- 1 | */target/ 2 | **/target/ 3 | */.classpath 4 | **/.classpath 5 | */**/.gitignore 6 | */.project 7 | **/*.iml 8 | **/.idea 9 | .project 10 | .settings/ 11 | **/bin/ 12 | 13 | node_modules 14 | build 15 | npm-debug.log 16 | *.log 17 | *.iml -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/reposity/CustomerDtoReposity.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.reposity; 2 | 3 | import org.springframework.data.mongodb.repository.MongoRepository; 4 | 5 | import com.lyqf.dto.CustomerDto; 6 | 7 | public interface CustomerDtoReposity extends MongoRepository{ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/SpringApplicationRun.java: -------------------------------------------------------------------------------- 1 | package com.lyqf; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringApplicationRun { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringApplicationRun.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/command/CreateCustomerCommand.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.command; 2 | 3 | import org.axonframework.eventsourcing.annotation.AggregateIdentifier; 4 | 5 | public class CreateCustomerCommand { 6 | 7 | @AggregateIdentifier 8 | private String id; 9 | 10 | private String name; 11 | 12 | private String pwd; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public String getPwd() { 31 | return pwd; 32 | } 33 | 34 | public void setPwd(String pwd) { 35 | this.pwd = pwd; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/replay/CustomerReplay.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.replay; 2 | 3 | 4 | import org.axonframework.eventhandling.replay.ReplayingCluster; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | 10 | 11 | @Controller 12 | public class CustomerReplay { 13 | 14 | @Autowired 15 | @Qualifier(value ="customerReplayingCluster") 16 | private ReplayingCluster customerReplayingCluster; 17 | 18 | @RequestMapping("/test/replay") 19 | public void test(){ 20 | System.out.println("------"); 21 | customerReplayingCluster.startReplay(); 22 | } 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/hanndler/event/CustomerEventHanndler.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.hanndler.event; 2 | 3 | import org.axonframework.eventhandling.annotation.EventHandler; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import com.lyqf.dto.CustomerDto; 8 | import com.lyqf.event.CustomerCreatedEvent; 9 | import com.lyqf.reposity.CustomerDtoReposity; 10 | 11 | @Component 12 | public class CustomerEventHanndler { 13 | 14 | @Autowired 15 | private CustomerDtoReposity customerDtoReposity; 16 | 17 | @EventHandler 18 | public void on(CustomerCreatedEvent event){ 19 | CustomerDto dto = new CustomerDto(); 20 | dto.setName(event.getName()); 21 | dto.setPwd(event.getPwd()); 22 | customerDtoReposity.save(dto); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/dto/CustomerDto.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.annotation.Id; 6 | 7 | 8 | public class CustomerDto implements Serializable{ 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 2453272753830310582L; 14 | 15 | @Id 16 | private String id; 17 | 18 | private String name; 19 | 20 | private String pwd; 21 | 22 | public String getId() { 23 | return id; 24 | } 25 | 26 | public void setId(String id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getPwd() { 39 | return pwd; 40 | } 41 | 42 | public void setPwd(String pwd) { 43 | this.pwd = pwd; 44 | } 45 | 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/infrastructure/CQRSContext.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.infrastructure; 2 | 3 | import org.axonframework.commandhandling.CommandBus; 4 | import org.axonframework.commandhandling.gateway.CommandGateway; 5 | import org.axonframework.commandhandling.gateway.DefaultCommandGateway; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.ImportResource; 10 | 11 | @Configuration 12 | @ImportResource({"classpath:META-INF/spring/cqrs-infrastructure-context.xml" 13 | ,"classpath:META-INF/spring/customer-context.xml" 14 | }) 15 | public class CQRSContext { 16 | @Autowired 17 | private CommandBus commandBus; 18 | 19 | @Bean 20 | public CommandGateway commandGateWay() { 21 | return new DefaultCommandGateway(commandBus); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/event/CustomerCreatedEvent.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.event; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.axonframework.eventsourcing.annotation.AggregateIdentifier; 6 | 7 | public class CustomerCreatedEvent implements Serializable{ 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 3682075358286689379L; 13 | 14 | @AggregateIdentifier 15 | private String id; 16 | 17 | private String name; 18 | 19 | private String pwd; 20 | 21 | 22 | public String getId() { 23 | return id; 24 | } 25 | 26 | public void setId(String id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getPwd() { 39 | return pwd; 40 | } 41 | 42 | public void setPwd(String pwd) { 43 | this.pwd = pwd; 44 | } 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/web/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.web; 2 | 3 | import org.axonframework.commandhandling.gateway.CommandGateway; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | import com.lyqf.command.CreateCustomerCommand; 10 | 11 | @Controller 12 | public class CustomerController { 13 | 14 | @Autowired 15 | private CommandGateway commandGateway; 16 | 17 | @RequestMapping("/test/save") 18 | @ResponseBody 19 | public String save(){ 20 | CreateCustomerCommand createCommand = new CreateCustomerCommand(); 21 | createCommand.setId("2222333"); 22 | createCommand.setName("hehe"); 23 | createCommand.setPwd("4234234"); 24 | commandGateway.send(createCommand); 25 | return "success"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/hanndler/CustomerCommandHanndler.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.hanndler; 2 | 3 | import org.axonframework.commandhandling.annotation.CommandHandler; 4 | import org.axonframework.repository.Repository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.stereotype.Component; 8 | 9 | import com.lyqf.command.CreateCustomerCommand; 10 | import com.lyqf.domain.Customer; 11 | 12 | @Component 13 | public class CustomerCommandHanndler { 14 | 15 | @Autowired 16 | @Qualifier("customerRepository") 17 | private Repository customerRepository; 18 | 19 | @CommandHandler 20 | public void handler(CreateCustomerCommand createCommand){ 21 | Customer c = null; 22 | try{ 23 | c = customerRepository.load(createCommand.getId()); 24 | 25 | }catch(Exception e){ 26 | e.printStackTrace(); 27 | } 28 | try{ 29 | if(c != null){ 30 | 31 | }else{ 32 | Customer webC = new Customer(createCommand); 33 | customerRepository.add(webC); 34 | } 35 | }catch(Exception e){ 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8899 2 | 3 | #web mvc 4 | spring.resources.cache-period=604800 5 | #log 6 | logging.file=app.log 7 | logging.level.*.*=INFO 8 | logging.level.com.s400=DEBUG 9 | #logging.level.org.springframework.security=DEBUG 10 | #logging.level.org.springframework.web=DEBUG 11 | 12 | # THYMELEAF (ThymeleafAutoConfiguration) 13 | #spring.thymeleaf.check-template-location=true 14 | #spring.thymeleaf.prefix=classpath:/templates/ 15 | #spring.thymeleaf.suffix=.html 16 | #spring.thymeleaf.mode=HTML5 17 | spring.thymeleaf.encoding=UTF-8 18 | #spring.thymeleaf.content-type=text/html 19 | spring.thymeleaf.cache=false 20 | 21 | #mongodb 22 | spring.data.mongodb.host=localhost 23 | spring.data.mongodb.port=27017 24 | spring.data.mongodb.database=cqrs_demo 25 | #spring.data.mongodb.username=lynxiaojing 26 | #spring.data.mongodb.password=54347789 27 | 28 | server.tomcat.uri-encoding=UTF-8 29 | 30 | # A thread pool executor dispatcher, named threadPoolExecutor 31 | reactor.dispatchers.threadPoolExecutor.type = threadPoolExecutor 32 | reactor.dispatchers.threadPoolExecutor.size = 20 33 | # Backlog is how many Task objects to warm up internally 34 | reactor.dispatchers.threadPoolExecutor.backlog = 2048 35 | 36 | #custom 37 | #max upload file size(KB,MB) 38 | #custom.upload.size=100MB 39 | 40 | 41 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/resources/META-INF/spring/customer-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 14 | 15 | 16 | 20 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/java/com/lyqf/domain/Customer.java: -------------------------------------------------------------------------------- 1 | package com.lyqf.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | import org.axonframework.eventhandling.annotation.EventHandler; 12 | import org.axonframework.eventsourcing.annotation.AbstractAnnotatedAggregateRoot; 13 | import org.axonframework.eventsourcing.annotation.AggregateIdentifier; 14 | import org.axonframework.eventsourcing.annotation.EventSourcingHandler; 15 | 16 | import com.lyqf.command.CreateCustomerCommand; 17 | import com.lyqf.event.CustomerCreatedEvent; 18 | 19 | 20 | 21 | public class Customer extends AbstractAnnotatedAggregateRoot{ 22 | 23 | /** 24 | * 25 | */ 26 | private static final long serialVersionUID = 1L; 27 | 28 | @AggregateIdentifier 29 | private String id; 30 | 31 | private String name; 32 | 33 | private String pwd; 34 | 35 | 36 | 37 | 38 | public Customer(){ 39 | 40 | } 41 | 42 | 43 | public Customer(CreateCustomerCommand command){ 44 | CustomerCreatedEvent event = new CustomerCreatedEvent(); 45 | event.setId(command.getId()); 46 | event.setName(command.getName()); 47 | event.setPwd(command.getPwd()); 48 | apply(event); 49 | } 50 | 51 | 52 | @EventSourcingHandler 53 | public void hand(CustomerCreatedEvent e){ 54 | this.id = e.getId(); 55 | this.name = e.getName(); 56 | this.pwd = e.getPwd(); 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | public String getId() { 80 | return id; 81 | } 82 | 83 | public void setId(String id) { 84 | this.id = id; 85 | } 86 | 87 | public String getName() { 88 | return name; 89 | } 90 | 91 | public void setName(String name) { 92 | this.name = name; 93 | } 94 | 95 | public String getPwd() { 96 | return pwd; 97 | } 98 | 99 | public void setPwd(String pwd) { 100 | this.pwd = pwd; 101 | } 102 | 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 24 | 28 | 29 | 30 | 31 | 34 | 35 | Multipart MIME handling filter for Cocoon 36 | Cocoon multipart filter 37 | CocoonMultipartFilter 38 | org.apache.cocoon.servlet.multipart.MultipartFilter 39 | 40 | 41 | 44 | 45 | Log debug information about each request 46 | Cocoon debug filter 47 | CocoonDebugFilter 48 | org.apache.cocoon.servlet.DebugFilter 49 | 50 | 51 | 52 | 53 | 56 | 57 | CocoonMultipartFilter 58 | Cocoon 59 | 60 | 61 | CocoonMultipartFilter 62 | DispatcherServlet 63 | 64 | 65 | 72 | 73 | 74 | 75 | 79 | 80 | org.springframework.web.context.ContextLoaderListener 81 | 82 | 83 | 88 | 89 | org.springframework.web.context.request.RequestContextListener 90 | 91 | 92 | 93 | 94 | 97 | 98 | Cocoon blocks dispatcher 99 | DispatcherServlet 100 | DispatcherServlet 101 | org.apache.cocoon.servletservice.DispatcherServlet 102 | 1 103 | 104 | 105 | 106 | 107 | 113 | 114 | DispatcherServlet 115 | /* 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/src/main/resources/META-INF/spring/cqrs-infrastructure-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 54 | 61 | 67 | 75 | 76 | 77 | 78 | 79 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 114 | 115 | -------------------------------------------------------------------------------- /cqrs-axon-demo/cqrs-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 4.0.0 24 | war 25 | 26 | cqrs-demo 27 | com.oauth.lyqf 28 | cqrs-demo 29 | 0.0.1-SNAPSHOT 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-parent 35 | 1.2.3.RELEASE 36 | 37 | 38 | 39 | 40 | 41 | org.projectlombok 42 | lombok 43 | ${lombok.version} 44 | 45 | 46 | 47 | org.apache.commons 48 | commons-lang3 49 | 3.3.2 50 | 51 | 52 | commons-codec 53 | commons-codec 54 | 1.10 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-web 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-starter-data-mongodb 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-websocket 68 | 69 | 70 | org.springframework 71 | spring-messaging 72 | 73 | 74 | org.projectreactor 75 | reactor-core 76 | ${reactorVersion} 77 | 78 | 79 | 80 | org.axonframework 81 | axon-core 82 | 2.4 83 | 84 | 85 | org.axonframework 86 | axon-mongo 87 | 2.4 88 | 89 | 90 | 91 | 92 | 93 | spring-releases 94 | http://repo.spring.io/libs-release 95 | 96 | 97 | spring-milestone 98 | http://repo.spring.io/libs-milestone 99 | 100 | 101 | spring-snapshot 102 | http://repo.spring.io/libs-snapshot 103 | 104 | 105 | 106 | 107 | 108 | 109 | spring-releases 110 | http://repo.spring.io/libs-release 111 | 112 | 113 | spring-snapshots 114 | http://repo.spring.io/snapshot 115 | 116 | 117 | spring-milestones 118 | http://repo.spring.io/milestone 119 | 120 | 121 | 122 | 123 | 124 | org.springframework.boot 125 | spring-boot-maven-plugin 126 | 127 | 128 | 129 | 130 | 131 | --------------------------------------------------------------------------------