diff --git a/README.md b/README.md index 9563cac..729ea09 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ - 服务注册与配置中心:Nacos、Eureka、Dubbo; - 支付:IJPay; - 微信生态支持:WxJava; -- 多种通信支持:gRPC、HTTP等; +- 多种通信支持:gRPC、HTTP、WebSocket等; - 分布式处理引擎:Apache Flink; - 文件存储:私有云或公有云均支持; - 单元测试框架:Junit; @@ -193,23 +193,29 @@ - 例子覆盖60%(yc-example)。 -## 本次版本V1.0.9更新 -- 1.接入空气质量数据(和风天气API)。 -- 2.新增image-combiner(Java服务端图片合成工具)。 -- 3.新增easyes(在elatic search基础上只做增强不做改变)。 -- 4.新增dynamic-tp(动态线程池监控)。 -- 5.新增Gobrs-Async(高性能异步编排)。 -- 6.新增easypdf(一个用搭积木的方式构建pdf)。 -- 7.修复若干bug。 -- 8.支持InfluxDB。 -- 9.支持Clickhouse。 -- 10.支持Ti-DB。 -- 11.支持SQL Server。 -- 12.支持postgreSQL。 -- 13.支持neo4j。 -- 14.支持couchbase。 -- 15.支持达梦数据库。 -- 16.yc-framework官方文档全部开源。 +## 本次版本V1.0.10更新 +- 1.精简与完善Example +- 2.鉴权体系精确到接口级别 +- 3.文档全面更新 +- 4.增加JWT插件 +- 5.修复若干bug +- 6.增加国密算法(SM2 SM3 SM4) +- 7.升级: + - (1)LiteFlow升级2.9.3 + - (2)Sa-Token升级1.32.0 + - (3)Wx-Java升级4.4.0 + - (4)Smart-Socket升级1.6.0 + - (5)ShedLock升级4.42.0 + - (6)T-Log升级1.5.0 + - (7)IJPay升级2.9.4 + - (8)Image Combiner升级2.3.7 + - (9)Gobrs Async升级1.2.3-RELEASE + - (10)ElasticJob升级3.0.2 + - (11)Easy-Poi升级4.4.0 + - (12)Dynamic-Tp升级1.0.9 + - (13)Easy-ES升级1.0.3 + - (14)Dubbo升级3.1.2 + - (15)WebMagic升级0.7.6 ## 八、环境 diff --git a/pom.xml b/pom.xml index ae3ca5b..7f44363 100644 --- a/pom.xml +++ b/pom.xml @@ -44,12 +44,12 @@ 5.2.2.RELEASE 1.11.3 0.7.4 - 1.31.0 + 1.32.0 2.11.3 0.4 21.0 3.6 - 1.4.1 + 1.5.0 @@ -499,6 +499,24 @@ ${version} + + com.yc.framework + yc-common-sqlserver + ${version} + + + + com.yc.framework + yc-common-clickhouse + ${version} + + + + com.yc.framework + yc-common-websocket + ${version} + + com.google.guava guava @@ -577,20 +595,6 @@ - - central - aliyun maven - http://maven.aliyun.com/nexus/content/groups/public/ - default - - - true - - - - false - - diff --git a/yc-common/pom.xml b/yc-common/pom.xml index 1414aa7..5133f41 100644 --- a/yc-common/pom.xml +++ b/yc-common/pom.xml @@ -63,6 +63,7 @@ yc-common-postgresql yc-common-neo4j yc-common-dmjdbc + yc-common-websocket diff --git a/yc-common/yc-common-core/src/main/java/com/yc/common/core/base/utils/JudgeSysUtil.java b/yc-common/yc-common-core/src/main/java/com/yc/common/core/base/utils/JudgeSysUtil.java new file mode 100644 index 0000000..3ff3879 --- /dev/null +++ b/yc-common/yc-common-core/src/main/java/com/yc/common/core/base/utils/JudgeSysUtil.java @@ -0,0 +1,53 @@ +package com.yc.common.core.base.utils; + +/** + * @description: + * @author: youcong + */ +public class JudgeSysUtil { + + private static final String OS_NAME = "os.name"; + + private static final String LINUX_SYS = "linux"; + + private static final String WINDOWS_SYS = "windows"; + + private static final String OTHER_SYS = "other system"; + + /** + * Linux + * + * @return + */ + public static boolean isLinux() { + return System.getProperty(OS_NAME).toLowerCase().contains("linux"); + } + + /** + * Windows + * + * @return + */ + public static boolean isWindows() { + return System.getProperty(OS_NAME).toLowerCase().contains("windows"); + } + + /** + * 判断当前操作系统 + * + * @return + */ + public static String JudgeSystem() { + if (isLinux()) { + return LINUX_SYS; + } else if (isWindows()) { + return WINDOWS_SYS; + } else { + return OTHER_SYS; + } + } + + public static void main(String[] args) { + System.out.println("current system is:" + JudgeSysUtil.JudgeSystem()); + } +} diff --git a/yc-common/yc-common-crawler/pom.xml b/yc-common/yc-common-crawler/pom.xml index 10c49e9..56550ae 100644 --- a/yc-common/yc-common-crawler/pom.xml +++ b/yc-common/yc-common-crawler/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-crawler - 0.7.4 + 0.7.6 diff --git a/yc-common/yc-common-dubbo/pom.xml b/yc-common/yc-common-dubbo/pom.xml index feb438b..bffb749 100644 --- a/yc-common/yc-common-dubbo/pom.xml +++ b/yc-common/yc-common-dubbo/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-dubbo - 2.7.6 + 3.1.2 diff --git a/yc-common/yc-common-dynamic-tp/pom.xml b/yc-common/yc-common-dynamic-tp/pom.xml index e3c30dd..61f7398 100644 --- a/yc-common/yc-common-dynamic-tp/pom.xml +++ b/yc-common/yc-common-dynamic-tp/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-dynamic-tp - 1.0.8 + 1.0.9 diff --git a/yc-common/yc-common-easyes/pom.xml b/yc-common/yc-common-easyes/pom.xml index b236cc8..45dd7de 100644 --- a/yc-common/yc-common-easyes/pom.xml +++ b/yc-common/yc-common-easyes/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-easyes - 1.0.1 + 1.0.3 diff --git a/yc-common/yc-common-easypoi/pom.xml b/yc-common/yc-common-easypoi/pom.xml index 4e4fd3a..ed7a01b 100644 --- a/yc-common/yc-common-easypoi/pom.xml +++ b/yc-common/yc-common-easypoi/pom.xml @@ -13,7 +13,7 @@ yc-common-easypoi - 4.1.0 + 4.4.0 diff --git a/yc-common/yc-common-elasticjob/pom.xml b/yc-common/yc-common-elasticjob/pom.xml index 9757b1a..cca8ab3 100644 --- a/yc-common/yc-common-elasticjob/pom.xml +++ b/yc-common/yc-common-elasticjob/pom.xml @@ -13,7 +13,7 @@ yc-common-elasticjob - 3.0.1 + 3.0.2 diff --git a/yc-common/yc-common-gobrs-async/pom.xml b/yc-common/yc-common-gobrs-async/pom.xml index 1956806..0a0c707 100644 --- a/yc-common/yc-common-gobrs-async/pom.xml +++ b/yc-common/yc-common-gobrs-async/pom.xml @@ -13,7 +13,7 @@ yc-common-gobrs-async - 1.2.1-RELEASE + 1.2.3-RELEASE diff --git a/yc-common/yc-common-image-combiner/pom.xml b/yc-common/yc-common-image-combiner/pom.xml index eddfabd..0d58ea7 100644 --- a/yc-common/yc-common-image-combiner/pom.xml +++ b/yc-common/yc-common-image-combiner/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-image-combiner - 2.3.5 + 2.3.7 diff --git a/yc-common/yc-common-liteflow/pom.xml b/yc-common/yc-common-liteflow/pom.xml index f603502..d8d6669 100644 --- a/yc-common/yc-common-liteflow/pom.xml +++ b/yc-common/yc-common-liteflow/pom.xml @@ -14,7 +14,7 @@ - 2.9.0 + 2.9.3 diff --git a/yc-common/yc-common-pay/pom.xml b/yc-common/yc-common-pay/pom.xml index 3c11f54..c3a4341 100644 --- a/yc-common/yc-common-pay/pom.xml +++ b/yc-common/yc-common-pay/pom.xml @@ -13,7 +13,7 @@ yc-common-pay - 2.7.9 + 2.9.4 diff --git a/yc-common/yc-common-seata/pom.xml b/yc-common/yc-common-seata/pom.xml index 7db4460..f567134 100644 --- a/yc-common/yc-common-seata/pom.xml +++ b/yc-common/yc-common-seata/pom.xml @@ -11,16 +11,11 @@ com.yc.framework yc-common-seata - - - - io.seata seata-spring-boot-starter - \ No newline at end of file diff --git a/yc-common/yc-common-shedlock/pom.xml b/yc-common/yc-common-shedlock/pom.xml index 09ba54c..fe2ba2a 100644 --- a/yc-common/yc-common-shedlock/pom.xml +++ b/yc-common/yc-common-shedlock/pom.xml @@ -12,7 +12,7 @@ com.yc.framework yc-common-shedlock - 4.28.0 + 4.42.0 diff --git a/yc-common/yc-common-smart-socket/pom.xml b/yc-common/yc-common-smart-socket/pom.xml index d023267..1d1d2cc 100644 --- a/yc-common/yc-common-smart-socket/pom.xml +++ b/yc-common/yc-common-smart-socket/pom.xml @@ -13,7 +13,7 @@ yc-common-smart-socket - 1.5.15 + 1.6.0 diff --git a/yc-example/yc-example-smart-socket/pom.xml b/yc-common/yc-common-websocket/pom.xml similarity index 71% rename from yc-example/yc-example-smart-socket/pom.xml rename to yc-common/yc-common-websocket/pom.xml index 3a81e2a..04f0a29 100644 --- a/yc-example/yc-example-smart-socket/pom.xml +++ b/yc-common/yc-common-websocket/pom.xml @@ -3,19 +3,18 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - yc-example + yc-common com.yc.framework 1.0 4.0.0 com.yc.framework - yc-example-smart-socket - + yc-common-websocket - com.yc.framework - yc-common-smart-socket + org.springframework.boot + spring-boot-starter-websocket diff --git a/yc-common/yc-common-wx/pom.xml b/yc-common/yc-common-wx/pom.xml index 00a10c0..1bf2c0b 100644 --- a/yc-common/yc-common-wx/pom.xml +++ b/yc-common/yc-common-wx/pom.xml @@ -13,7 +13,7 @@ yc-common-wx - 4.1.0 + 4.4.0 diff --git a/yc-example/pom.xml b/yc-example/pom.xml index 794c726..4433b5e 100644 --- a/yc-example/pom.xml +++ b/yc-example/pom.xml @@ -41,7 +41,6 @@ yc-example-test yc-example-netty yc-example-liteflow - yc-example-smart-socket yc-example-dynamic-tp yc-example-gobrs-async yc-example-image-combiner @@ -57,6 +56,7 @@ yc-example-quartz yc-example-postgresql yc-example-neo4j + yc-example-websocket diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/AProcess.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/AProcess.java index 5a163ad..f6f0a28 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/AProcess.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/AProcess.java @@ -16,9 +16,5 @@ public class AProcess extends NodeComponent { public void process() { System.out.println("第一道流程"); ProcessReqDTO req = this.getSlot().getRequestData(); - ProcessSlot processSlot = this.getSlot(); - processSlot.setProcessId(req.getProcessId()); - processSlot.setProcessName(req.getProcessName()); - processSlot.setProcessStatus(req.getProcessStatus()); } } \ No newline at end of file diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/BProcess.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/BProcess.java index acb117a..0ec6a3d 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/BProcess.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/BProcess.java @@ -1,6 +1,5 @@ package com.yc.example.liteflow.component; -import com.yc.example.liteflow.slot.ProcessSlot; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; @@ -13,9 +12,5 @@ public class BProcess extends NodeComponent { @Override public void process() throws Exception { System.out.println("第二道流程"); - ProcessSlot processSlot = this.getSlot(); - if (processSlot.getProcessId() == null) { - throw new RuntimeException("流程ID为空"); - } } } diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/CProcess.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/CProcess.java index e98f20d..81f3b98 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/CProcess.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/component/CProcess.java @@ -1,6 +1,5 @@ package com.yc.example.liteflow.component; -import com.yc.example.liteflow.slot.ProcessSlot; import com.yomahub.liteflow.core.NodeComponent; import org.springframework.stereotype.Component; @@ -13,7 +12,5 @@ public class CProcess extends NodeComponent { @Override public void process() throws Exception { System.out.println("第三道流程"); - ProcessSlot processSlot = this.getSlot(); - System.out.println("result:" + processSlot); } } diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/controller/ProccessController.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/controller/ProccessController.java index 27d7135..9e907c1 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/controller/ProccessController.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/controller/ProccessController.java @@ -3,7 +3,7 @@ import com.yc.example.liteflow.dto.ProcessReqDTO; import com.yc.example.liteflow.slot.ProcessSlot; import com.yomahub.liteflow.core.FlowExecutor; -import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.flow.LiteflowResponse; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,7 +21,7 @@ public class ProccessController { @GetMapping("/test") public String test() { ProcessReqDTO processReqDTO = getProcessReqDTO(); - LiteflowResponse response = flowExecutor.execute2Resp("chain1", processReqDTO, ProcessSlot.class); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", processReqDTO, ProcessSlot.class); System.out.println("isSuccess:" + response.isSuccess()); System.out.println("slot:" + response.getSlot()); return response.getMessage(); diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/dto/ProcessReqDTO.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/dto/ProcessReqDTO.java index db0ee24..b5926eb 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/dto/ProcessReqDTO.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/dto/ProcessReqDTO.java @@ -1,6 +1,7 @@ package com.yc.example.liteflow.dto; -import com.yomahub.liteflow.entity.data.AbsSlot; + +import com.yomahub.liteflow.slot.Slot; import lombok.Builder; import lombok.Data; @@ -10,7 +11,7 @@ */ @Data @Builder -public class ProcessReqDTO extends AbsSlot { +public class ProcessReqDTO extends Slot { private Long processId; private String processName; private Integer processStatus; diff --git a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/slot/ProcessSlot.java b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/slot/ProcessSlot.java index aee01ba..3503b00 100644 --- a/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/slot/ProcessSlot.java +++ b/yc-example/yc-example-liteflow/src/main/java/com/yc/example/liteflow/slot/ProcessSlot.java @@ -1,7 +1,7 @@ package com.yc.example.liteflow.slot; -import com.yomahub.liteflow.entity.data.AbsSlot; +import com.yomahub.liteflow.slot.Slot; import lombok.Data; /** @@ -9,7 +9,7 @@ * @author: youcong */ @Data -public class ProcessSlot extends AbsSlot { +public class ProcessSlot extends Slot { private Long processId; private String processName; private Integer processStatus; diff --git a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketClient.java b/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketClient.java deleted file mode 100644 index f1b4eca..0000000 --- a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketClient.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.yc.example.smart.socket; - -import org.smartboot.socket.MessageProcessor; -import org.smartboot.socket.transport.AioQuickClient; -import org.smartboot.socket.transport.AioSession; -import org.smartboot.socket.transport.WriteBuffer; - -import java.io.IOException; - -/** - * @description: - * @author: youcong - */ -public class YcSmartSocketClient { - - public static void main(String[] args) throws IOException { - MessageProcessor processor = new MessageProcessor() { - @Override - public void process(AioSession session, String msg) { - System.out.println("receive from server: " + msg); - } - }; - AioQuickClient client = new AioQuickClient("localhost", 8888, new YcSmartSocketProtocol(), processor); - AioSession session = client.start(); - WriteBuffer writeBuffer = session.writeBuffer(); - byte[] data = "hello smart-socket".getBytes(); - writeBuffer.writeInt(data.length); - writeBuffer.write(data); - writeBuffer.flush(); - } -} diff --git a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketProtocol.java b/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketProtocol.java deleted file mode 100644 index 50f63cb..0000000 --- a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketProtocol.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.yc.example.smart.socket; - -import org.smartboot.socket.Protocol; -import org.smartboot.socket.transport.AioSession; - -import java.nio.ByteBuffer; - -/** - * @description: - * @author: youcong - */ -public class YcSmartSocketProtocol implements Protocol { - @Override - public String decode(ByteBuffer readBuffer, AioSession session) { - int remaining = readBuffer.remaining(); - if (remaining < Integer.BYTES) { - return null; - } - readBuffer.mark(); - int length = readBuffer.getInt(); - if (length > readBuffer.remaining()) { - readBuffer.reset(); - return null; - } - byte[] b = new byte[length]; - readBuffer.get(b); - readBuffer.mark(); - return new String(b); - } -} diff --git a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketServer.java b/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketServer.java deleted file mode 100644 index 9e05a45..0000000 --- a/yc-example/yc-example-smart-socket/src/main/java/com/yc/example/smart/socket/YcSmartSocketServer.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.yc.example.smart.socket; - -import org.smartboot.socket.MessageProcessor; -import org.smartboot.socket.transport.AioQuickServer; -import org.smartboot.socket.transport.AioSession; -import org.smartboot.socket.transport.WriteBuffer; - -import java.io.IOException; - -/** - * @description: - * @author: youcong - */ -public class YcSmartSocketServer { - public static void main(String[] args) throws IOException { - MessageProcessor processor = new MessageProcessor() { - @Override - public void process(AioSession session, String msg) { - System.out.println("receive from client: " + msg); - WriteBuffer outputStream = session.writeBuffer(); - try { - byte[] bytes = msg.getBytes(); - outputStream.writeInt(bytes.length); - outputStream.write(bytes); - } catch (IOException e) { - e.printStackTrace(); - } - } - }; - - AioQuickServer server = new AioQuickServer(8888, new YcSmartSocketProtocol(), processor); - server.start(); - } -} diff --git a/yc-example/yc-example-websocket/pom.xml b/yc-example/yc-example-websocket/pom.xml new file mode 100644 index 0000000..fe183be --- /dev/null +++ b/yc-example/yc-example-websocket/pom.xml @@ -0,0 +1,33 @@ + + + + yc-example + com.yc.framework + 1.0 + + 4.0.0 + + com.yc.framework + yc-example-websocket + + + com.yc.framework + yc-common-websocket + + + org.springframework.boot + spring-boot-starter-web + + + com.yc.framework + yc-common-core + + + org.springframework.boot + spring-boot-starter-freemarker + + + + \ No newline at end of file diff --git a/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/YcExampleWebSocketApplication.java b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/YcExampleWebSocketApplication.java new file mode 100644 index 0000000..0714159 --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/YcExampleWebSocketApplication.java @@ -0,0 +1,16 @@ +package com.yc.example.websocket; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +/** + * @description: + * @author: youcong + */ +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +public class YcExampleWebSocketApplication { + public static void main(String[] args) { + SpringApplication.run(YcExampleWebSocketApplication.class, args); + } +} diff --git a/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/config/WebSocketConfig.java b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/config/WebSocketConfig.java new file mode 100644 index 0000000..1213531 --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/config/WebSocketConfig.java @@ -0,0 +1,17 @@ +package com.yc.example.websocket.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +/** + * @description: + * @author: youcong + */ +@Configuration +public class WebSocketConfig { + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } +} diff --git a/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/IndexController.java b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/IndexController.java new file mode 100644 index 0000000..88f222b --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/IndexController.java @@ -0,0 +1,17 @@ +package com.yc.example.websocket.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @description: + * @author: youcong + */ +@Controller +public class IndexController { + + @RequestMapping("/index") + public String index() { + return "index"; + } +} diff --git a/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/TestController.java b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/TestController.java new file mode 100644 index 0000000..5df85d4 --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/controller/TestController.java @@ -0,0 +1,31 @@ +package com.yc.example.websocket.controller; + +import com.yc.example.websocket.server.WebSocketServer; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @description: + * @author: youcong + */ +@RestController +public class TestController { + //推送数据接口 + @RequestMapping("/socket/push/{cid}") + public Map pushToWeb(@PathVariable String cid, String message) { + Map result = new HashMap<>(); + try { + WebSocketServer.sendInfo(message, cid); + result.put("code", cid); + result.put("msg", message); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/server/WebSocketServer.java b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/server/WebSocketServer.java new file mode 100644 index 0000000..346ce89 --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/java/com/yc/example/websocket/server/WebSocketServer.java @@ -0,0 +1,134 @@ +package com.yc.example.websocket.server; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; +import java.util.concurrent.CopyOnWriteArraySet; + +/** + * @description: + * @author: youcong + */ +@Component +@Slf4j +@Service +@ServerEndpoint("/api/websocket/{sid}") +public class WebSocketServer { + //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 + private static int onlineCount = 0; + //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 + private static CopyOnWriteArraySet webSocketSet = new CopyOnWriteArraySet(); + + //与某个客户端的连接会话,需要通过它来给客户端发送数据 + private Session session; + + //接收sid + private String sid = ""; + + /** + * 连接建立成功调用的方法 + */ + @OnOpen + public void onOpen(Session session, @PathParam("sid") String sid) { + this.session = session; + webSocketSet.add(this); //加入set中 + this.sid = sid; + addOnlineCount(); //在线数加1 + try { + sendMessage("conn_success"); + log.info("有新窗口开始监听:" + sid + ",当前在线人数为:" + getOnlineCount()); + } catch (IOException e) { + log.error("websocket IO Exception"); + } + } + + /** + * 连接关闭调用的方法 + */ + @OnClose + public void onClose() { + webSocketSet.remove(this); //从set中删除 + subOnlineCount(); //在线数减1 + //断开连接情况下,更新主板占用情况为释放 + log.info("释放的sid为:" + sid); + //这里写你 释放的时候,要处理的业务 + log.info("有一连接关闭!当前在线人数为" + getOnlineCount()); + + } + + /** + * 收到客户端消息后调用的方法 + * + * @ Param message 客户端发送过来的消息 + */ + @OnMessage + public void onMessage(String message, Session session) { + log.info("收到来自窗口" + sid + "的信息:" + message); + //群发消息 + for (WebSocketServer item : webSocketSet) { + try { + item.sendMessage(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * @ Param session + * @ Param error + */ + @OnError + public void onError(Session session, Throwable error) { + log.error("发生错误"); + error.printStackTrace(); + } + + /** + * 实现服务器主动推送 + */ + public void sendMessage(String message) throws IOException { + this.session.getBasicRemote().sendText(message); + } + + /** + * 群发自定义消息 + */ + public static void sendInfo(String message, @PathParam("sid") String sid) throws IOException { + log.info("推送消息到窗口" + sid + ",推送内容:" + message); + + for (WebSocketServer item : webSocketSet) { + try { + //这里可以设定只推送给这个sid的,为null则全部推送 + if (sid == null) { +// item.sendMessage(message); + } else if (item.sid.equals(sid)) { + item.sendMessage(message); + } + } catch (IOException e) { + continue; + } + } + } + + public static synchronized int getOnlineCount() { + return onlineCount; + } + + public static synchronized void addOnlineCount() { + WebSocketServer.onlineCount++; + } + + public static synchronized void subOnlineCount() { + WebSocketServer.onlineCount--; + } + + public static CopyOnWriteArraySet getWebSocketSet() { + return webSocketSet; + } +} \ No newline at end of file diff --git a/yc-example/yc-example-websocket/src/main/resources/bootstrap.yml b/yc-example/yc-example-websocket/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..98c134c --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/resources/bootstrap.yml @@ -0,0 +1,23 @@ +server: + port: 9800 + +# Spring +spring: + freemarker: + settings: + classic_compatible: true #处理空值 + datetime_format: yyy-MM-dd HH:mm + number_format: 0.## + suffix: .ftl + template-loader-path: + - classpath:/templates + servlet: + multipart: + max-request-size: 5GB # 上传文件总的最大值 + max-file-size: 1GB #单个文件最大值 + mvc: + pathmatch: + matching-strategy: ant_path_matcher + application: + # 应用名称 + name: platform-websocket diff --git a/yc-example/yc-example-websocket/src/main/resources/templates/index.ftl b/yc-example/yc-example-websocket/src/main/resources/templates/index.ftl new file mode 100644 index 0000000..3ba7aad --- /dev/null +++ b/yc-example/yc-example-websocket/src/main/resources/templates/index.ftl @@ -0,0 +1,74 @@ + + + + + + WebSocket Test + + + + +
+Welcome
+ +
+ +
+ +
+ + + + diff --git a/yc-framework-docs/README.md b/yc-framework-docs/README.md index 9839918..85cceb7 100644 --- a/yc-framework-docs/README.md +++ b/yc-framework-docs/README.md @@ -50,7 +50,7 @@ - 服务注册与配置中心:Nacos、Eureka、Dubbo; - 支付:IJPay; - 微信生态支持:WxJava; -- 多种通信支持:gRPC、HTTP等; +- 多种通信支持:gRPC、HTTP、WebSocket等; - 分布式处理引擎:Apache Flink; - 文件存储:私有云或公有云均支持; - 单元测试框架:Junit; @@ -195,24 +195,29 @@ - 例子覆盖60%(yc-example)。 -## 本次版本V1.0.9更新 -- 1.接入空气质量数据(和风天气API)。 -- 2.新增image-combiner(Java服务端图片合成工具)。 -- 3.新增easyes(在elatic search基础上只做增强不做改变)。 -- 4.新增dynamic-tp(动态线程池监控)。 -- 5.新增Gobrs-Async(高性能异步编排)。 -- 6.新增easypdf(一个用搭积木的方式构建pdf)。 -- 7.修复若干bug。 -- 8.支持InfluxDB。 -- 9.支持Clickhouse。 -- 10.支持Ti-DB。 -- 11.支持SQL Server。 -- 12.支持postgreSQL。 -- 13.支持neo4j。 -- 14.支持couchbase。 -- 15.支持达梦数据库。 -- (16)yc-framework官方文档全部开源。 - +## 本次版本V1.0.10更新 +- 1.精简与完善Example +- 2.鉴权体系精确到接口级别 +- 3.文档全面更新 +- 4.增加JWT插件 +- 5.修复若干bug +- 6.增加国密算法(SM2 SM3 SM4) +- 7.升级: + - (1)LiteFlow升级2.9.3 + - (2)Sa-Token升级1.32.0 + - (3)Wx-Java升级4.4.0 + - (4)Smart-Socket升级1.6.0 + - (5)ShedLock升级4.42.0 + - (6)T-Log升级1.5.0 + - (7)IJPay升级2.9.4 + - (8)Image Combiner升级2.3.7 + - (9)Gobrs Async升级1.2.3-RELEASE + - (10)ElasticJob升级3.0.2 + - (11)Easy-Poi升级4.4.0 + - (12)Dynamic-Tp升级1.0.9 + - (13)Easy-ES升级1.0.3 + - (14)Dubbo升级3.1.2 + - (15)WebMagic升级0.7.6 ## 八、环境 ### 1.开发环境 diff --git a/yc-framework-docs/_coverpage.md b/yc-framework-docs/_coverpage.md index 6450c9d..40e8a4c 100644 --- a/yc-framework-docs/_coverpage.md +++ b/yc-framework-docs/_coverpage.md @@ -1,7 +1,7 @@ ![logo](_media/logo.png) -# YC-Framework 1.0.9 +# YC-Framework 1.0.10 > 致力于打造一款优秀的分布式微服务解决方案