diff --git a/docs/dev-ops/environment/docker-compose.yml b/docs/dev-ops/environment/docker-compose.yml index 2dd8372a87b39b64a03722ed7516feaa526fcf76..8713f33cd9f4376a6635df76e0c1be4c94edc599 100644 --- a/docs/dev-ops/environment/docker-compose.yml +++ b/docs/dev-ops/environment/docker-compose.yml @@ -86,6 +86,7 @@ services: container_name: mysql-job-dbdata volumes: - /var/lib/mysql + # Redis redis: image: redis:7.2.0 @@ -98,6 +99,25 @@ services: networks: - my-network + # https://hub.docker.com/r/xuchengen/rocketmq + # 注意修改项; + # 01:data/rocketmq/conf/broker.conf 添加 brokerIP1=127.0.0.1 + # 02:data/console/config/application.properties server.port=9009 - 如果8080端口被占用,可以修改或者添加映射端口 + rocketmq: + image: livinphp/rocketmq:5.1.0 + container_name: rocketmq + ports: + - 8080:8080 + - 9876:9876 + - 10909:10909 + - 10911:10911 + - 10912:10912 + volumes: + - ./rocketmq/data:/home/app/data + environment: + TZ: "Asia/Shanghai" + NAMESRV_ADDR: "rocketmq:9876" + networks: my-network: driver: bridge \ No newline at end of file diff --git a/docs/dev-ops/environment/rocketmq/create-group.sh b/docs/dev-ops/environment/rocketmq/create-group.sh new file mode 100644 index 0000000000000000000000000000000000000000..2004b327285641f44799141c2d6dc255165d8f58 --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/create-group.sh @@ -0,0 +1,2 @@ +# 命令创建 消费者组 Group xfg-group 你可以更换你需要的 +docker exec -it rocketmq sh /home/app/rocketmq/bin/mqadmin updateSubGroup -n localhost:9876 -c DefaultCluster -g xfg-group diff --git a/docs/dev-ops/environment/rocketmq/create-topic.sh b/docs/dev-ops/environment/rocketmq/create-topic.sh new file mode 100644 index 0000000000000000000000000000000000000000..63393f6ed35c63f364251af542cd528ed29a33c3 --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/create-topic.sh @@ -0,0 +1,2 @@ +# 命令创建 主题消息 Topic xfg-mq 你可以更换你需要的 +docker exec -it rocketmq sh /home/app/rocketmq/bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t xfg-mq diff --git a/docs/dev-ops/environment/rocketmq/data/console/config/application.properties b/docs/dev-ops/environment/rocketmq/data/console/config/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..00936b3729510bd53d4be3a6f50520feba0d2436 --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/data/console/config/application.properties @@ -0,0 +1,54 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +server.address=0.0.0.0 +server.port=8080 + +### SSL setting +#server.ssl.key-store=classpath:rmqcngkeystore.jks +#server.ssl.key-store-password=rocketmq +#server.ssl.keyStoreType=PKCS12 +#server.ssl.keyAlias=rmqcngkey + +#spring.application.index=true +spring.application.name=rocketmq-dashboard +spring.http.encoding.charset=UTF-8 +spring.http.encoding.enabled=true +spring.http.encoding.force=true +logging.level.root=INFO +logging.config=./config/logback.xml +#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876 +rocketmq.config.namesrvAddr= +#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true +rocketmq.config.isVIPChannel= +#timeout for mqadminExt, default 5000ms +rocketmq.config.timeoutMillis= +#rocketmq-console's data path:dashboard/monitor +rocketmq.config.dataPath=./store +#set it false if you don't want use dashboard.default true +rocketmq.config.enableDashBoardCollect=true +#set the message track trace topic if you don't want use the default one +rocketmq.config.msgTrackTopicName= +rocketmq.config.ticketKey=ticket + +#Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required +rocketmq.config.loginRequired=true + +#set the accessKey and secretKey if you used acl +#rocketmq.config.accessKey= +#rocketmq.config.secretKey= +rocketmq.config.useTLS=false diff --git a/docs/dev-ops/environment/rocketmq/data/console/config/config b/docs/dev-ops/environment/rocketmq/data/console/config/config new file mode 120000 index 0000000000000000000000000000000000000000..a367cfd171d11311d064f11c9afba313f3974e8d --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/data/console/config/config @@ -0,0 +1 @@ +/home/app/data/console/config \ No newline at end of file diff --git a/docs/dev-ops/environment/rocketmq/data/console/config/logback.xml b/docs/dev-ops/environment/rocketmq/data/console/config/logback.xml new file mode 100644 index 0000000000000000000000000000000000000000..d3b20d1e731db7e403efdfef1f174ab71cbaa572 --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/data/console/config/logback.xml @@ -0,0 +1,49 @@ + + + + + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %5p %m%n + + + + + ${user.home}${file.separator}data${file.separator}logs${file.separator}consolelogs${file.separator}rocketmq-console.log + true + + ${user.home}${file.separator}data${file.separator}logs${file.separator}consolelogs${file.separator}rocketmq-console-%d{yyyy-MM-dd}.%i.log + + 104857600 + + 10 + + + [%d{yyyy-MM-dd HH:mm:ss.SSS}] %5p %m%n + UTF-8 + + + + + + + + + \ No newline at end of file diff --git a/docs/dev-ops/environment/rocketmq/data/console/store/users.properties b/docs/dev-ops/environment/rocketmq/data/console/store/users.properties new file mode 100644 index 0000000000000000000000000000000000000000..c18849be723f2b148271e2339817a5764731e541 --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/data/console/store/users.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# This file supports hot change, any change will be auto-reloaded without Dashboard restarting. +# Format: a user per line, username=password[,N] #N is optional, 0 (Normal User); 1 (Admin) + +# Define Admin +admin=admin,1 + +# Define Users +normal=normal \ No newline at end of file diff --git a/docs/dev-ops/environment/rocketmq/data/logs/logs.txt b/docs/dev-ops/environment/rocketmq/data/logs/logs.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/docs/dev-ops/environment/rocketmq/data/rocketmq/conf/broker.conf b/docs/dev-ops/environment/rocketmq/data/rocketmq/conf/broker.conf new file mode 100644 index 0000000000000000000000000000000000000000..9e6bbea4093d6ceb47c312ff5252f6684f2e53ce --- /dev/null +++ b/docs/dev-ops/environment/rocketmq/data/rocketmq/conf/broker.conf @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 集群名称 +brokerClusterName = DefaultCluster +# BROKER 名称 +brokerName = broker-a +# 0 表示 Master, > 0 表示 Slave +brokerId = 0 +# 删除文件时间点,默认凌晨 4 点 +deleteWhen = 04 +# 文件保留时间,默认 48 小时 +fileReservedTime = 48 +# BROKER 角色 ASYNC_MASTER为异步主节点,SYNC_MASTER为同步主节点,SLAVE为从节点 +brokerRole = ASYNC_MASTER +# 刷新数据到磁盘的方式,ASYNC_FLUSH 刷新 +flushDiskType = ASYNC_FLUSH +# 存储路径 +storePathRootDir = /home/app/data/rocketmq/store +# IP地址 +brokerIP1 = 127.0.0.1 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7301d744d2fd7b71ebc6c4d24ec36e51f23a4c8b..706cf0ec9b67f939dd5907f0c58790187aafd237 100644 --- a/pom.xml +++ b/pom.xml @@ -136,6 +136,16 @@ xxl-job-core 2.4.0 + + org.apache.rocketmq + rocketmq-client-java + 5.0.4 + + + org.apache.rocketmq + rocketmq-spring-boot-starter + 2.2.0 + diff --git a/xfg-frame-archetype-std-app/pom.xml b/xfg-frame-archetype-std-app/pom.xml index 2932a8654ee99bfffca0def04b4ecfbc424eb1da..650f6d4b563596f06085233a3c85eb9137ed99b7 100644 --- a/xfg-frame-archetype-std-app/pom.xml +++ b/xfg-frame-archetype-std-app/pom.xml @@ -106,6 +106,14 @@ com.xuxueli xxl-job-core + + org.apache.rocketmq + rocketmq-client-java + + + org.apache.rocketmq + rocketmq-spring-boot-starter + diff --git a/xfg-frame-archetype-std-app/src/main/resources/application-dev.yml b/xfg-frame-archetype-std-app/src/main/resources/application-dev.yml index 95db53755953209420959dfd94a89144c482b7b9..f258824d68213d67ef78180a5742850d6266c94c 100644 --- a/xfg-frame-archetype-std-app/src/main/resources/application-dev.yml +++ b/xfg-frame-archetype-std-app/src/main/resources/application-dev.yml @@ -52,6 +52,29 @@ dubbo: scan: base-packages: cn.bugstack.api +# RocketMQ 配置,在docs/dev-ops下,有创建 xfg-group 脚本,也有场景mq消息的脚本 +rocketmq: + name-server: 127.0.0.1:9876 + consumer: + group: xfg-group + # 一次拉取消息最大值,注意是拉取消息的最大值而非消费最大值 + pull-batch-size: 10 + producer: + # 发送同一类消息的设置为同一个group,保证唯一 + group: xfg-group + # 发送消息超时时间,默认3000 + sendMessageTimeout: 10000 + # 发送消息失败重试次数,默认2 + retryTimesWhenSendFailed: 2 + # 异步消息重试此处,默认2 + retryTimesWhenSendAsyncFailed: 2 + # 消息最大长度,默认1024 * 1024 * 4(默认4M) + maxMessageSize: 4096 + # 压缩消息阈值,默认4k(1024 * 4) + compressMessageBodyThreshold: 4096 + # 是否在内部发送失败时重试另一个broker,默认false + retryNextServer: false + # xxl-job https://www.xuxueli.com/xxl-job/#%E6%AD%A5%E9%AA%A4%E4%B8%80%EF%BC%9A%E8%B0%83%E5%BA%A6%E4%B8%AD%E5%BF%83%E9%85%8D%E7%BD%AE%EF%BC%9A xxl: job: diff --git a/xfg-frame-archetype-std-app/src/test/java/cn/bugstack/test/infrastructure/redis/RedisTest.java b/xfg-frame-archetype-std-app/src/test/java/cn/bugstack/test/infrastructure/redis/RedisTest.java index 33b995d55413206237733eb263427b3693e92e91..41c2e7fe3dda1b0721548c5033b691a3173f80ca 100644 --- a/xfg-frame-archetype-std-app/src/test/java/cn/bugstack/test/infrastructure/redis/RedisTest.java +++ b/xfg-frame-archetype-std-app/src/test/java/cn/bugstack/test/infrastructure/redis/RedisTest.java @@ -1,4 +1,4 @@ -package cn.bugstack.test.infrastructure.redis; +package cn.bugstack.test.infrastructure.persistent; import cn.bugstack.infrastructure.redis.IRedisService; import lombok.extern.slf4j.Slf4j; diff --git a/xfg-frame-archetype-std-trigger/pom.xml b/xfg-frame-archetype-std-trigger/pom.xml index 58ae6196867695749630208e7ef3ff5709a8596d..d4d81804f4f3762fcc5748a8398aa1bf49f97c20 100644 --- a/xfg-frame-archetype-std-trigger/pom.xml +++ b/xfg-frame-archetype-std-trigger/pom.xml @@ -38,7 +38,14 @@ com.xuxueli xxl-job-core - + + org.apache.rocketmq + rocketmq-client-java + + + org.apache.rocketmq + rocketmq-spring-boot-starter + diff --git a/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/job/XXLJob.java b/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/job/XXLJob.java index 1559fef32d1326a520f6908b7a7c46e5969900b9..0998d7c1345f3e25950c4b6c1ffde8e7918bd9c6 100644 --- a/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/job/XXLJob.java +++ b/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/job/XXLJob.java @@ -1,7 +1,10 @@ package cn.bugstack.trigger.job; import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -11,10 +14,15 @@ import org.springframework.stereotype.Component; @Component public class XXLJob { + @Setter(onMethod_ = @Autowired) + private RocketMQTemplate rocketmqTemplate; + @XxlJob("demoJobHandler") public void doJob() { // 可以在任务中,调用一些业务方法逻辑的实现,如定时扫描超时未支付订单为关单处理,恢复库存 - log.info("执行任务 - XXL-Job - 01"); + log.info("执行任务 - XXL-Job - 01 发送一条MQ消息"); + // 发送MQ消息 + rocketmqTemplate.convertAndSend("xfg-mq", "我是测试消息"); } } diff --git a/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/listener/MQListener.java b/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/listener/MQListener.java new file mode 100644 index 0000000000000000000000000000000000000000..5d3a299328ece562830e05119345dabe8e809b83 --- /dev/null +++ b/xfg-frame-archetype-std-trigger/src/main/java/cn/bugstack/trigger/listener/MQListener.java @@ -0,0 +1,22 @@ +package cn.bugstack.trigger.listener; + +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.springframework.stereotype.Component; + +/** + * RocketMQ 接收消息 + * @author Fuzhengwei bugstack.cn @小傅哥 + */ +@Component +@Slf4j +@RocketMQMessageListener(topic = "xfg-mq", consumerGroup = "xfg-group") +public class MQListener implements RocketMQListener { + + @Override + public void onMessage(String s) { + log.info("接收到RocketMQ消息 {}", s); + } + +}