From f8937b3af617535c67438f1e892e9428bcf74395 Mon Sep 17 00:00:00 2001 From: Administrator Date: Mon, 15 May 2023 23:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E7=BD=91=E5=85=B3=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=90=AD=E5=BB=BA=E5=92=8C=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B6=88=E8=B4=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mashibing/push/mq/PushReportListener.java | 1 + beacon-smsgateway/pom.xml | 46 +++++++++++++++++++ .../smsgateway/SmsGatewayStarterApp.java | 19 ++++++++ .../smsgateway/config/RabbitMQConfig.java | 29 ++++++++++++ .../smsgateway/mq/SmsGatewayListener.java | 29 ++++++++++++ .../src/main/resources/bootstrap.yml | 16 +++++++ .../com/mashibing/test/TestStarterApp.java | 3 +- pom.xml | 1 + 8 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 beacon-smsgateway/pom.xml create mode 100644 beacon-smsgateway/src/main/java/com/mashibing/smsgateway/SmsGatewayStarterApp.java create mode 100644 beacon-smsgateway/src/main/java/com/mashibing/smsgateway/config/RabbitMQConfig.java create mode 100644 beacon-smsgateway/src/main/java/com/mashibing/smsgateway/mq/SmsGatewayListener.java create mode 100644 beacon-smsgateway/src/main/resources/bootstrap.yml diff --git a/beacon-push/src/main/java/com/mashibing/push/mq/PushReportListener.java b/beacon-push/src/main/java/com/mashibing/push/mq/PushReportListener.java index aba44d1..89f7912 100644 --- a/beacon-push/src/main/java/com/mashibing/push/mq/PushReportListener.java +++ b/beacon-push/src/main/java/com/mashibing/push/mq/PushReportListener.java @@ -116,6 +116,7 @@ public class PushReportListener { //3、得到响应后,确认是否为SUCCESS return flag; } + /** * 判断状态报告是否推送成功,失败的话需要发送重试消息 * @param report diff --git a/beacon-smsgateway/pom.xml b/beacon-smsgateway/pom.xml new file mode 100644 index 0000000..8137be2 --- /dev/null +++ b/beacon-smsgateway/pom.xml @@ -0,0 +1,46 @@ + + + + beacon-cloud + com.mashibing + 1.0-SNAPSHOT + + 4.0.0 + + beacon-smsgateway + 短信网关模块的模板 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.mashibing + beacon-common + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-amqp + + + + + \ No newline at end of file diff --git a/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/SmsGatewayStarterApp.java b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/SmsGatewayStarterApp.java new file mode 100644 index 0000000..07a99d5 --- /dev/null +++ b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/SmsGatewayStarterApp.java @@ -0,0 +1,19 @@ +package com.mashibing.smsgateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * @author zjw + * @description + */ +@SpringBootApplication +@EnableDiscoveryClient +public class SmsGatewayStarterApp { + + public static void main(String[] args) { + SpringApplication.run(SmsGatewayStarterApp.class,args); + } + +} diff --git a/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/config/RabbitMQConfig.java b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/config/RabbitMQConfig.java new file mode 100644 index 0000000..270bb6c --- /dev/null +++ b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/config/RabbitMQConfig.java @@ -0,0 +1,29 @@ +package com.mashibing.smsgateway.config; + +import org.springframework.amqp.core.AcknowledgeMode; +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 针对性的配置,可以采用当前方式~ + * @author zjw + * @description + */ +//@Configuration +public class RabbitMQConfig { + +// @Bean + public SimpleRabbitListenerContainerFactory gatewayContainerFactory(ConnectionFactory connectionFactory, + SimpleRabbitListenerContainerFactoryConfigurer configurer){ + SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory = new SimpleRabbitListenerContainerFactory(); + simpleRabbitListenerContainerFactory.setConcurrentConsumers(5); + simpleRabbitListenerContainerFactory.setPrefetchCount(10); + simpleRabbitListenerContainerFactory.setAcknowledgeMode(AcknowledgeMode.MANUAL); + configurer.configure(simpleRabbitListenerContainerFactory,connectionFactory); + return simpleRabbitListenerContainerFactory; + } + +} diff --git a/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/mq/SmsGatewayListener.java b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/mq/SmsGatewayListener.java new file mode 100644 index 0000000..33a3f1b --- /dev/null +++ b/beacon-smsgateway/src/main/java/com/mashibing/smsgateway/mq/SmsGatewayListener.java @@ -0,0 +1,29 @@ +package com.mashibing.smsgateway.mq; + +import com.mashibing.common.model.StandardSubmit; +import com.rabbitmq.client.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +import java.io.IOException; + + +/** + * @author zjw + * @description + */ +@Component +@Slf4j +public class SmsGatewayListener { + + @RabbitListener(queues = "${gateway.sendtopic}",containerFactory = "gatewayContainerFactory") + public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException, InterruptedException { + log.info("【短信网关模块】 接收到消息 submit = {}",submit); + // =====================完成运营商交互,发送一次请求,接收两次响应========================== + channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); + } + + +} diff --git a/beacon-smsgateway/src/main/resources/bootstrap.yml b/beacon-smsgateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..1c602ac --- /dev/null +++ b/beacon-smsgateway/src/main/resources/bootstrap.yml @@ -0,0 +1,16 @@ +# 服务名称 +spring: + application: + name: beacon-smsgateway + # 多环境 + profiles: + active: dev + # nacos注册中心地址 + cloud: + nacos: + discovery: + server-addr: 114.116.226.76:8848 + # nacos配置中心地址: + config: + server-addr: 114.116.226.76:8848 + file-extension: yml diff --git a/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java b/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java index 68642ca..9fd3c18 100644 --- a/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java +++ b/beacon-test/src/main/java/com/mashibing/test/TestStarterApp.java @@ -7,6 +7,8 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; import java.util.concurrent.*; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; /** * @author zjw @@ -20,7 +22,6 @@ public class TestStarterApp { public static void main(String[] args) { SpringApplication.run(TestStarterApp.class,args); - } diff --git a/pom.xml b/pom.xml index 137dea2..daebbfd 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ beacon-strategy beacon-search beacon-push + beacon-smsgateway org.springframework.boot