Skip to content

Commit b2846ca

Browse files
authored
Merge pull request #77 from codingapi/dev
Dev
2 parents 1243e29 + eae1705 commit b2846ca

File tree

48 files changed

+573
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+573
-149
lines changed

example/example-application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.3</version>
8+
<version>3.3.5</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.codingapi.example.command;
2+
3+
import com.codingapi.example.event.TestEvent;
4+
import com.codingapi.example.infra.entity.TestEntity;
5+
import com.codingapi.example.infra.jpa.TestEntityRepository;
6+
import com.codingapi.springboot.framework.event.EventPusher;
7+
import lombok.AllArgsConstructor;
8+
import org.springframework.transaction.annotation.Transactional;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
@RequestMapping("/open/test")
15+
@AllArgsConstructor
16+
public class TestController {
17+
18+
private final TestEntityRepository testEntityRepository;
19+
20+
21+
@GetMapping("/hi")
22+
@Transactional
23+
public void hi(){
24+
TestEntity testEntity = new TestEntity("test");
25+
testEntityRepository.save(testEntity);
26+
27+
TestEvent event = new TestEvent(testEntity.getName());
28+
EventPusher.push(event);
29+
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codingapi.example.event;
2+
3+
import com.codingapi.springboot.framework.event.IEvent;
4+
5+
public class AEvent implements IEvent {
6+
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codingapi.example.event;
2+
3+
import com.codingapi.springboot.framework.event.IEvent;
4+
5+
public class BEvent implements IEvent {
6+
7+
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codingapi.example.event;
2+
3+
import com.codingapi.springboot.framework.event.IEvent;
4+
5+
public class CEvent implements IEvent {
6+
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.codingapi.example.event;
2+
3+
import com.codingapi.springboot.framework.event.IAsyncEvent;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@AllArgsConstructor
9+
public class TestEvent implements IAsyncEvent {
10+
11+
private String name;
12+
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codingapi.example.handler;
2+
3+
import com.codingapi.example.event.AEvent;
4+
import com.codingapi.example.event.BEvent;
5+
import com.codingapi.springboot.framework.event.EventPusher;
6+
import com.codingapi.springboot.framework.event.EventTraceContext;
7+
import com.codingapi.springboot.framework.event.IHandler;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.stereotype.Service;
10+
11+
@Slf4j
12+
@Service
13+
public class AHandler implements IHandler<AEvent> {
14+
15+
@Override
16+
public void handler(AEvent event) {
17+
log.info("a event:{},eventKey:{}",event, EventTraceContext.getInstance().getEventKey());
18+
19+
EventPusher.push(new BEvent());
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codingapi.example.handler;
2+
3+
import com.codingapi.example.event.BEvent;
4+
import com.codingapi.example.event.CEvent;
5+
import com.codingapi.springboot.framework.event.EventPusher;
6+
import com.codingapi.springboot.framework.event.EventTraceContext;
7+
import com.codingapi.springboot.framework.event.IHandler;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.stereotype.Service;
10+
11+
@Slf4j
12+
@Service
13+
public class BHandler implements IHandler<BEvent> {
14+
15+
@Override
16+
public void handler(BEvent event) {
17+
log.info("b event:{},eventKey:{}",event, EventTraceContext.getInstance().getEventKey());
18+
19+
EventPusher.push(new CEvent());
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.codingapi.example.handler;
2+
3+
import com.codingapi.example.event.CEvent;
4+
import com.codingapi.springboot.framework.event.EventTraceContext;
5+
import com.codingapi.springboot.framework.event.IHandler;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.stereotype.Service;
8+
9+
@Slf4j
10+
@Service
11+
public class CHandler implements IHandler<CEvent> {
12+
13+
@Override
14+
public void handler(CEvent event) {
15+
log.info("c event:{},eventKey:{}", event, EventTraceContext.getInstance().getEventKey());
16+
17+
// EventPusher.push(new AEvent());
18+
throw new RuntimeException("c handler error");
19+
}
20+
21+
@Override
22+
public void error(Exception exception) throws Exception {
23+
log.error("c handler error:{}", exception.getMessage());
24+
throw exception;
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.codingapi.example.handler;
2+
3+
import com.codingapi.example.event.AEvent;
4+
import com.codingapi.example.event.TestEvent;
5+
import com.codingapi.example.infra.entity.TestEntity;
6+
import com.codingapi.example.infra.jpa.TestEntityRepository;
7+
import com.codingapi.springboot.framework.event.EventPusher;
8+
import com.codingapi.springboot.framework.event.IHandler;
9+
import lombok.AllArgsConstructor;
10+
import org.springframework.stereotype.Repository;
11+
12+
@Repository
13+
@AllArgsConstructor
14+
public class TestHandler implements IHandler<TestEvent> {
15+
16+
private TestEntityRepository testEntityRepository;
17+
18+
@Override
19+
public void handler(TestEvent event) {
20+
TestEntity entity = new TestEntity(event.getName()+"123");
21+
testEntityRepository.save(entity);
22+
23+
new Thread(()->{
24+
EventPusher.push(new AEvent());
25+
}).start();
26+
27+
new Thread(()->{
28+
EventPusher.push(new AEvent());
29+
}).start();
30+
}
31+
32+
33+
}

0 commit comments

Comments
 (0)