烽火云长椿街3.26 2:23

master
DanielDeng 8 months ago
parent ce800117f6
commit 88c562607a

@ -10,11 +10,14 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="beacon-test" />
<module name="beacon-common" />
<module name="beacon-smsgateway" />
<module name="beacon-push" />
<module name="beacon-api" />
<module name="beacon-common" />
<module name="beacon-cache" />
<module name="beacon-test" />
<module name="beacon-strategy" />
<module name="beacon-search" />
</profile>
</annotationProcessing>
</component>
@ -23,6 +26,9 @@
<module name="beacon-api" options="-parameters" />
<module name="beacon-cache" options="-parameters" />
<module name="beacon-common" options="-parameters" />
<module name="beacon-push" options="-parameters" />
<module name="beacon-search" options="-parameters" />
<module name="beacon-smsgateway" options="-parameters" />
<module name="beacon-strategy" options="-parameters" />
<module name="beacon-test" options="-parameters" />
</option>

@ -5,6 +5,9 @@
<file url="file://$PROJECT_DIR$/beacon-api/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-cache/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-push/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-search/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-smsgateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-strategy/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/beacon-test/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />

@ -1,7 +1,3 @@
## 端口号
#server:
# port: 8080
# 服务名称
spring:
application:
@ -13,17 +9,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 192.168.1.113:8848
server-addr: 192.168.43.132:8848
# nacos配置中心地址:
config:
server-addr: 192.168.1.113:8848
server-addr: 192.168.43.132:8848
file-extension: yml
# beacon-api-dev.yml
# # rabbitMQ连接信息
# rabbitmq:
# host: 192.168.1.113
# port: 5672
# username: root
# password: 19970213Dch.
# virtual-host: /

@ -26,6 +26,16 @@
<artifactId>spring-context</artifactId>
<version>5.3.12</version>
</dependency>
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.5</version>
</dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.12.5</version>
</dependency>
</dependencies>
</project>

