Commit a5e982eff7a7792b9aa1a922c74a96b741de78c9
1 parent
b287db95
金蝶push
Showing
16 changed files
with
296 additions
and
36 deletions
ereport-start/build.gradle
@@ -9,6 +9,7 @@ bootJar { | @@ -9,6 +9,7 @@ bootJar { | ||
9 | 9 | ||
10 | dependencies { | 10 | dependencies { |
11 | implementation project(':ereport-core') | 11 | implementation project(':ereport-core') |
12 | + implementation project(':etrade-thirdparty') | ||
12 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2022.0.0.0-RC2' | 13 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2022.0.0.0-RC2' |
13 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:2022.0.0.0-RC2' | 14 | implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config:2022.0.0.0-RC2' |
14 | } | 15 | } |
ereport-start/src/main/java/com/diligrp/etrade/boss/EtradeBossBootstrap.java
@@ -4,6 +4,7 @@ import com.diligrp.etrade.core.CoreConfiguration; | @@ -4,6 +4,7 @@ import com.diligrp.etrade.core.CoreConfiguration; | ||
4 | import com.diligrp.etrade.report.ReportConfiguration; | 4 | import com.diligrp.etrade.report.ReportConfiguration; |
5 | import com.diligrp.etrade.rpc.RpcConfiguration; | 5 | import com.diligrp.etrade.rpc.RpcConfiguration; |
6 | import com.diligrp.etrade.shared.SharedConfiguration; | 6 | import com.diligrp.etrade.shared.SharedConfiguration; |
7 | +import com.diligrp.etrade.thirdparty.ThirdPartyConfiguration; | ||
7 | import org.springframework.boot.SpringApplication; | 8 | import org.springframework.boot.SpringApplication; |
8 | import org.springframework.boot.SpringBootConfiguration; | 9 | import org.springframework.boot.SpringBootConfiguration; |
9 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | 10 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
@@ -13,7 +14,7 @@ import org.springframework.context.annotation.Import; | @@ -13,7 +14,7 @@ import org.springframework.context.annotation.Import; | ||
13 | 14 | ||
14 | @SpringBootConfiguration | 15 | @SpringBootConfiguration |
15 | @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class }) | 16 | @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class }) |
16 | -@Import({BossConfiguration.class, SharedConfiguration.class, RpcConfiguration.class, CoreConfiguration.class, ReportConfiguration.class}) | 17 | +@Import({BossConfiguration.class, SharedConfiguration.class, RpcConfiguration.class, CoreConfiguration.class, ReportConfiguration.class, ThirdPartyConfiguration.class}) |
17 | @EnableDiscoveryClient | 18 | @EnableDiscoveryClient |
18 | public class EtradeBossBootstrap { | 19 | public class EtradeBossBootstrap { |
19 | public static void main(String[] args) { | 20 | public static void main(String[] args) { |
etrade-core/src/main/java/com/diligrp/etrade/core/service/ApplicationContextHolder.java
0 → 100644
1 | +package com.diligrp.etrade.core.service; | ||
2 | + | ||
3 | +import org.springframework.context.ApplicationContext; | ||
4 | + | ||
5 | +/** | ||
6 | + * ApplicationContext 持有者 | ||
7 | + */ | ||
8 | +public enum ApplicationContextHolder { | ||
9 | + | ||
10 | + INSTANCE; | ||
11 | + | ||
12 | + private ApplicationContext applicationContext; | ||
13 | + | ||
14 | + /** | ||
15 | + * 赋值 | ||
16 | + * | ||
17 | + * @param applicationContext | ||
18 | + */ | ||
19 | + public void setApplicationContext(ApplicationContext applicationContext) { | ||
20 | + this.applicationContext = applicationContext; | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * 获取bean | ||
25 | + * | ||
26 | + * @param cls | ||
27 | + * @return | ||
28 | + */ | ||
29 | + public <T> T getBean(Class<T> cls) { | ||
30 | + return this.applicationContext.getBean(cls); | ||
31 | + } | ||
32 | +} |
etrade-thirdparty/build.gradle
0 → 100644
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/ThirdPartyConfiguration.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty; | ||
2 | + | ||
3 | +import org.springframework.context.annotation.ComponentScan; | ||
4 | +import org.springframework.context.annotation.Configuration; | ||
5 | + | ||
6 | +/** | ||
7 | + * @Author: zhangmeiyang | ||
8 | + * @CreateTime: 2024-09-10 11:09 | ||
9 | + * @Version: todo | ||
10 | + */ | ||
11 | +@Configuration | ||
12 | +@ComponentScan("com.diligrp.etrade.thirdparty") | ||
13 | +public class ThirdPartyConfiguration { | ||
14 | +} |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/co/BaseCo.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.co; | ||
2 | + | ||
3 | +import com.diligrp.etrade.thirdparty.type.BusinessEnum; | ||
4 | + | ||
5 | +/** | ||
6 | + * @Author: zhangmeiyang | ||
7 | + * @CreateTime: 2024-09-10 11:30 | ||
8 | + * @Version: todo | ||
9 | + */ | ||
10 | +public class BaseCo { | ||
11 | + private String errorMessage; | ||
12 | + private Integer retryCount; | ||
13 | + private BusinessEnum businessEnum; | ||
14 | + | ||
15 | + public BaseCo() { | ||
16 | + this.retryCount = 0; | ||
17 | + } | ||
18 | + | ||
19 | + public BusinessEnum getBusinessEnum() { | ||
20 | + return businessEnum; | ||
21 | + } | ||
22 | + | ||
23 | + public void setBusinessEnum(BusinessEnum businessEnum) { | ||
24 | + this.businessEnum = businessEnum; | ||
25 | + } | ||
26 | + | ||
27 | + public Integer getRetryCount() { | ||
28 | + return retryCount; | ||
29 | + } | ||
30 | + | ||
31 | + public void setRetryCount(Integer retryCount) { | ||
32 | + this.retryCount = retryCount; | ||
33 | + } | ||
34 | + | ||
35 | + public String getErrorMessage() { | ||
36 | + return errorMessage; | ||
37 | + } | ||
38 | + | ||
39 | + public void setErrorMessage(String errorMessage) { | ||
40 | + this.errorMessage = errorMessage; | ||
41 | + } | ||
42 | +} |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/co/ErrorMessageCo.java
0 → 100644
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/co/TestCo.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.co; | ||
2 | + | ||
3 | +/** | ||
4 | + * @Author: zhangmeiyang | ||
5 | + * @CreateTime: 2024-09-10 15:06 | ||
6 | + * @Version: todo | ||
7 | + */ | ||
8 | +public class TestCo extends BaseCo{ | ||
9 | + private String name; | ||
10 | + | ||
11 | + public String getName() { | ||
12 | + return name; | ||
13 | + } | ||
14 | + | ||
15 | + public void setName(String name) { | ||
16 | + this.name = name; | ||
17 | + } | ||
18 | +} |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/executor/ZrAutoPush.java renamed to etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/exec/ZrAutoPush.java
1 | -package com.diligrp.etrade.rpc.executor; | 1 | +package com.diligrp.etrade.thirdparty.exec; |
2 | 2 | ||
3 | -import jakarta.annotation.Resource; | ||
4 | import org.springframework.amqp.core.*; | 3 | import org.springframework.amqp.core.*; |
5 | -import org.springframework.amqp.rabbit.annotation.QueueBinding; | ||
6 | -import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
7 | -import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
8 | import org.springframework.beans.factory.annotation.Qualifier; | 4 | import org.springframework.beans.factory.annotation.Qualifier; |
9 | import org.springframework.context.annotation.Bean; | 5 | import org.springframework.context.annotation.Bean; |
10 | import org.springframework.context.annotation.Configuration; | 6 | import org.springframework.context.annotation.Configuration; |
11 | -import org.springframework.stereotype.Component; | ||
12 | 7 | ||
13 | -import java.nio.charset.StandardCharsets; | ||
14 | import java.util.HashMap; | 8 | import java.util.HashMap; |
15 | import java.util.Map; | 9 | import java.util.Map; |
16 | 10 |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/exec/ZrHolder.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.exec; | ||
2 | + | ||
3 | +import com.diligrp.etrade.thirdparty.handler.AbstractBusinessHandler; | ||
4 | +import com.diligrp.etrade.thirdparty.type.BusinessEnum; | ||
5 | +import jakarta.annotation.Resource; | ||
6 | +import org.springframework.beans.factory.DisposableBean; | ||
7 | +import org.springframework.beans.factory.InitializingBean; | ||
8 | +import org.springframework.stereotype.Component; | ||
9 | + | ||
10 | +import java.util.List; | ||
11 | +import java.util.Map; | ||
12 | +import java.util.concurrent.ConcurrentHashMap; | ||
13 | + | ||
14 | +/** | ||
15 | + * @Author: zhangmeiyang | ||
16 | + * @CreateTime: 2024-09-10 10:49 | ||
17 | + * @Version: todo | ||
18 | + */ | ||
19 | +@Component | ||
20 | +public class ZrHolder implements InitializingBean, DisposableBean { | ||
21 | + | ||
22 | + public final static Map<BusinessEnum, AbstractBusinessHandler> CONTEXT = new ConcurrentHashMap<>(); | ||
23 | + | ||
24 | + @Resource | ||
25 | + private List<AbstractBusinessHandler> abstractBusinessHandlerList; | ||
26 | + | ||
27 | + @Override | ||
28 | + public void afterPropertiesSet() throws Exception { | ||
29 | + abstractBusinessHandlerList.forEach(e->{ | ||
30 | + CONTEXT.put(e.getType(), e); | ||
31 | + }); | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public void destroy() throws Exception { | ||
36 | + | ||
37 | + } | ||
38 | +} |
etrade-rpc/src/main/java/com/diligrp/etrade/rpc/executor/ZrReceiver.java renamed to etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/exec/ZrReceiver.java
1 | -package com.diligrp.etrade.rpc.executor; | 1 | +package com.diligrp.etrade.thirdparty.exec; |
2 | 2 | ||
3 | import com.diligrp.etrade.core.util.JsonUtils; | 3 | import com.diligrp.etrade.core.util.JsonUtils; |
4 | +import com.diligrp.etrade.thirdparty.co.BaseCo; | ||
5 | +import com.diligrp.etrade.thirdparty.type.BusinessEnum; | ||
4 | import com.rabbitmq.client.Channel; | 6 | import com.rabbitmq.client.Channel; |
5 | import jakarta.annotation.Resource; | 7 | import jakarta.annotation.Resource; |
8 | +import org.slf4j.Logger; | ||
9 | +import org.slf4j.LoggerFactory; | ||
6 | import org.springframework.amqp.core.Message; | 10 | import org.springframework.amqp.core.Message; |
7 | import org.springframework.amqp.core.MessageBuilder; | 11 | import org.springframework.amqp.core.MessageBuilder; |
8 | import org.springframework.amqp.rabbit.annotation.Exchange; | 12 | import org.springframework.amqp.rabbit.annotation.Exchange; |
@@ -14,9 +18,8 @@ import org.springframework.stereotype.Component; | @@ -14,9 +18,8 @@ import org.springframework.stereotype.Component; | ||
14 | 18 | ||
15 | import java.io.IOException; | 19 | import java.io.IOException; |
16 | import java.nio.charset.StandardCharsets; | 20 | import java.nio.charset.StandardCharsets; |
17 | -import java.util.Map; | ||
18 | 21 | ||
19 | -import static com.diligrp.etrade.rpc.executor.ZrAutoPush.*; | 22 | +import static com.diligrp.etrade.thirdparty.exec.ZrAutoPush.*; |
20 | 23 | ||
21 | /** | 24 | /** |
22 | * @Author: zhangmeiyang | 25 | * @Author: zhangmeiyang |
@@ -25,47 +28,49 @@ import static com.diligrp.etrade.rpc.executor.ZrAutoPush.*; | @@ -25,47 +28,49 @@ import static com.diligrp.etrade.rpc.executor.ZrAutoPush.*; | ||
25 | */ | 28 | */ |
26 | @Component | 29 | @Component |
27 | public class ZrReceiver { | 30 | public class ZrReceiver { |
28 | - | 31 | + private final static Logger LOG = LoggerFactory.getLogger(ZrReceiver.class); |
32 | + private static final Long DELAY = 5000L; | ||
33 | + private static final String DELAY_PREFIX = "x-delay"; | ||
29 | @Resource | 34 | @Resource |
30 | private RabbitTemplate rabbitTemplate; | 35 | private RabbitTemplate rabbitTemplate; |
31 | 36 | ||
32 | @RabbitListener(bindings = @QueueBinding(value = @Queue(value = ZR_NORMAL_QUEUE, autoDelete = "false"), exchange = @Exchange(value = ZR_NORMAL_EXCHANGE), key = ZR_NORMAL_ROUTING), ackMode = "MANUAL") | 37 | @RabbitListener(bindings = @QueueBinding(value = @Queue(value = ZR_NORMAL_QUEUE, autoDelete = "false"), exchange = @Exchange(value = ZR_NORMAL_EXCHANGE), key = ZR_NORMAL_ROUTING), ackMode = "MANUAL") |
33 | public void receiveMessage(Channel channel, Message message) throws IOException { | 38 | public void receiveMessage(Channel channel, Message message) throws IOException { |
39 | + var content = new String(message.getBody(), StandardCharsets.UTF_8); | ||
40 | + BaseCo baseCo = JsonUtils.fromJsonString(content, BaseCo.class); | ||
34 | try { | 41 | try { |
35 | - var temp = 1/0; | 42 | + ZrHolder.CONTEXT.get(baseCo.getBusinessEnum()).handle(content); |
36 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | 43 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
37 | - }catch (Exception e){ | ||
38 | - StackTraceElement[] stackTrace = e.getStackTrace(); | ||
39 | - String jsonString = JsonUtils.toJsonString(stackTrace); | ||
40 | - System.out.println(jsonString); | ||
41 | - sendDelayMsg(3000L,message.getBody()); | 44 | + } catch (Exception e) { |
42 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | 45 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
46 | + var t = baseCo.getBusinessEnum().getBusinessParam(content); | ||
47 | + t.setRetryCount(baseCo.getRetryCount() + 1); | ||
48 | + sendDelayMsg(DELAY, JsonUtils.toJsonString(t)); | ||
43 | } | 49 | } |
44 | } | 50 | } |
45 | 51 | ||
46 | - @RabbitListener(queues = ZR_DEAD_QUEUE) | 52 | + @RabbitListener(queues = ZR_DEAD_QUEUE, ackMode = "MANUAL") |
47 | public void handleCustomDelayMsg(Channel channel, Message message) throws IOException { | 53 | public void handleCustomDelayMsg(Channel channel, Message message) throws IOException { |
48 | - Map<String, Object> headersMap = message.getMessageProperties().getHeaders(); | ||
49 | - int retryCount = (int) headersMap.get("x-retry-count"); | 54 | + var content = new String(message.getBody(), StandardCharsets.UTF_8); |
55 | + BaseCo baseCo = JsonUtils.fromJsonString(content, BaseCo.class); | ||
50 | try { | 56 | try { |
51 | - if (retryCount > 3){ | ||
52 | - //db | ||
53 | - }else { | ||
54 | - | ||
55 | - } | 57 | + ZrHolder.CONTEXT.get(baseCo.getBusinessEnum()).handle(content); |
56 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | 58 | channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
57 | - }catch (Exception e){ | ||
58 | - retryCount++; | ||
59 | - headersMap.put("x-retry-count", retryCount); | ||
60 | - channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true); | 59 | + } catch (Exception e) { |
60 | + channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); | ||
61 | + var t = baseCo.getBusinessEnum().getBusinessParam(content); | ||
62 | + t.setRetryCount(baseCo.getRetryCount() + 1); | ||
63 | + if (t.getRetryCount() > 3) { | ||
64 | + t.setErrorMessage(e.fillInStackTrace().getMessage()); | ||
65 | + t.setBusinessEnum(BusinessEnum.ERROR); | ||
66 | + } | ||
67 | + sendDelayMsg(DELAY, JsonUtils.toJsonString(t)); | ||
61 | } | 68 | } |
62 | } | 69 | } |
63 | 70 | ||
64 | - public void sendDelayMsg(Long currentMills,byte[] bytes) { | ||
65 | - Message msg = MessageBuilder.withBody(bytes) | ||
66 | - .setHeader("x-delay", currentMills) | ||
67 | - .setHeader("x-retry-count", 0) | ||
68 | - .build(); | 71 | + public void sendDelayMsg(Long currentMills, String message) { |
72 | + byte[] bytes = message.getBytes(StandardCharsets.UTF_8); | ||
73 | + Message msg = MessageBuilder.withBody(bytes).setHeader(DELAY_PREFIX, currentMills).build(); | ||
69 | rabbitTemplate.convertAndSend(ZR_DEAD_EXCHANGE, ZR_DEAD_QUEUE, msg); | 74 | rabbitTemplate.convertAndSend(ZR_DEAD_EXCHANGE, ZR_DEAD_QUEUE, msg); |
70 | } | 75 | } |
71 | } | 76 | } |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/AbstractBusinessHandler.java
0 → 100644
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/ErrorBusinessHandler.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.handler; | ||
2 | + | ||
3 | +import com.diligrp.etrade.core.util.JsonUtils; | ||
4 | +import com.diligrp.etrade.thirdparty.co.ErrorMessageCo; | ||
5 | +import com.diligrp.etrade.thirdparty.type.BusinessEnum; | ||
6 | +import org.springframework.stereotype.Component; | ||
7 | + | ||
8 | +/** | ||
9 | + * @Author: zhangmeiyang | ||
10 | + * @CreateTime: 2024-09-10 10:56 | ||
11 | + * @Version: todo | ||
12 | + */ | ||
13 | +@Component | ||
14 | +public class ErrorBusinessHandler extends AbstractBusinessHandler { | ||
15 | + @Override | ||
16 | + public void handle(String json) { | ||
17 | + ErrorMessageCo co = JsonUtils.fromJsonString(json, ErrorMessageCo.class); | ||
18 | + System.out.println(co.getErrorMessage()); | ||
19 | + } | ||
20 | + | ||
21 | + @Override | ||
22 | + public BusinessEnum getType() { | ||
23 | + return BusinessEnum.ERROR; | ||
24 | + } | ||
25 | +} |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/handler/TestBusinessHandler.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.handler; | ||
2 | + | ||
3 | +import com.diligrp.etrade.core.util.JsonUtils; | ||
4 | +import com.diligrp.etrade.thirdparty.co.TestCo; | ||
5 | +import com.diligrp.etrade.thirdparty.type.BusinessEnum; | ||
6 | +import org.springframework.stereotype.Component; | ||
7 | + | ||
8 | +/** | ||
9 | + * @Author: zhangmeiyang | ||
10 | + * @CreateTime: 2024-09-10 15:03 | ||
11 | + * @Version: todo | ||
12 | + */ | ||
13 | +@Component | ||
14 | +public class TestBusinessHandler extends AbstractBusinessHandler{ | ||
15 | + @Override | ||
16 | + public void handle(String json) { | ||
17 | + TestCo testCo = JsonUtils.fromJsonString(json, TestCo.class); | ||
18 | + var s = 1/0; | ||
19 | + } | ||
20 | + | ||
21 | + @Override | ||
22 | + public BusinessEnum getType() { | ||
23 | + return BusinessEnum.TEST; | ||
24 | + } | ||
25 | +} |
etrade-thirdparty/src/main/java/com/diligrp/etrade/thirdparty/type/BusinessEnum.java
0 → 100644
1 | +package com.diligrp.etrade.thirdparty.type; | ||
2 | + | ||
3 | +import com.diligrp.etrade.core.util.JsonUtils; | ||
4 | +import com.diligrp.etrade.thirdparty.co.BaseCo; | ||
5 | +import com.diligrp.etrade.thirdparty.co.ErrorMessageCo; | ||
6 | +import com.diligrp.etrade.thirdparty.co.TestCo; | ||
7 | + | ||
8 | +/** | ||
9 | + * @Author: zhangmeiyang | ||
10 | + * @CreateTime: 2024-09-10 10:53 | ||
11 | + * @Version: todo | ||
12 | + */ | ||
13 | +public enum BusinessEnum implements BusinessKlass{ | ||
14 | + | ||
15 | + ERROR("ERROR"){ | ||
16 | + @Override | ||
17 | + public ErrorMessageCo getBusinessParam(String content) { | ||
18 | + return JsonUtils.fromJsonString(content,ErrorMessageCo.class); | ||
19 | + } | ||
20 | + }, | ||
21 | + | ||
22 | + TEST("TEST"){ | ||
23 | + @Override | ||
24 | + public TestCo getBusinessParam(String content) { | ||
25 | + return JsonUtils.fromJsonString(content,TestCo.class); | ||
26 | + } | ||
27 | + }; | ||
28 | + | ||
29 | + public final String code; | ||
30 | + | ||
31 | + BusinessEnum(String code) { | ||
32 | + this.code = code; | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | +interface BusinessKlass<T extends BaseCo> { | ||
37 | + T getBusinessParam(String content); | ||
38 | + | ||
39 | +} |
settings.gradle
1 | rootProject.name = 'dili-ereport' | 1 | rootProject.name = 'dili-ereport' |
2 | include 'etrade-core' | 2 | include 'etrade-core' |
3 | +include 'etrade-thirdparty' | ||
3 | include 'etrade-rpc' | 4 | include 'etrade-rpc' |
4 | include 'etrade-shared' | 5 | include 'etrade-shared' |
5 | include 'ereport-start' | 6 | include 'ereport-start' |
6 | include 'ereport-core' | 7 | include 'ereport-core' |
7 | 8 | ||
8 | - |