Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-leave/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>

<artifactId>example-interface</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<artifactId>springboot-example</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>

<name>springboot-starter-data-authorization</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>

<name>springboot-starter-flow</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>

<artifactId>springboot-starter-security</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.42</version>
<version>3.4.43</version>
</parent>
<artifactId>springboot-starter</artifactId>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.codingapi.springboot.framework.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* handler订阅的Spring触发器,在异步的情况下可配置多线程。
*/
@Slf4j
public class SpringDefaultEventHandler extends SpringEventHandler{

/**
* 异步多线程的KEY
* 可通过 System.setProperty(THREAD_KEY,"20") 调整线程数
*/
public final static String THREAD_KEY = "Handler.ThreadPools";

private final ExecutorService executorService = Executors
.newFixedThreadPool(Integer.parseInt(System.getProperty(THREAD_KEY, "10")));

public SpringDefaultEventHandler(List<IHandler> handlers) {
ApplicationHandlerUtils.getInstance().addHandlers(handlers);
log.info("SpringDefaultEventHandler Success Initial.");
}

@EventListener
public synchronized void dispatch(DomainEvent domainEvent) {
String traceId = domainEvent.getTraceId();

if (domainEvent.isSync()) {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
} else {
executorService.execute(() -> {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
});
}
}

}
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
package com.codingapi.springboot.framework.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* handler订阅的Spring触发器,在异步的情况下可配置多线程。
*/
@Slf4j
public class SpringEventHandler implements ApplicationListener<DomainEvent> {

/**
* 异步多线程的KEY
* 可通过 System.setProperty(THREAD_KEY,"20") 调整线程数
*/
public final static String THREAD_KEY = "Handler.ThreadPools";

private final ExecutorService executorService = Executors.newFixedThreadPool(Integer.parseInt(System.getProperty(THREAD_KEY, "10")));

public SpringEventHandler(List<IHandler> handlers) {
ApplicationHandlerUtils.getInstance().addHandlers(handlers);
}

@Override
public synchronized void onApplicationEvent(DomainEvent domainEvent) {
String traceId = domainEvent.getTraceId();

if (domainEvent.isSync()) {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
} else {
executorService.execute(() -> {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
});
}
}

public abstract class SpringEventHandler {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.codingapi.springboot.framework.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -10,8 +12,17 @@
public class SpringHandlerConfiguration {

@Bean
public SpringEventHandler springEventHandler(@Autowired(required = false) List<IHandler> handlers) {
return new SpringEventHandler(handlers);
@ConditionalOnProperty(value = "codingapi.framework.event.transaction.enable",havingValue = "true")
public SpringEventHandler springTransactionEventHandler(@Autowired(required = false) List<IHandler> handlers) {
return new SpringTransactionEventHandler(handlers);
}

@Bean
@ConditionalOnMissingBean
public SpringEventHandler springDefaultEventHandler(@Autowired(required = false) List<IHandler> handlers) {
return new SpringDefaultEventHandler(handlers);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.codingapi.springboot.framework.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* handler订阅的Spring触发器,在异步的情况下可配置多线程。
*/
@Slf4j
public class SpringTransactionEventHandler extends SpringEventHandler{

/**
* 异步多线程的KEY
* 可通过 System.setProperty(THREAD_KEY,"20") 调整线程数
*/
public final static String THREAD_KEY = "Handler.ThreadPools";

private final ExecutorService executorService = Executors
.newFixedThreadPool(Integer.parseInt(System.getProperty(THREAD_KEY, "10")));

public SpringTransactionEventHandler(List<IHandler> handlers) {
ApplicationHandlerUtils.getInstance().addHandlers(handlers);
log.info("SpringTransactionEventHandler Success Initial.");
}

@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
public synchronized void dispatch(DomainEvent domainEvent) {
String traceId = domainEvent.getTraceId();

if (domainEvent.isSync()) {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
} else {
executorService.execute(() -> {
try {
EventTraceContext.getInstance().createEventKey(traceId);
ApplicationHandlerUtils.getInstance().handler(domainEvent.getEvent());
} finally {
EventTraceContext.getInstance().checkEventState();
}
});
}
}

}
Loading