@ -25,6 +25,7 @@ public enum ExceptionEnums {
ONE_MINUTE_LIMIT(-16,"1分钟限流规则生效无法发送短信"),
ONE_HOUR_LIMIT(-17,"1小时限流规则生效无法发送短信"),
NO_CHANNEL(-18,"没有选择到合适的通道"),
SEARCH_INDEX_ERROR(-19,"添加ES文档信息失败")
;
private Integer code;

@ -0,0 +1,26 @@
package com.mashibing.common.exception;
import com.mashibing.common.enums.ExceptionEnums;
import lombok.Getter;
/**
* @author dch
* @create 2024-03-20 12:15
*/
@Getter
public class SearchException extends RuntimeException {
private Integer code;
public SearchException(String message, Integer code) {
super(message);
this.code = code;
}
public SearchException(ExceptionEnums enums) {
super(enums.getMsg());
this.code = enums.getCode();
}
}

@ -5,6 +5,11 @@ package com.mashibing.common.model;
* @create 2024-03-24 17:05
*/
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -47,6 +52,9 @@ public class StandardReport implements Serializable {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime sendTime;
/**
@ -61,10 +69,14 @@ public class StandardReport implements Serializable {
/**
*
*
*/
private Integer isCallback;
private String callbackUrl;
/**
*
*/
private Integer resendCount = 0;
}

@ -1,5 +1,10 @@
package com.mashibing.common.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -56,6 +61,9 @@ public class StandardSubmit implements Serializable {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime sendTime;
/**

@ -0,0 +1,21 @@
package com.mashibing.common.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author dch
* @create 2024-03-25 22:20
*/
public class JsonUtil {
private static ObjectMapper objectMapper = new ObjectMapper();
public static String obj2JSON(Object obj){
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new RuntimeException("转换JSON失败");
}
}
}

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beacon-push</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- start-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos-dis-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos-config-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 公共组件common-->
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>beacon-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RabbitMQ依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,19 @@
package com.mashibing.push;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author dch
* @create 2024-03-25 23:59
*/
@SpringBootApplication
@EnableDiscoveryClient
public class PushStarterApp {
public static void main(String[] args) {
SpringApplication.run(PushStarterApp.class,args);
}
}

@ -0,0 +1,47 @@
package com.mashibing.push.config;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
/**
* @author dch
* @create 2024-03-26 1:00
*/
@Configuration
public class RabbitMQConfig {
public static final String DELAYED_EXCHANGE = "push_delayed_exchange";
public static final String DELAYED_QUEUE = "push_delayed_queue";
private static final String DELAYED_EXCHANGE_TYPE = "x-delayed-message";
private static final String DELAYED_ROUTING_TYPE_KEY = "x-delayed-type";
private static final String DELAYED_ROUTING_TYPE_FANOUT = "fanout";
@Bean
public Exchange delayedExchange(){
Map<String, Object> args = new HashMap<>();
//延迟交换机的路由类型----fanout
args.put(DELAYED_ROUTING_TYPE_KEY,DELAYED_ROUTING_TYPE_FANOUT);
Exchange delayedExchange = new CustomExchange(DELAYED_EXCHANGE,DELAYED_EXCHANGE_TYPE,false,false,args);
return delayedExchange;
}
@Bean
public Queue delayedQueue(){
return QueueBuilder.durable(DELAYED_QUEUE).build();
}
@Bean
public Binding delayedBinding(Exchange delayedExchange, Queue delayedQueue){
return BindingBuilder.bind(delayedQueue).to(delayedExchange).with("").noargs();
}
}

@ -0,0 +1,25 @@
package com.mashibing.push.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
* @author dch
* @create 2024-03-26 0:07
*/
@Configuration
@Slf4j
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

@ -0,0 +1,146 @@
package com.mashibing.push.mq;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.mashibing.common.constant.RabbitMQConstants;
import com.mashibing.common.model.StandardReport;
import com.mashibing.common.util.JsonUtil;
import com.mashibing.push.config.RabbitMQConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
/**
* @author dch
* @create 2024-03-26 0:05
*/
@Component
@Slf4j
public class PushReportListener {
// 重试的时间间隔。
private int[] delayTime = {0, 15000, 30000, 60000, 300000};
private final String SUCCESS = "SUCCESS";
@Autowired
private RestTemplate restTemplate;
@Autowired
private RabbitTemplate rabbitTemplate;
/**
*
*
* @param report
* @param channel
* @param message
* @throws IOException
*/
@RabbitListener(queues = RabbitMQConstants.SMS_PUSH_REPORT)
public void consume(StandardReport report, Channel channel, Message message) throws IOException {
//1、获取客户的回调地址
String callbackUrl = report.getCallbackUrl();
if (StringUtils.isEmpty(callbackUrl)) {
log.info("【推送模块-推送状态报告】 客户方没有设置回调的地址信息callbackUrl = {} ", callbackUrl);
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
return;
}
//2、发送状态报告
boolean flag = pushReport(report);
//3、如果发送失败重试
isResend(report, flag);
//4、直接手动ack
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
/**
*
*
* @param report
* @param channel
* @param message
* @throws IOException
*/
@RabbitListener(queues = RabbitMQConfig.DELAYED_QUEUE)
public void delayedConsume(StandardReport report, Channel channel, Message message) throws IOException {
// 1、发送状态报告
boolean flag = pushReport(report);
// 2、判断状态报告发送情况
isResend(report, flag);
// 手动ack
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
/**
* callbackUrl
*
* @param report
* @return
*/
private boolean pushReport(StandardReport report) {
// 声明返回结果你默认为false
boolean flag = false;
//1、声明发送的参数
String body = JsonUtil.obj2JSON(report);
//2、声明RestTemplate的模板代码
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
try {
log.info("【推送模块-推送状态报告】 第{}次推送状态报告开始report = {}", report.getResendCount() + 1, report);
String result = restTemplate.postForObject("http://" + report.getCallbackUrl(), new HttpEntity<>(body, httpHeaders), String.class);
flag = SUCCESS.equals(result);
} catch (RestClientException e) {
}
//3、得到响应后确认是否为SUCCESS
return flag;
}
/**
*
*
* @param report
* @param flag
*/
private void isResend(StandardReport report, boolean flag) {
if (!flag) {
log.info("【推送模块-推送状态报告】 第{}次推送状态报告失败report = {}", report.getResendCount() + 1, report);
report.setResendCount(report.getResendCount() + 1);
rabbitTemplate.convertAndSend(RabbitMQConfig.DELAYED_EXCHANGE, "", report, new MessagePostProcessor() {
@Override
public Message postProcessMessage(Message message) throws AmqpException {
// 设置延迟时间
message.getMessageProperties().setDelay(delayTime[report.getResendCount()]);
return message;
}
});
} else {
log.info("【推送模块-推送状态报告】 第一次推送状态报告成功report = {}", report);
}
}
}

@ -0,0 +1,17 @@
# 服务名称
spring:
application:
name: beacon-push
# 多环境
profiles:
active: dev
# nacos注册中心地址
cloud:
nacos:
discovery:
server-addr: 192.168.43.132:8848
# nacos配置中心地址:
config:
server-addr: 192.168.43.132:8848
file-extension: yml
# beacon-push-dev.yml

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beacon-search</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- start-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos-dis-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos-config-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 公共组件common-->
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>beacon-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RabbitMQ依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- elasticsearch的客户端依赖-->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.6.2</version>
</dependency>
<!--测试组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,18 @@
package com.mashibing.search;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author dch
* @create 2024-03-25 20:43
*/
@SpringBootApplication
@EnableDiscoveryClient
public class SearchStarterApp {
public static void main(String[] args) {
SpringApplication.run(SearchStarterApp.class,args);
}
}

@ -0,0 +1,57 @@
package com.mashibing.search.config;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author dch
* @create 2024-03-25 21:02
*/
@Configuration
public class RestHighLevelClientConfig {
@Value("#{'${elasticsearch.hostAndPorts}'.split(',')}")
private List<String> hostAndPorts;
@Value("${elasticsearch.username:elastic}")
private String username;
@Value("${elasticsearch.password}")
private String password;
@Bean
public RestHighLevelClient restHighLevelClient(){
// 初始化连接ES的HttpHost信息
HttpHost[] httpHosts = new HttpHost[hostAndPorts.size()];
for (int i = 0; i < hostAndPorts.size(); i++) {
String[] hostAndPort = hostAndPorts.get(i).split(":");
httpHosts[i] = new HttpHost(hostAndPort[0],Integer.parseInt(hostAndPort[1]));
}
// 设置认证信息
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(username,password));
// 构建时设置连接信息基于set设置认证信息
RestClientBuilder restClientBuilder = RestClient.builder(httpHosts);
restClientBuilder.setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider));
// 构建连接ES的client对象
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
// 返回
return restHighLevelClient;
}
}

@ -0,0 +1,46 @@
package com.mashibing.search.mq;
import com.mashibing.common.constant.RabbitMQConstants;
import com.mashibing.common.model.StandardSubmit;
import com.mashibing.common.util.JsonUtil;
import com.mashibing.search.service.SearchService;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.LocalDateTime;
/**
* @author dch
* @create 2024-03-25 21:16
*/
@Component
@Slf4j
public class SmsWriteLogListener {
@Autowired
private SearchService searchService;
private final String INDEX = "sms_submit_log_";
@RabbitListener(queues = RabbitMQConstants.SMS_WRITE_LOG)
public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
//1、调用搜索模块的添加方法完成添加操作
log.info("接收到存储日志的信息 submit = {}",submit);
searchService.index(INDEX + getYear(),submit.getSequenceId().toString(), JsonUtil.obj2JSON(submit));
//2、手动ack
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
}
public String getYear(){
return LocalDateTime.now().getYear() + "";
}
}

@ -0,0 +1,18 @@
package com.mashibing.search.service;
import java.io.IOException;
/**
* @author dch
* @create 2024-03-25 21:34
*/
public interface SearchService {
/**
* ES
*
* @param index
* @param id id
* @param json
*/
void index(String index, String id, String json) throws IOException;
}

@ -0,0 +1,55 @@
package com.mashibing.search.service.impl;
import com.mashibing.common.enums.ExceptionEnums;
import com.mashibing.common.exception.SearchException;
import com.mashibing.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
/**
* @author dch
* @create 2024-03-25 21:34
*/
@Service
@Slf4j
public class ElasticsearchServiceImpl implements SearchService {
/**
* result
*/
private final String CREATED = "created";
@Autowired
private RestHighLevelClient restHighLevelClient;
@Override
public void index(String index, String id, String json) throws IOException {
//1、构建插入数据的Request
IndexRequest request = new IndexRequest();
//2、给request对象封装索引信息文档id以及文档内容
request.index(index);
request.id(id);
request.source(json, XContentType.JSON);
//3、将request信息发送给ES服务
IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);
//4、校验添加是否成功
String result = response.getResult().getLowercase();
if(!CREATED.equals(result)){
// 添加失败!!
log.error("【搜索模块-写入数据失败】 index = {},id = {},json = {},result = {}",index,id,json,result);
throw new SearchException(ExceptionEnums.SEARCH_INDEX_ERROR);
}
log.info("【搜索模块-写入数据成功】 索引添加成功index = {},id = {},json = {},result = {}",index,id,json,result);
}
}

@ -0,0 +1,17 @@
# 服务名称
spring:
application:
name: beacon-search
# 多环境
profiles:
active: dev
# nacos注册中心地址
cloud:
nacos:
discovery:
server-addr: 192.168.43.132:8848
# nacos配置中心地址:
config:
server-addr: 192.168.43.132:8848
file-extension: yml
# beacon-search-dev.yml

@ -0,0 +1,28 @@
package com.mashibing.search.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import static org.junit.Assert.*;
/**
* @author dch
* @create 2024-03-25 21:49
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class SearchServiceTest {
@Autowired
private SearchService searchService;
@Test
public void index() throws IOException {
searchService.index("sms_submit_log_2024","1","{\"clientId\":1}");
}
}

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mashibing</groupId>
<artifactId>beacon-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>beacon-smsgateway</artifactId>
<name>短信网关模块的模板</name>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- start-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos-dis-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos-config-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 公共组件common-->
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>beacon-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- RabbitMQ依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,17 @@
package com.mashibing.smsgateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author dch
* @create 2024-03-26 2:01
*/
@EnableDiscoveryClient
@SpringBootApplication
public class SmsGatewayStarterApp {
public static void main(String[] args) {
SpringApplication.run(SmsGatewayStarterApp.class, args);
}
}

@ -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 dch
* @create 2024-03-26 2:12
*/
@Component
@Slf4j
public class SmsGatewayListener {
@RabbitListener(queues = "${gateway.sendtopic}")
public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException, InterruptedException {
log.info("【短信网关模块】 接收到消息 submit = {}", submit);
// =====================完成运营商交互,发送一次请求,接收两次响应==========================
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
}

@ -0,0 +1,16 @@
# 服务名称
spring:
application:
name: beacon-smsgateway
# 多环境
profiles:
active: dev
# nacos注册中心地址
cloud:
nacos:
discovery:
server-addr: 192.168.43.132:8848
# nacos配置中心地址:
config:
server-addr: 192.168.43.132:8848
file-extension: yml

@ -37,7 +37,7 @@ public class RabbitTemplateConfig {
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
// ack为false代表消息没有发送到exchange。
if(!ack){
log.error("【接口模块-发送消息】 消息没有发送到交换机correlationData = {}cause = {}",correlationData,cause);
log.error("【策略模块-发送消息】 消息没有发送到交换机correlationData = {}cause = {}",correlationData,cause);
}
}
});
@ -48,7 +48,7 @@ public class RabbitTemplateConfig {
// 触发这个回调,说明交换机没有把消息路由到指定的队列中
@Override
public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
log.error("【接口模块-发送消息】 消息没有路由到指定的Queue。 message = {},exchange = {},routingKey = {}",
log.error("【策略模块-发送消息】 消息没有路由到指定的Queue。 message = {},exchange = {},routingKey = {}",
new String(message.getBody()),exchange,routingKey);
}
});

@ -20,6 +20,9 @@
<module>beacon-cache</module>
<module>beacon-test</module>
<module>beacon-strategy</module>
<module>beacon-search</module>
<module>beacon-push</module>
<module>beacon-smsgateway</module>
</modules>
<properties>

Loading…
Cancel
Save